Skip to content

Commit

Permalink
Fix 'secondSubtitle' KeyError for some playlists (#399)
Browse files Browse the repository at this point in the history
* Fix 'secondSubtitle' KeyError for some playlists

* Feedback.
  • Loading branch information
MarvinSchenkel authored and sigma67 committed Jul 21, 2023
1 parent eef8ffd commit c3e65f5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ytmusicapi/mixins/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ def get_playlist(self,
if run_count == 5:
playlist['year'] = nav(header, SUBTITLE3)

second_subtitle_runs = header['secondSubtitle']['runs']

has_views = (len(second_subtitle_runs) > 3) * 2
playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text'])
has_duration = (len(second_subtitle_runs) > 1) * 2
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
playlist['views'] = None
playlist['duration'] = None
if 'runs' in header['secondSubtitle']:
second_subtitle_runs = header['secondSubtitle']['runs']
has_views = (len(second_subtitle_runs) > 3) * 2
playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text'])
has_duration = (len(second_subtitle_runs) > 1) * 2
playlist['duration'] = None if not has_duration else second_subtitle_runs[has_views + has_duration]['text']

song_count = len(results['contents'])
playlist['trackCount'] = song_count

request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams)
Expand Down

0 comments on commit c3e65f5

Please sign in to comment.