[PeerTube] Improve safety of dictionary access

This could probably be more elegant.
This commit is contained in:
3risian 2020-01-08 12:45:21 +11:00 committed by GitHub
parent 64186d344a
commit 66f07dcd41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -490,11 +490,16 @@ class PeerTubeIE(InfoExtractor):
'https://%s/api/v1/videos/%s/captions' % (host, video_id), video_id)
subtitles = {}
for entry in video_captions['data']:
caption_url = 'https://%s%s' % (host, entry['captionPath'])
subtitles[entry['language']['id']] = [{
'url': caption_url
}]
for entry in video_captions.get('data'):
captions_language = entry.get('language')
if captions_language is not None:
language_id = captions_language.get('id')
caption_path = entry.get('captionPath')
if language_id is not None and caption_path is not None:
caption_url = 'https://%s%s' % (host, caption_path)
subtitles[language_id] = [{
'url': caption_url
}]
return subtitles
def _real_extract(self, url):