improve coverage
This commit is contained in:
parent
da492e49f6
commit
f98274f0ec
5 changed files with 15 additions and 26 deletions
|
|
@ -86,6 +86,10 @@ class TestBrowsing:
|
|||
album = yt.get_album("MPREb_YuigcYm2erf") # album with track (#8) disabled/greyed out
|
||||
assert album["tracks"][7]["trackNumber"] is None
|
||||
|
||||
def test_get_album_errors(self, yt):
|
||||
with pytest.raises(Exception, match="Invalid album browseId"):
|
||||
yt.get_album("asdf")
|
||||
|
||||
def test_get_album_other_versions(self, yt):
|
||||
# Eminem - Curtain Call: The Hits (Explicit Variant)
|
||||
album = yt.get_album("MPREb_LQCAymzbaKJ")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
import pytest
|
||||
|
||||
|
||||
class TestWatch:
|
||||
def test_get_watch_playlist(self, config, yt, yt_brand, yt_oauth):
|
||||
playlist = yt_oauth.get_watch_playlist(
|
||||
|
|
@ -14,3 +17,7 @@ class TestWatch:
|
|||
assert len(playlist["tracks"]) == config.getint("albums", "album_track_length")
|
||||
playlist = yt_brand.get_watch_playlist(playlistId=config["playlists"]["own"], shuffle=True)
|
||||
assert len(playlist["tracks"]) == config.getint("playlists", "own_length")
|
||||
|
||||
def test_get_watch_playlist_errors(self, config, yt):
|
||||
with pytest.raises(Exception, match="No content returned by the server"):
|
||||
yt.get_watch_playlist(playlistId="PL_NOT_EXIST")
|
||||
|
|
|
|||
|
|
@ -51,19 +51,12 @@ def get_fixed_column_item(item, index):
|
|||
return item["fixedColumns"][index]["musicResponsiveListItemFixedColumnRenderer"]
|
||||
|
||||
|
||||
def get_browse_id(item, index):
|
||||
if "navigationEndpoint" not in item["text"]["runs"][index]:
|
||||
return None
|
||||
else:
|
||||
return nav(item["text"]["runs"][index], NAVIGATION_BROWSE_ID)
|
||||
|
||||
|
||||
def get_dot_separator_index(runs):
|
||||
index = len(runs)
|
||||
try:
|
||||
index = runs.index({"text": " • "})
|
||||
except ValueError:
|
||||
len(runs)
|
||||
index = len(runs)
|
||||
|
||||
return index
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,22 +24,6 @@ def parse_chart_artist(data):
|
|||
return parsed
|
||||
|
||||
|
||||
def parse_chart_trending(data):
|
||||
flex_0 = get_flex_column_item(data, 0)
|
||||
artists = parse_song_artists(data, 1)
|
||||
index = get_dot_separator_index(artists)
|
||||
# last item is views for some reason
|
||||
views = None if index == len(artists) else artists.pop()["name"].split(" ")[0]
|
||||
return {
|
||||
"title": nav(flex_0, TEXT_RUN_TEXT),
|
||||
"videoId": nav(flex_0, TEXT_RUN + NAVIGATION_VIDEO_ID, True),
|
||||
"playlistId": nav(flex_0, TEXT_RUN + NAVIGATION_PLAYLIST_ID, True),
|
||||
"artists": artists,
|
||||
"thumbnails": nav(data, THUMBNAILS),
|
||||
"views": views,
|
||||
}
|
||||
|
||||
|
||||
def parse_ranking(data):
|
||||
return {
|
||||
"rank": nav(data, ["customIndexColumn", "musicCustomIndexColumnRenderer", *TEXT_RUN_TEXT]),
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ def parse_song_runs(runs):
|
|||
|
||||
def parse_song_album(data, index):
|
||||
flex_item = get_flex_column_item(data, index)
|
||||
return None if not flex_item else {"name": get_item_text(data, index), "id": get_browse_id(flex_item, 0)}
|
||||
browse_id = nav(flex_item, TEXT_RUN + NAVIGATION_BROWSE_ID, True)
|
||||
return None if not flex_item else {"name": get_item_text(data, index), "id": browse_id}
|
||||
|
||||
|
||||
def parse_song_library_status(item) -> bool:
|
||||
|
|
|
|||
Loading…
Reference in a new issue