Skip to content

Commit df56ca2

Browse files
dizcologyJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
update samples to v1 [(#1221)](GoogleCloudPlatform/python-docs-samples#1221)
* update samples to v1 * replace while loop with operation.result(timeout) * addressing review comments * flake * flake
1 parent 3acd5f5 commit df56ca2

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

samples/shotchange/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-videointelligence==0.28.0
1+
google-cloud-videointelligence==1.0.0

samples/shotchange/shotchange.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,27 @@
2929
# [START full_tutorial]
3030
# [START imports]
3131
import argparse
32-
import sys
33-
import time
3432

35-
from google.cloud import videointelligence_v1beta2
36-
from google.cloud.videointelligence_v1beta2 import enums
33+
from google.cloud import videointelligence
3734
# [END imports]
3835

3936

4037
def analyze_shots(path):
4138
""" Detects camera shot changes. """
4239
# [START construct_request]
43-
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
44-
features = [enums.Feature.SHOT_CHANGE_DETECTION]
45-
operation = video_client.annotate_video(path, features)
40+
video_client = videointelligence.VideoIntelligenceServiceClient()
41+
features = [videointelligence.enums.Feature.SHOT_CHANGE_DETECTION]
42+
operation = video_client.annotate_video(path, features=features)
4643
# [END construct_request]
4744
print('\nProcessing video for shot change annotations:')
4845

4946
# [START check_operation]
50-
while not operation.done():
51-
sys.stdout.write('.')
52-
sys.stdout.flush()
53-
time.sleep(20)
54-
47+
result = operation.result(timeout=90)
5548
print('\nFinished processing.')
5649
# [END check_operation]
5750

5851
# [START parse_response]
59-
shots = operation.result().annotation_results[0].shot_annotations
60-
61-
for i, shot in enumerate(shots):
52+
for i, shot in enumerate(result.annotation_results[0].shot_annotations):
6253
start_time = (shot.start_time_offset.seconds +
6354
shot.start_time_offset.nanos / 1e9)
6455
end_time = (shot.end_time_offset.seconds +

0 commit comments

Comments
 (0)