From 66f07dcd4178ca3807cf6a093d26e0a24d1f8216 Mon Sep 17 00:00:00 2001 From: 3risian <59593325+3risian@users.noreply.github.com> Date: Wed, 8 Jan 2020 12:45:21 +1100 Subject: [PATCH] [PeerTube] Improve safety of dictionary access This could probably be more elegant. --- youtube_dl/extractor/peertube.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/peertube.py b/youtube_dl/extractor/peertube.py index 19328729d..e4fc78695 100644 --- a/youtube_dl/extractor/peertube.py +++ b/youtube_dl/extractor/peertube.py @@ -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):