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

Extract song count from text #607

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions ytmusicapi/mixins/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
6 changes: 4 additions & 2 deletions ytmusicapi/parsers/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading