Skip to content

Commit

Permalink
get_home: remove "year" attribute from album results, parse podcasts … (
Browse files Browse the repository at this point in the history
#591)

* get_home: remove "year" attribute from album results, parse podcasts and episodes

* search: make itemCount int cast error proof

* fix None case for parse_album year

* fix lint
  • Loading branch information
sigma67 authored May 27, 2024
1 parent fdc2594 commit 33098ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion ytmusicapi/mixins/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def get_home(self, limit=3) -> List[Dict]:
"contents": [
{ //album result
"title": "Sentiment",
"year": "Said The Sky",
"browseId": "MPREb_QtqXtd2xZMR",
"thumbnails": [...]
},
Expand Down
20 changes: 14 additions & 6 deletions ytmusicapi/parsers/browsing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .podcasts import parse_episode, parse_podcast
from .songs import *


Expand Down Expand Up @@ -30,11 +31,14 @@ def parse_mixed_content(rows):
content = parse_related_artist(data)
elif page_type == "MUSIC_PAGE_TYPE_PLAYLIST":
content = parse_playlist(data)
else:
data = nav(result, [MRLIR], True)
if not data:
continue
elif page_type == "MUSIC_PAGE_TYPE_PODCAST_SHOW_DETAIL_PAGE":
content = parse_podcast(data)
elif data := nav(result, [MRLIR], True):
content = parse_song_flat(data)
elif data := nav(result, [MMRIR], True):
content = parse_episode(data)
else:
continue

contents.append(content)

Expand All @@ -51,17 +55,21 @@ def parse_content_list(results, parse_func, key=MTRIR):


def parse_album(result):
return {
album = {
"title": nav(result, TITLE_TEXT),
"type": nav(result, SUBTITLE),
"year": nav(result, SUBTITLE2, True),
"artists": [parse_id_name(x) for x in nav(result, ["subtitle", "runs"]) if "navigationEndpoint" in x],
"browseId": nav(result, TITLE + NAVIGATION_BROWSE_ID),
"audioPlaylistId": nav(result, THUMBNAIL_OVERLAY, True),
"thumbnails": nav(result, THUMBNAIL_RENDERER),
"isExplicit": nav(result, SUBTITLE_BADGE_LABEL, True) is not None,
}

if (year := nav(result, SUBTITLE2, True)) and year.isnumeric():
album["year"] = year

return album


def parse_single(result):
return {
Expand Down
2 changes: 1 addition & 1 deletion ytmusicapi/parsers/podcasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def parse_podcast(data):
"""Parses a single podcast under "Podcasts" on a channel page"""
return {
"title": nav(data, TITLE_TEXT),
"channel": parse_id_name(nav(data, [*SUBTITLE_RUNS, 0])),
"channel": parse_id_name(nav(data, [*SUBTITLE_RUNS, 0], True)),
"browseId": nav(data, TITLE + NAVIGATION_BROWSE_ID),
"podcastId": nav(data, THUMBNAIL_OVERLAY, True),
"thumbnails": nav(data, THUMBNAIL_RENDERER),
Expand Down
6 changes: 3 additions & 3 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def parse_search_result(data, search_result_types, result_type, category):
elif result_type == "playlist":
flex_item = get_flex_column_item(data, 1)["text"]["runs"]
has_author = len(flex_item) == default_offset + 3
search_result["itemCount"] = to_int(
get_item_text(data, 1, default_offset + has_author * 2).split(" ")[0]
)
search_result["itemCount"] = get_item_text(data, 1, default_offset + has_author * 2).split(" ")[0]
if search_result["itemCount"] and search_result["itemCount"].isnumeric():
search_result["itemCount"] = to_int(search_result["itemCount"])
search_result["author"] = None if not has_author else get_item_text(data, 1, default_offset)

elif result_type == "station":
Expand Down

0 comments on commit 33098ba

Please sign in to comment.