From 2751f945652b4efe5a0d0209f26ea6626b669659 Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 6 Aug 2020 23:02:12 +0200 Subject: [PATCH] dangerous.channel/playlist: parse extra messages --- app/common/innertube.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/common/innertube.py b/app/common/innertube.py index fef691c..6facecf 100644 --- a/app/common/innertube.py +++ b/app/common/innertube.py @@ -44,15 +44,18 @@ def prepare_channel(result, channel_id): if 'continuationContents' in response.keys(): contents = response['continuationContents'] try: # TODO: cleanup - items = parse_channel_items(contents['gridContinuation']['items'], channel_id, title) + items, extra = parse_channel_items(contents['gridContinuation']['items'], channel_id, title) except: try: - items = parse_channel_items(contents['sectionListContinuation']['contents'], channel_id, title) - except: + items, extra = parse_channel_items(contents['sectionListContinuation']['contents'], channel_id, title) + except Exception as e: from flask import current_app current_app.logger.error(result) - items = [] + raise e + # TODO: show extra to user else: # if absent, we reach end of list + from flask import current_app + current_app.logger.error(result) items = [] return title, descr, thumb, items @@ -277,6 +280,7 @@ def parse_endcard(card): def parse_channel_items(items, channel_id, author): result = [] + extra = [] for item in items: key = next(iter(item.keys()), None) content = item[key] @@ -303,11 +307,16 @@ def parse_channel_items(items, channel_id, author): content.get('videoCountText',{}).get('runs',[{}])[0].get('text')), # grid(2) }}) elif key == "itemSectionRenderer": - result.extend(parse_channel_items(content['contents'], channel_id, author)) + r, e = parse_channel_items(content['contents'], channel_id, author) + result.extend(r) + extra.extend(e) + elif key == "messageRenderer": + # e.g. {'messageRenderer': {'text': {'runs': [{'text': 'This channel has no playlists.'}]}}} + pass else: - raise Exception(item) # XXX TODO + log_unknown_card(item) - return result + return result, extra def parse_playlist(item): key = next(iter(item.keys()), None) -- 2.39.3