fix(playlists): handle missing regex group in trackCount (#651)
* fix(playlists): get_playlist trackCount incorrect for playlists with more than 1k tracks This ensures that the regex doesnt just return the first group in 1000+ long playlists. * feat+fix(playlist_tests): Update playlist ID and add new track count test * fix tests --------- Co-authored-by: RealCalumPlays <calumplays666+github@gmail.com> Co-authored-by: sigma67 <sigma67.github@gmail.com>
This commit is contained in:
parent
7b96ac2c5e
commit
5478951ba3
4 changed files with 16 additions and 22 deletions
|
|
@ -41,36 +41,30 @@ class TestPlaylists:
|
|||
if track["videoType"] == "MUSIC_VIDEO_TYPE_ATV":
|
||||
assert isinstance(track["album"]["name"], str) and track["album"]["name"]
|
||||
|
||||
def test_get_playlist_foreign(self, yt, yt_auth, yt_oauth):
|
||||
def test_get_playlist_foreign(self, yt_empty, yt_oauth, sample_playlist):
|
||||
with pytest.raises(Exception):
|
||||
yt.get_playlist("PLABC")
|
||||
playlist = yt_auth.get_playlist("PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA", limit=300, suggestions_limit=7)
|
||||
yt_empty.get_playlist("PLABC")
|
||||
playlist = yt_empty.get_playlist(
|
||||
"RDCLAK5uy_nfjzC9YC1NVPPZHvdoAtKVBOILMDOuxOs", limit=300, suggestions_limit=7
|
||||
)
|
||||
assert len(playlist["duration"]) > 5
|
||||
assert playlist["trackCount"] > 200
|
||||
assert len(playlist["tracks"]) > 200
|
||||
assert "suggestions" not in playlist
|
||||
assert playlist["owned"] is False
|
||||
|
||||
yt.get_playlist("RDATgXd-")
|
||||
playlist = yt_oauth.get_playlist("RDATgXd-")
|
||||
assert playlist["trackCount"] >= 100
|
||||
assert len(playlist["tracks"]) >= 100
|
||||
|
||||
playlist = yt_oauth.get_playlist("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", limit=None, related=True)
|
||||
assert playlist["trackCount"] > 200
|
||||
assert len(playlist["tracks"]) > 200
|
||||
assert len(playlist["related"]) == 0
|
||||
|
||||
def test_get_playlist_foreign_new_format(self, yt_empty):
|
||||
with pytest.raises(Exception):
|
||||
yt_empty.get_playlist("PLABC")
|
||||
playlist = yt_empty.get_playlist("PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA", limit=300, suggestions_limit=7)
|
||||
assert len(playlist["duration"]) > 5
|
||||
assert len(playlist["tracks"]) > 200
|
||||
assert "suggestions" not in playlist
|
||||
assert playlist["owned"] is False
|
||||
|
||||
playlist = yt_empty.get_playlist("RDATgXd-")
|
||||
assert len(playlist["tracks"]) >= 100
|
||||
|
||||
playlist = yt_empty.get_playlist("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", limit=None, related=True)
|
||||
assert len(playlist["tracks"]) > 200
|
||||
playlist = yt_oauth.get_playlist(sample_playlist, limit=1100)
|
||||
assert playlist["trackCount"] > 1000
|
||||
assert len(playlist["tracks"]) > 1000
|
||||
assert len(playlist["related"]) == 0
|
||||
|
||||
@pytest.mark.parametrize("language", SUPPORTED_LANGUAGES)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class TestPodcasts:
|
|||
podcast_id = config["podcasts"]["channel_id"]
|
||||
channel = yt.get_channel(podcast_id)
|
||||
assert len(channel["episodes"]["results"]) == 10
|
||||
assert len(channel["podcasts"]["results"]) > 5
|
||||
assert len(channel["podcasts"]["results"]) >= 5
|
||||
|
||||
def test_get_channel_episodes(self, config, yt_oauth):
|
||||
channel_id = config["podcasts"]["channel_id"]
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class TestSearch:
|
|||
assert len(results) > 10
|
||||
assert all(item["resultType"] == "profile" for item in results)
|
||||
results = yt_auth.search(query, filter="podcasts")
|
||||
assert len(results) > 10
|
||||
assert len(results) > 5
|
||||
assert all(item["resultType"] == "podcast" for item in results)
|
||||
results = yt_auth.search(query, filter="episodes")
|
||||
assert len(results) >= 3
|
||||
|
|
|
|||
|
|
@ -149,9 +149,9 @@ class PlaylistsMixin(MixinProtocol):
|
|||
None if not has_duration else second_subtitle_runs[has_views + has_duration]["text"]
|
||||
)
|
||||
song_count_text = second_subtitle_runs[has_views + 0]["text"]
|
||||
song_count_search = re.search(r"\d+", song_count_text)
|
||||
song_count_search = re.findall(r"\d+", song_count_text)
|
||||
# extract the digits from the text, return 0 if no match
|
||||
song_count = to_int(song_count_search.group()) if song_count_search is not None else 0
|
||||
song_count = to_int("".join(song_count_search)) if song_count_search is not None else 0
|
||||
else:
|
||||
song_count = len(section_list["contents"])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue