get_album: track positions (#510)
* get_album (via parse_playlist_items): add track_position key + tests for the badly indexed album * get_album & parse_playlist_items: nav changes * parse_playlist_items: only add track_position for albums * parse_playlist_items & related test_browsing: track_position > track_number --------- Co-authored-by: sigma67 <sigma67.github@gmail.com>
This commit is contained in:
parent
b60bcd7675
commit
ba71fc998d
4 changed files with 18 additions and 3 deletions
|
|
@ -24,6 +24,12 @@ def fixture_sample_album() -> str:
|
|||
return "MPREb_4pL8gzRtw1p"
|
||||
|
||||
|
||||
@pytest.fixture(name="badly_indexed_album")
|
||||
def fixture_badly_indexed_album() -> str:
|
||||
"""Sean Paul - Dutty Classics Collection"""
|
||||
return "MPREb_TPH4WqN5pUo"
|
||||
|
||||
|
||||
@pytest.fixture(name="sample_video")
|
||||
def fixture_sample_video() -> str:
|
||||
"""Oasis - Wonderwall"""
|
||||
|
|
|
|||
|
|
@ -66,12 +66,13 @@ class TestBrowsing:
|
|||
escaped_browse_id = yt.get_album_browse_id("OLAK5uy_nbMYyrfeg5ZgknoOsOGBL268hGxtcbnDM")
|
||||
assert escaped_browse_id == "MPREb_scJdtUCpPE2"
|
||||
|
||||
def test_get_album(self, yt, yt_auth, sample_album):
|
||||
def test_get_album(self, yt, yt_auth, sample_album, badly_indexed_album):
|
||||
results = yt_auth.get_album(sample_album)
|
||||
assert len(results) >= 9
|
||||
assert results["tracks"][0]["isExplicit"]
|
||||
assert all(item["views"] is not None for item in results["tracks"])
|
||||
assert all(item["album"] is not None for item in results["tracks"])
|
||||
assert results["tracks"][0]["track_number"] == 1
|
||||
assert "feedbackTokens" in results["tracks"][0]
|
||||
assert len(results["other_versions"]) >= 1 # appears to be regional
|
||||
results = yt.get_album("MPREb_BQZvl3BFGay")
|
||||
|
|
@ -79,6 +80,9 @@ class TestBrowsing:
|
|||
assert len(results["tracks"][0]["artists"]) == 1
|
||||
results = yt.get_album("MPREb_rqH94Zr3NN0")
|
||||
assert len(results["tracks"][0]["artists"]) == 2
|
||||
results = yt.get_album(badly_indexed_album) # album with non-standard indexing
|
||||
assert results["tracks"][0]["track_number"] == 3
|
||||
assert results["tracks"][13]["track_number"] == 18
|
||||
|
||||
def test_get_song(self, config, yt, yt_oauth, sample_video):
|
||||
song = yt_oauth.get_song(config["uploads"]["private_upload_id"]) # private upload
|
||||
|
|
|
|||
|
|
@ -494,7 +494,7 @@ class BrowsingMixin(MixinProtocol):
|
|||
response = self._send_request(endpoint, body)
|
||||
album = parse_album_header(response)
|
||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
|
||||
album["tracks"] = parse_playlist_items(results["contents"])
|
||||
album["tracks"] = parse_playlist_items(results["contents"], is_album=True)
|
||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + CAROUSEL, True)
|
||||
if results is not None:
|
||||
album["other_versions"] = parse_content_list(results["contents"], parse_album)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import List, Optional
|
|||
from .songs import *
|
||||
|
||||
|
||||
def parse_playlist_items(results, menu_entries: Optional[List[List]] = None):
|
||||
def parse_playlist_items(results, menu_entries: Optional[List[List]] = None, is_album=False):
|
||||
songs = []
|
||||
for result in results:
|
||||
if MRLIR not in result:
|
||||
|
|
@ -92,6 +92,11 @@ def parse_playlist_items(results, menu_entries: Optional[List[List]] = None):
|
|||
"videoType": videoType,
|
||||
"views": views,
|
||||
}
|
||||
|
||||
if is_album:
|
||||
track_idx_found = nav(data, ["index", "runs", 0, "text"], True)
|
||||
song["track_number"] = track_idx_found if track_idx_found is None else int(track_idx_found)
|
||||
|
||||
if duration:
|
||||
song["duration"] = duration
|
||||
song["duration_seconds"] = parse_duration(duration)
|
||||
|
|
|
|||
Loading…
Reference in a new issue