From 3ab931a6a0fc2fc95d18865725fc236c4f53b5e1 Mon Sep 17 00:00:00 2001 From: v4hn Date: Wed, 17 Feb 2021 14:10:15 +0100 Subject: [PATCH] [youtube] fix playlist extraction & comprehensive error output --- src/you_get/extractors/youtube.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/you_get/extractors/youtube.py b/src/you_get/extractors/youtube.py index e954b1f4..7e4c74f0 100644 --- a/src/you_get/extractors/youtube.py +++ b/src/you_get/extractors/youtube.py @@ -157,7 +157,12 @@ class YouTube(VideoExtractor): log.wtf('[Failed] Unsupported URL pattern.') video_page = get_content('https://www.youtube.com/playlist?list=%s' % playlist_id) - ytInitialData = json.loads(match1(video_page, r'window\["ytInitialData"\]\s*=\s*(.+);')) + playlist_json_serialized = match1(video_page, r'window\["ytInitialData"\]\s*=\s*(.+);', r'var\s+ytInitialData\s*=\s*([^;]+);') + + if len(playlist_json_serialized) == 0: + log.wtf('[Failed] Unable to extract playlist data') + + ytInitialData = json.loads(playlist_json_serialized[0]) tab0 = ytInitialData['contents']['twoColumnBrowseResultsRenderer']['tabs'][0] itemSection0 = tab0['tabRenderer']['content']['sectionListRenderer']['contents'][0]