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 1 commit
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
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ def fixture_sample_album() -> str:
return "MPREb_4pL8gzRtw1p"


@pytest.fixture(name="badly_indexed_album")
def fixture_badly_indexed_album() -> str:
@pytest.fixture(name="missing_indices_album")
def fixture_missing_indices_album() -> str:
"""Sean Paul - Dutty Classics Collection"""
return "MPREb_TPH4WqN5pUo"


@pytest.fixture(name="disabled_indices_album")
def fixture_disabled_indices_album() -> str:
jcbirdwell marked this conversation as resolved.
Show resolved Hide resolved
"""Kristian Conde - Absolutely Kristian Conde"""
return "MPREb_YuigcYm2erf"


@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, missing_indices_album, disabled_indices_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(missing_indices_album) # album with tracks completely removed
assert results["tracks"][0]["track_number"] == 3
assert results["tracks"][13]["track_number"] == 18
results = yt.get_album(disabled_indices_album) # 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
7 changes: 5 additions & 2 deletions ytmusicapi/parsers/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ 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)
if not isAvailable:
song["track_number"] = None
else:
# returning None from nav is pointless as the keys are always present
song["track_number"] = int(nav(data, ["index", "runs", 0, "text"]))
jcbirdwell marked this conversation as resolved.
Show resolved Hide resolved

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