Taiko2k / Tauon

The music player of today! :city_sunrise:
https://tauonmusicbox.rocks
GNU General Public License v3.0
1.77k stars 67 forks source link

Check type of track before trying to load. #1044

Closed jduar closed 11 months ago

jduar commented 11 months ago

When I was trying to import all of my Spotify playlists, I ran into this error:

Exception in thread Thread-13 (import_all_playlists):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/app/bin/t_modules/t_spot.py", line 294, in import_all_playlists
    self.playlist(item[1], silent=True)
  File "/app/bin/t_modules/t_spot.py", line 773, in playlist
    nt = self.load_track(item.track, include_album_url=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bin/t_modules/t_spot.py", line 961, in load_track
    if "spotify" in track.artists[0].external_urls:
                    ^^^^^^^^^^^^^
AttributeError: 'FullPlaylistEpisode' object has no attribute 'artists'

I noticed this happened because of playlists that contained podcast episodes. The same will happen with playlists that contain local music files. I didn't want to manually add only playlists that contained music tracks as I have way too many, so I came up with this solution.

I'm basically checking the type of the track and ensuring it is a music track before trying to load its information.

Do tell me if you'd rather implement a fancier solution. Since loading anything other than a music track currently leads to an Error, I assumed podcasts and etc. weren't meant to be supported.