get_album: distinguish between "other versions" and "releases for you" (#791)
* parse_album: return audioPlaylistId for Premium users `audioPlaylistId` is no longer `None` when `parse_album` is called with data from a Premium account * get_album: distinguish between "other versions" and "releases for you" adds `related_recommendations`, a list of albums in "Releases for you" `other_versions` no longer contains those recommendations when its carousel is positioned after "Releases for you"
This commit is contained in:
parent
59b3ca5643
commit
7f42e8d5f0
5 changed files with 24 additions and 12 deletions
|
|
@ -109,6 +109,7 @@ class TestBrowsing:
|
|||
def test_get_album(self, yt, yt_auth, sample_album):
|
||||
album = yt_auth.get_album(sample_album)
|
||||
assert len(album) >= 9
|
||||
assert album["related_recommendations"]
|
||||
assert "isExplicit" in album
|
||||
assert album["tracks"][0]["isExplicit"]
|
||||
assert all(item["views"] is not None for item in album["tracks"])
|
||||
|
|
@ -141,13 +142,14 @@ class TestBrowsing:
|
|||
assert album["audioPlaylistId"] is not None
|
||||
assert len(album["tracks"]) == 11
|
||||
|
||||
def test_get_album_other_versions(self, yt):
|
||||
def test_get_album_other_versions(self, yt, yt_oauth):
|
||||
# Eminem - Curtain Call: The Hits (Explicit Variant)
|
||||
album = yt.get_album("MPREb_LQCAymzbaKJ")
|
||||
album = yt_oauth.get_album("MPREb_LQCAymzbaKJ")
|
||||
variants = album["other_versions"]
|
||||
assert len(variants) >= 1 # appears to be regional
|
||||
variant = variants[0]
|
||||
assert variant["type"] == "Album"
|
||||
assert variant["title"] == album["title"]
|
||||
assert len(variant["artists"]) == 1
|
||||
assert variant["artists"][0] == {"name": "Eminem", "id": "UCedvOgsKFzcK3hA5taf3KoQ"}
|
||||
assert variant["audioPlaylistId"] is not None
|
||||
|
|
@ -158,11 +160,13 @@ class TestBrowsing:
|
|||
assert not album["isExplicit"]
|
||||
variant = album["other_versions"][0]
|
||||
assert variant["type"] == "Single"
|
||||
assert variant["title"] == "Prada"
|
||||
assert variant["isExplicit"]
|
||||
assert len(variant["artists"]) == 3
|
||||
assert variant["artists"][0]["id"] == "UCGWMNnI1Ky5bMcRlr73Cj2Q"
|
||||
assert variant["artists"][1]["name"] == "RAYE"
|
||||
assert variant["artists"][2] == {"id": "UCb7jnkQW94hzOoWkG14zs4w", "name": "D-Block Europe"}
|
||||
assert variant["audioPlaylistId"] is not None
|
||||
|
||||
def test_get_song(self, config, yt, yt_oauth, sample_video):
|
||||
song = yt_oauth.get_song(config["uploads"]["private_upload_id"]) # private upload
|
||||
|
|
|
|||
|
|
@ -564,11 +564,17 @@ class BrowsingMixin(MixinProtocol):
|
|||
results = nav(response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST_ITEM, *MUSIC_SHELF])
|
||||
album["tracks"] = parse_playlist_items(results["contents"], is_album=True)
|
||||
|
||||
other_versions = nav(
|
||||
response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST, 1, *CAROUSEL], True
|
||||
secondary_carousels = (
|
||||
nav(response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION_LIST], True) or []
|
||||
)
|
||||
if other_versions is not None:
|
||||
album["other_versions"] = parse_content_list(other_versions["contents"], parse_album)
|
||||
for section in secondary_carousels[1:]:
|
||||
carousel = nav(section, CAROUSEL)
|
||||
key = {
|
||||
"COLLECTION_STYLE_ITEM_SIZE_SMALL": "related_recommendations",
|
||||
"COLLECTION_STYLE_ITEM_SIZE_MEDIUM": "other_versions",
|
||||
}[carousel["itemSize"]]
|
||||
album[key] = parse_content_list(carousel["contents"], parse_album)
|
||||
|
||||
album["duration_seconds"] = sum_total_duration(album)
|
||||
for i, track in enumerate(album["tracks"]):
|
||||
album["tracks"][i]["album"] = album["title"]
|
||||
|
|
|
|||
|
|
@ -85,3 +85,8 @@ def parse_album_header_2024(response: JsonDict) -> JsonDict:
|
|||
album["likeStatus"] = parse_like_status(service)
|
||||
|
||||
return album
|
||||
|
||||
|
||||
def parse_album_playlistid_if_exists(data: JsonDict | None) -> str | None:
|
||||
"""the content of the data changes based on whether the user is authenticated or not"""
|
||||
return nav(data, WATCH_PID, True) or nav(data, WATCH_PLAYLIST_ID, True) if data else None
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import re
|
|||
|
||||
from ytmusicapi.type_alias import JsonDict, JsonList, ParseFuncDictType
|
||||
|
||||
from .albums import parse_album_playlistid_if_exists
|
||||
from .podcasts import parse_episode, parse_podcast
|
||||
from .songs import *
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ def parse_album(result: JsonDict) -> JsonDict:
|
|||
"type": nav(result, SUBTITLE),
|
||||
"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),
|
||||
"audioPlaylistId": parse_album_playlistid_if_exists(nav(result, THUMBNAIL_OVERLAY_NAVIGATION, True)),
|
||||
"thumbnails": nav(result, THUMBNAIL_RENDERER),
|
||||
"isExplicit": nav(result, SUBTITLE_BADGE_LABEL, True) is not None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from ytmusicapi.type_alias import JsonDict, JsonList
|
|||
|
||||
from ..helpers import to_int
|
||||
from ._utils import *
|
||||
from .albums import parse_album_playlistid_if_exists
|
||||
from .songs import *
|
||||
|
||||
ALL_RESULT_TYPES = [
|
||||
|
|
@ -214,11 +215,6 @@ def parse_search_result(
|
|||
return search_result
|
||||
|
||||
|
||||
def parse_album_playlistid_if_exists(data: JsonDict | None) -> str | None:
|
||||
"""the content of the data changes based on whether the user is authenticated or not"""
|
||||
return nav(data, WATCH_PID, True) or nav(data, WATCH_PLAYLIST_ID, True) if data else None
|
||||
|
||||
|
||||
def parse_search_results(
|
||||
results: JsonList,
|
||||
api_search_result_types: list[str],
|
||||
|
|
|
|||
Loading…
Reference in a new issue