From fcea964d2675b186937136ef4b8081f3ba3a59a0 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Sun, 23 Feb 2020 18:06:10 +0100 Subject: [PATCH] Add more info on song/video search results --- ytmusicapi/helpers.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ytmusicapi/helpers.py b/ytmusicapi/helpers.py index 86b3b9ec..73dfc117 100644 --- a/ytmusicapi/helpers.py +++ b/ytmusicapi/helpers.py @@ -37,6 +37,12 @@ def parse_search_result(data, resultType = None): if resultType not in ['artist', 'playlist', 'song', 'video']: resultType = 'album' + if resultType in ['song', 'video']: + search_result['videoId'] = data['overlay']['musicItemThumbnailOverlayRenderer']['content'][ + 'musicPlayButtonRenderer']['playNavigationEndpoint']['watchEndpoint']['videoId'] + search_result['title'] = get_item_text(data, 0) + search_result['artist'] = get_item_text(data, 1 + default) + if resultType in ['artist', 'album', 'playlist']: search_result['browseId'] = data['navigationEndpoint']['browseEndpoint']['browseId'] @@ -54,12 +60,13 @@ def parse_search_result(data, resultType = None): search_result['author'] = get_item_text(data, 1 + default) search_result['itemCount'] = get_item_text(data, 2 + default).split(' ')[0] - # songs, videos - elif resultType in ['song', 'video']: - search_result['videoId'] = data['overlay']['musicItemThumbnailOverlayRenderer']['content'][ - 'musicPlayButtonRenderer']['playNavigationEndpoint']['watchEndpoint']['videoId'] - search_result['title'] = get_item_text(data, 0) - search_result['artist'] = get_item_text(data, 1 + default) + elif resultType in ['song']: + search_result['album'] = get_item_text(data, 2 + default) + search_result['duration'] = get_item_text(data, 3 + default) + + elif resultType in ['video']: + search_result['views'] = get_item_text(data, 2 + default).split(' ')[0] + search_result['duration'] = get_item_text(data, 3 + default) search_result['resultType'] = resultType