From 4d608b522f7f05c7dbc4b74e6183e93cc95d6a0c Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 7 Feb 2021 15:22:36 +0530 Subject: [PATCH] [youtube_live_chat] Improve extraction :ci skip dl --- youtube_dlc/downloader/youtube_live_chat.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/youtube_dlc/downloader/youtube_live_chat.py b/youtube_dlc/downloader/youtube_live_chat.py index 615be1ec8..5ac24c020 100644 --- a/youtube_dlc/downloader/youtube_live_chat.py +++ b/youtube_dlc/downloader/youtube_live_chat.py @@ -50,7 +50,16 @@ class YoutubeLiveChatReplayFD(FragmentFD): success, raw_fragment = dl_fragment(url) if not success: return False, None, None - data = parse_yt_initial_data(raw_fragment) or json.loads(raw_fragment)['response'] + data = parse_yt_initial_data(raw_fragment) + if not data: + raw_data = json.loads(raw_fragment) + # sometimes youtube replies with a list + if not isinstance(raw_data, list): + raw_data = [raw_data] + try: + data = next(item['response'] for item in raw_data if 'response' in item) + except StopIteration: + data = {} live_chat_continuation = try_get( data,