From 4d7bbbe51fdc7dd0b09cf65b879e1ea83d88541c Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 17 Aug 2020 18:48:15 +0200 Subject: [PATCH] fix "learning playlist" and playlists in general, more search result types --- app/common/innertube.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/common/innertube.py b/app/common/innertube.py index fcbff3b..f2c97d6 100644 --- a/app/common/innertube.py +++ b/app/common/innertube.py @@ -179,12 +179,19 @@ def parse_result_items(items): pass elif key == 'emergencyOneboxRenderer': # suicide prevention hotline pass + elif key == 'clarificationRenderer': # COVID-19 infos + pass elif key == 'didYouMeanRenderer' or key == 'showingResultsForRenderer': extras.append({ 'type': 'spelling', 'query': content['correctedQueryEndpoint']['searchEndpoint']['query'], # non-misspelled query 'autocorrected': key == 'showingResultsForRenderer', }) + elif key == 'backgroundPromoRenderer': # e.g. "no results" + extras.append({ + 'type': content['icon']['iconType'], + 'message': content['title']['runs'][0]['text'], + }) else: log_unknown_card(item) return results, extras @@ -303,8 +310,8 @@ def parse_channel_items(items, channel_id, author): }}) elif key == "gridPlaylistRenderer" or key == "playlistRenderer": result.append({'type': 'PLAYLIST', 'content': { - 'playlist_id': content['navigationEndpoint']['watchEndpoint']['playlistId'], - 'video_id': content['navigationEndpoint']['watchEndpoint']['videoId'], + 'playlist_id': content['navigationEndpoint'].get('watchEndpoint',{}).get('playlistId') or content.get('playlistId'), + 'video_id': content['navigationEndpoint'].get('watchEndpoint',{}).get('videoId',{}), 'title': (content['title'].get('simpleText') or # playlistRenderer content['title']['runs'][0]['text']), # gridPlaylistRenderer 'author': author, @@ -348,7 +355,7 @@ def parse_playlist(item): 'title': (content['title'].get('simpleText') or # playable videos content['title'].get('runs',[{}])[0].get('text')), # "[Private video]" 'playlist_id': content['navigationEndpoint']['watchEndpoint']['playlistId'], - 'index': content['navigationEndpoint']['watchEndpoint']['index'], #or int(content['index']['simpleText']) + 'index': content['navigationEndpoint']['watchEndpoint'].get('index',0), #or int(content['index']['simpleText']) (absent on course intros; e.g. PL96C35uN7xGJu6skU4TBYrIWxggkZBrF5) # rest is missing from unplayable videos: 'author': content.get('shortBylineText',{}).get('runs',[{}])[0].get('text'), 'channel_id':content.get('shortBylineText',{}).get('runs',[{}])[0].get('navigationEndpoint',{}).get('browseEndpoint',{}).get('browseId'), -- 2.39.3