From 1d62e9865071e23d1a1375c6569bc41356ab800d Mon Sep 17 00:00:00 2001 From: John Koh Date: Fri, 21 Jun 2024 13:35:29 -0400 Subject: [PATCH 1/2] Extract song count from text --- ytmusicapi/mixins/playlists.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 35281c7..3c973a6 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"]) From ffc0eba3f5cdadaeba40a170995e649e5152b800 Mon Sep 17 00:00:00 2001 From: John Koh Date: Fri, 21 Jun 2024 13:44:26 -0400 Subject: [PATCH 2/2] Add fix in parsers --- ytmusicapi/parsers/playlists.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ytmusicapi/parsers/playlists.py b/ytmusicapi/parsers/playlists.py index 699a73b..6a0b70b 100644 --- a/ytmusicapi/parsers/playlists.py +++ b/ytmusicapi/parsers/playlists.py @@ -38,8 +38,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