From 3e09193eafeb7072c46385b2c91e82fcd275cc25 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 5 Apr 2020 17:27:43 -0700 Subject: Fix exception due to missing 'playlist' key in extracted info Happens when there's an error on the page and there was no visible stuff on the page. 'playlist' wasn't set to None in that case. --- youtube/yt_data_extract/watch_extraction.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube/yt_data_extract/watch_extraction.py b/youtube/yt_data_extract/watch_extraction.py index 193b84b..8fb0af4 100644 --- a/youtube/yt_data_extract/watch_extraction.py +++ b/youtube/yt_data_extract/watch_extraction.py @@ -188,6 +188,8 @@ def _extract_watch_info_mobile(top_level): info['playlist']['current_index'] = playlist.get('currentIndex') info['playlist']['items'] = [ extract_item_info(i) for i in playlist.get('contents', ())] + else: + info['playlist'] = None # Holds the visible video info. It is inside singleColumnWatchNextResults # but use our convenience function instead @@ -264,6 +266,7 @@ def _extract_watch_info_desktop(top_level): 'comments_disabled': None, 'allowed_countries': [], 'limited_state': None, + 'playlist': None, } video_info = {} -- cgit v1.2.3