From 87023d602bb4e835cb05f6640cda8bf492b0ef61 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 29 Aug 2020 11:14:05 +0200 Subject: [PATCH] convert all search result types to use pipe framework --- app/common/innertube.py | 55 ++++++++++++----------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/app/common/innertube.py b/app/common/innertube.py index df7236e..96d5fe4 100644 --- a/app/common/innertube.py +++ b/app/common/innertube.py @@ -177,51 +177,29 @@ def parse_result_items(items): 'published': content|G('publishedTimeText')|G('simpleText')|A(age), 'live': content|G('badges')|Select('metadataBadgeRenderer')|G('style')=='BADGE_STYLE_TYPE_LIVE_NOW', }}) - elif key == 'playlistRenderer': + elif key in ['playlistRenderer', 'radioRenderer', 'showRenderer']: # radio == "Mix" playlist, show == normal playlist, specially displayed results.append({'type': 'PLAYLIST', 'content': { - 'playlist_id': content['navigationEndpoint'].get('watchEndpoint',{}).get('playlistId') or \ - content.get('playlistId'), # COURSE/"learning playlist" - 'video_id': content['navigationEndpoint'].get('watchEndpoint',{}).get('videoId') or \ + 'playlist_id': content['navigationEndpoint']|G('watchEndpoint')|G('playlistId') or \ + content|G('playlistId'), # COURSE/"learning playlist" + 'video_id': content['navigationEndpoint']|G('watchEndpoint')|G('videoId') or \ videoid_from_thumbnail(content), # learning playlist - 'title': content['title']['simpleText'], + 'title': content['title']|G.text, # Note: learning playlists have no author/channel_id - 'author': listget(content.get('longBylineText',{}).get('runs',[]),0,{}).get('text') or - listget(content.get('shortBylineText',{}).get('runs',[]),0,{}).get('text'), - 'channel_id': listget(content.get('longBylineText',{}).get('runs',[]),0,{}) \ - .get('navigationEndpoint',{}).get('browseEndpoint',{}).get('browseId'), # OR .shortBylineText - 'n_videos': toInt(content['videoCount']), - }}) - elif key == 'radioRenderer': # "Mix" playlists - results.append({'type': 'PLAYLIST', 'content': { - 'playlist_id': content['playlistId'], - 'video_id': content['navigationEndpoint']['watchEndpoint']['videoId'], - 'title': content['title']['simpleText'], - 'author': content['longBylineText']['simpleText'] or \ - content['shortBylineText']['simpleText'] , # always "YouTube" - 'channel_id': None, - 'n_videos': content['videoCountShortText']['runs'][0]['text'] or \ - content['videoCountText']['runs'][0]['text'], - # videoCountShortText: "50+"; videoCountText: "50+ videos" - }}) - elif key == 'showRenderer': # normal playlist, specially displayed - results.append({'type': 'PLAYLIST', 'content': { - 'playlist_id': content['navigationEndpoint']['watchEndpoint']['playlistId'], - 'video_id': content['navigationEndpoint']['watchEndpoint']['videoId'], - 'title': content['title']['simpleText'], - 'author': content['longBylineText']['runs'][0]['text'] or \ - content['shortBylineText']['runs'][0]['text'], - 'channel_id': None, - 'n_videos': None, + 'author': content|G('longBylineText','shortBylineText')|G.text, + 'channel_id': content|G('longBylineText','shortBylineText')|G('runs')|G(0) \ + |G('navigationEndpoint')|G('browseEndpoint')|G('browseId'), + 'n_videos': content|G('videoCount')|A.int or \ + content|G('videoCountShortText','videoCountText')|G.text, # "Mix" playlists }}) elif key == 'channelRenderer': results.append({'type': 'CHANNEL', 'content': { 'channel_id': content['channelId'], - 'title': content['title']['simpleText'], - 'icons': mkthumbs(content['thumbnail']['thumbnails']), - 'subscribers': content.get('subscriberCountText',{}).get('simpleText'), # "2.47K subscribers" + 'title': content['title']|G.text, + 'icons': content['thumbnail']['thumbnails']|A(mkthumbs), + 'subscribers': content|G('subscriberCountText')|G('simpleText'), # "2.47K subscribers" }}) elif key == 'shelfRenderer': - subkey = next(iter(content['content'].keys()), {}) #verticalListRenderer/horizontalMovieListRenderer + subkey = next(iter(content['content'].keys()), None) #verticalListRenderer/horizontalMovieListRenderer r, e = parse_result_items(content['content'][subkey]['items']) results.extend(r) extras.extend(e) @@ -247,13 +225,12 @@ def parse_result_items(items): elif key == 'messageRenderer': # "No more results" extras.append({ 'type': 'message', - 'message': content|G('title')|G('runs')|G(0)|G('text') or \ - content|G('text')|G('runs')|G(0)|G('text'), + 'message': content|G('title','text')|G.text, }) elif key == 'backgroundPromoRenderer': # e.g. "no results" extras.append({ 'type': content['icon']['iconType'], - 'message': content['title']['runs'][0]['text'], + 'message': content['title']|G.text, }) else: log_unknown_card(item) -- 2.39.3