Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_album: track_number returns none when track unavailable + test #516

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ 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"""
Expand Down
6 changes: 4 additions & 2 deletions tests/mixins/test_browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_get_album_browse_id_issue_470(self, yt):
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, badly_indexed_album):
def test_get_album(self, yt, yt_auth, sample_album):
results = yt_auth.get_album(sample_album)
assert len(results) >= 9
assert results["tracks"][0]["isExplicit"]
Expand All @@ -80,9 +80,11 @@ def test_get_album(self, yt, yt_auth, sample_album, badly_indexed_album):
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
results = yt.get_album("MPREb_TPH4WqN5pUo") # album with tracks completely removed/missing
assert results["tracks"][0]["track_number"] == 3
assert results["tracks"][13]["track_number"] == 18
results = yt.get_album("MPREb_YuigcYm2erf") # album with track (#8) disabled/greyed out
assert results["tracks"][7]["track_number"] is None

def test_get_song(self, config, yt, yt_oauth, sample_video):
song = yt_oauth.get_song(config["uploads"]["private_upload_id"]) # private upload
Expand Down
3 changes: 1 addition & 2 deletions ytmusicapi/parsers/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def parse_playlist_items(results, menu_entries: Optional[List[List]] = None, is_
}

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)
song["track_number"] = int(nav(data, ["index", "runs", 0, "text"])) if isAvailable else None

if duration:
song["duration"] = duration
Expand Down
Loading