sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.59k stars 182 forks source link

`get_playlist` does not work for all languages #606

Closed JohnHKoh closed 2 weeks ago

JohnHKoh commented 2 weeks ago

Describe the bug I receive the following errors when trying to run get_playlist with the Korean ("ko") language using v1.7.3:

Traceback (most recent call last):
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 64, in to_int
    int_value = locale.atoi(number_string)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\locale.py", line 342, in atoi
    return int(delocalize(string))
           ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

and

  File "C:\Users\asdf\Source\MelonYTMPlaylist\src\playlist_updater.py", line 117, in get_playlist
    return self.ytmusic.get_playlist(self.playlistId, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 111, in get_playlist
    return self._parse_new_playlist_format(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 215, in _parse_new_playlist_format
    song_count = to_int(song_count[0]) if len(song_count) > 1 else 0
                 ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 67, in to_int
    int_value = int(number_string)
                ^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

To Reproduce Steps to reproduce the behavior:

  1. Set YTMusic language parameter to Korean (language="ko")
  2. Run ytmusic.get_playlist(playlistId)
  3. See error

Additional context https://github.com/sigma67/ytmusicapi/blob/11823d638719d76456ec58a6d7b76133368e5f1a/ytmusicapi/mixins/playlists.py#L214-L215 These seem to be the offending lines. While English returns "100 tracks" for second_subtitle_runs[has_views + 0]["text"], in Korean, it returns "트랙 100개", Therefore, song_count[0] does not have the correct value in the Korean language. The integer should be extracted from the string to account for such differences.

JohnHKoh commented 2 weeks ago

Closing as duplicate.