Skip to content

Commit

Permalink
search: improve podcast and episode search
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Jan 22, 2024
1 parent 123eae7 commit be7a609
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ytmusicapi/parsers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ def _impl(self, *method_args, **method_kwargs):
return method(self, *method_args, **method_kwargs)

return _impl


def parse_id_name(sub_run):
return {
"id": nav(sub_run, NAVIGATION_BROWSE_ID, True),
"name": nav(sub_run, ["text"], True),
}
8 changes: 0 additions & 8 deletions ytmusicapi/parsers/browsing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ._utils import *
from .songs import *


Expand Down Expand Up @@ -64,13 +63,6 @@ def parse_album(result):
}


def parse_id_name(sub_run):
return {
"id": nav(sub_run, NAVIGATION_BROWSE_ID, True),
"name": nav(sub_run, ["text"], True),
}


def parse_single(result):
return {
"title": nav(result, TITLE_TEXT),
Expand Down
9 changes: 7 additions & 2 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def parse_search_result(data, search_result_types, result_type, category):
search_result["releaseDate"] = runs[2]
search_result["resultType"] = "album"

if result_type in ["song", "video"]:
if result_type in ["song", "video", "episode"]:
search_result["videoId"] = nav(
data, [*PLAY_BUTTON, "playNavigationEndpoint", "watchEndpoint", "videoId"], True
)
Expand All @@ -137,12 +137,17 @@ def parse_search_result(data, search_result_types, result_type, category):
song_info = parse_song_runs(runs)
search_result.update(song_info)

if result_type in ["artist", "album", "playlist", "profile"]:
if result_type in ["artist", "album", "playlist", "profile", "podcast"]:
search_result["browseId"] = nav(data, NAVIGATION_BROWSE_ID, True)

if result_type in ["song", "album"]:
search_result["isExplicit"] = nav(data, BADGE_LABEL, True) is not None

if result_type in ["episode"]:
flex_item = get_flex_column_item(data, 1)
search_result["date"] = nav(flex_item, TEXT_RUN_TEXT)
search_result["podcast"] = parse_id_name(nav(flex_item, ["text", "runs", 2]))

search_result["thumbnails"] = nav(data, THUMBNAILS, True)

return search_result
Expand Down

0 comments on commit be7a609

Please sign in to comment.