diff --git a/tests/mixins/test_playlists.py b/tests/mixins/test_playlists.py index dc55e9ba..27261c06 100644 --- a/tests/mixins/test_playlists.py +++ b/tests/mixins/test_playlists.py @@ -5,6 +5,9 @@ import pytest +from ytmusicapi import YTMusic +from ytmusicapi.constants import SUPPORTED_LANGUAGES + class TestPlaylists: @pytest.mark.parametrize( @@ -57,6 +60,12 @@ def test_get_playlist_foreign_new_format(self, yt_empty): assert len(playlist["tracks"]) > 200 assert len(playlist["related"]) == 0 + @pytest.mark.parametrize("language", SUPPORTED_LANGUAGES) + def test_get_playlist_languages(self, language): + yt = YTMusic(language=language) + result = yt.get_playlist("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk") + assert result["trackCount"] == 255 + def test_get_playlist_owned(self, config, yt_brand): playlist = yt_brand.get_playlist(config["playlists"]["own"], related=True, suggestions_limit=21) assert len(playlist["tracks"]) < 100 diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 35281c75..3c973a67 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -211,8 +211,10 @@ def _parse_new_playlist_format( playlist["duration"] = ( None if not has_duration else second_subtitle_runs[has_views + has_duration]["text"] ) - song_count = second_subtitle_runs[has_views + 0]["text"].split(" ") - song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 + song_count_text = second_subtitle_runs[has_views + 0]["text"] + song_count_search = re.search(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 else: song_count = len(section_list["contents"]) diff --git a/ytmusicapi/parsers/playlists.py b/ytmusicapi/parsers/playlists.py index 9307b5fa..f9c46d13 100644 --- a/ytmusicapi/parsers/playlists.py +++ b/ytmusicapi/parsers/playlists.py @@ -44,8 +44,10 @@ def parse_playlist_header(response: Dict) -> Dict[str, Any]: playlist["duration"] = ( None if not has_duration else second_subtitle_runs[has_views + has_duration]["text"] ) - song_count = second_subtitle_runs[has_views + 0]["text"].split(" ") - song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 + song_count_text = second_subtitle_runs[has_views + 0]["text"] + song_count_search = re.search(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 playlist["trackCount"] = song_count return playlist