From 1f4332a8a95f070342f478e3780bf12f0b9b296f Mon Sep 17 00:00:00 2001 From: Jonathan Bell <1707639+jonathanbell@users.noreply.github.com> Date: Sat, 25 May 2024 01:15:26 -0700 Subject: [PATCH] parse_seach_result: add playlist id to album search (#586) * parse_seach_result: add playlist id to album search * fix docs * add to top result --------- Co-authored-by: sigma67 --- ytmusicapi/mixins/search.py | 5 +++-- ytmusicapi/parsers/search.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/mixins/search.py b/ytmusicapi/mixins/search.py index 22e974d..29aa537 100644 --- a/ytmusicapi/mixins/search.py +++ b/ytmusicapi/mixins/search.py @@ -83,8 +83,9 @@ class SearchMixin(MixinProtocol): { "category": "Albums", "resultType": "album", - "browseId": "MPREb_9nqEki4ZDpp", - "title": "(What's The Story) Morning Glory? (Remastered)", + "browseId": "MPREb_IInSY5QXXrW", + "playlistId": "OLAK5uy_kunInnOpcKECWIBQGB0Qj6ZjquxDvfckg", + "title": "(What's The Story) Morning Glory?", "type": "Album", "artist": "Oasis", "year": "1995", diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index eab2e39..f2efa1b 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -46,6 +46,7 @@ def parse_top_result(data, search_result_types): if result_type in ["album"]: search_result["browseId"] = nav(data, TITLE + NAVIGATION_BROWSE_ID, True) + search_result["playlistId"] = nav(data, ["buttons", 0, "buttonRenderer", "command", *WATCH_PID], True) if result_type in ["playlist"]: search_result["playlistId"] = nav(data, MENU_PLAYLIST_ID) @@ -159,6 +160,13 @@ def parse_search_result(data, search_result_types, result_type, category): if result_type in ["song", "album"]: search_result["isExplicit"] = nav(data, BADGE_LABEL, True) is not None + if result_type in ["album"]: + search_result["playlistId"] = nav( + data, + [*PLAY_BUTTON, "playNavigationEndpoint", "watchEndpoint", "playlistId"], + True, + ) + if result_type in ["episode"]: flex_item = get_flex_column_item(data, 1) has_date = int(len(nav(flex_item, TEXT_RUNS)) > 1)