Using youtube api (v3) instead of v2 to get the video duration .
TNL-2413
This commit is contained in:
@@ -28,8 +28,7 @@ SERVICES = {
|
||||
|
||||
YOUTUBE_API_URLS = {
|
||||
'main': 'https://www.youtube.com/',
|
||||
'player': 'http://www.youtube.com/iframe_api',
|
||||
'metadata': 'http://gdata.youtube.com/feeds/api/videos/',
|
||||
'player': 'https://www.youtube.com/iframe_api',
|
||||
# For transcripts, you need to check an actual video, so we will
|
||||
# just specify our default video and see if that one is available.
|
||||
'transcript': 'http://video.google.com/timedtext?lang=en&v=OEoXaMPEzfM',
|
||||
|
||||
@@ -95,6 +95,9 @@ class StubYouTubeHandler(StubHttpRequestHandler):
|
||||
if self.server.config.get('youtube_api_blocked'):
|
||||
self.send_response(404, content='', headers={'Content-type': 'text/plain'})
|
||||
else:
|
||||
# Delay the response to simulate network latency
|
||||
time.sleep(self.server.config.get('time_to_response', self.DEFAULT_DELAY_SEC))
|
||||
|
||||
# Get the response to send from YouTube.
|
||||
# We need to do this every time because Google sometimes sends different responses
|
||||
# as part of their own experiments, which has caused our tests to become "flaky"
|
||||
@@ -117,17 +120,16 @@ class StubYouTubeHandler(StubHttpRequestHandler):
|
||||
|
||||
# Construct the response content
|
||||
callback = self.get_params['callback']
|
||||
youtube_metadata = json.loads(
|
||||
requests.get(
|
||||
"http://gdata.youtube.com/feeds/api/videos/{id}?v=2&alt=jsonc".format(id=youtube_id)
|
||||
).text
|
||||
)
|
||||
|
||||
data = OrderedDict({
|
||||
'data': OrderedDict({
|
||||
'id': youtube_id,
|
||||
'message': message,
|
||||
'duration': youtube_metadata['data']['duration'],
|
||||
})
|
||||
'items': list(
|
||||
OrderedDict({
|
||||
'contentDetails': OrderedDict({
|
||||
'id': youtube_id,
|
||||
'duration': 'PT2M20S',
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
response = "{cb}({data})".format(cb=callback, data=json.dumps(data))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user