Skip to content

Commit

Permalink
parse_seach_result: add playlist id to album search (#586)
Browse files Browse the repository at this point in the history
* parse_seach_result: add playlist id to album search

* fix docs

* add to top result

---------

Co-authored-by: sigma67 <sigma67.github@gmail.com>
  • Loading branch information
jonathanbell and sigma67 committed May 25, 2024
1 parent 0cf0883 commit 1f4332a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ytmusicapi/mixins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def search(
{
"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",
Expand Down
8 changes: 8 additions & 0 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1f4332a

Please sign in to comment.