Skip to content

Commit 33098ba

Browse files
authored
get_home: remove "year" attribute from album results, parse podcasts … (sigma67#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
1 parent fdc2594 commit 33098ba

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

ytmusicapi/mixins/browsing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def get_home(self, limit=3) -> List[Dict]:
3535
"contents": [
3636
{ //album result
3737
"title": "Sentiment",
38-
"year": "Said The Sky",
3938
"browseId": "MPREb_QtqXtd2xZMR",
4039
"thumbnails": [...]
4140
},

ytmusicapi/parsers/browsing.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .podcasts import parse_episode, parse_podcast
12
from .songs import *
23

34

@@ -30,11 +31,14 @@ def parse_mixed_content(rows):
3031
content = parse_related_artist(data)
3132
elif page_type == "MUSIC_PAGE_TYPE_PLAYLIST":
3233
content = parse_playlist(data)
33-
else:
34-
data = nav(result, [MRLIR], True)
35-
if not data:
36-
continue
34+
elif page_type == "MUSIC_PAGE_TYPE_PODCAST_SHOW_DETAIL_PAGE":
35+
content = parse_podcast(data)
36+
elif data := nav(result, [MRLIR], True):
3737
content = parse_song_flat(data)
38+
elif data := nav(result, [MMRIR], True):
39+
content = parse_episode(data)
40+
else:
41+
continue
3842

3943
contents.append(content)
4044

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

5256

5357
def parse_album(result):
54-
return {
58+
album = {
5559
"title": nav(result, TITLE_TEXT),
5660
"type": nav(result, SUBTITLE),
57-
"year": nav(result, SUBTITLE2, True),
5861
"artists": [parse_id_name(x) for x in nav(result, ["subtitle", "runs"]) if "navigationEndpoint" in x],
5962
"browseId": nav(result, TITLE + NAVIGATION_BROWSE_ID),
6063
"audioPlaylistId": nav(result, THUMBNAIL_OVERLAY, True),
6164
"thumbnails": nav(result, THUMBNAIL_RENDERER),
6265
"isExplicit": nav(result, SUBTITLE_BADGE_LABEL, True) is not None,
6366
}
6467

68+
if (year := nav(result, SUBTITLE2, True)) and year.isnumeric():
69+
album["year"] = year
70+
71+
return album
72+
6573

6674
def parse_single(result):
6775
return {

ytmusicapi/parsers/podcasts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def parse_podcast(data):
129129
"""Parses a single podcast under "Podcasts" on a channel page"""
130130
return {
131131
"title": nav(data, TITLE_TEXT),
132-
"channel": parse_id_name(nav(data, [*SUBTITLE_RUNS, 0])),
132+
"channel": parse_id_name(nav(data, [*SUBTITLE_RUNS, 0], True)),
133133
"browseId": nav(data, TITLE + NAVIGATION_BROWSE_ID),
134134
"podcastId": nav(data, THUMBNAIL_OVERLAY, True),
135135
"thumbnails": nav(data, THUMBNAIL_RENDERER),

ytmusicapi/parsers/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def parse_search_result(data, search_result_types, result_type, category):
9898
elif result_type == "playlist":
9999
flex_item = get_flex_column_item(data, 1)["text"]["runs"]
100100
has_author = len(flex_item) == default_offset + 3
101-
search_result["itemCount"] = to_int(
102-
get_item_text(data, 1, default_offset + has_author * 2).split(" ")[0]
103-
)
101+
search_result["itemCount"] = get_item_text(data, 1, default_offset + has_author * 2).split(" ")[0]
102+
if search_result["itemCount"] and search_result["itemCount"].isnumeric():
103+
search_result["itemCount"] = to_int(search_result["itemCount"])
104104
search_result["author"] = None if not has_author else get_item_text(data, 1, default_offset)
105105

106106
elif result_type == "station":

0 commit comments

Comments
 (0)