sigma67 / spotify_to_ytmusic

Clone a Spotify playlist to YouTube Music
MIT License
954 stars 72 forks source link

youtube: skip songs that lack duration metadata #18

Closed lucasrangit closed 3 years ago

lucasrangit commented 3 years ago

In my playlist Spotify did not return the duration for the following track.

{'resultType': 'video', 'title': 'Auditory Canvas - Spring Rain', 'views': None, 'videoId': None, 'year': None, 'artists': [], 'thumbnails': [{...}]}

Resulting in the following exception.


Traceback (most recent call last):
...
  File "/usr/lib/python3.8/runpy.py", line 95, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "YouTube.py", line 191, in <module>
    main()
  File "YouTube.py", line 182, in main
    videoIds = ytmusic.search_songs(playlist['tracks'])
  File "YouTube.py", line 75, in search_songs
    targetSong = self.get_best_fit_song_id(result, song)
  File "YouTube.py", line 30, in get_best_fit_song_id
    if res['duration']:
KeyError: 'duration'
sigma67 commented 3 years ago

We should check both if the key exists and if it is None. In your PR it would now crash in cases it previously didn't.

lucasrangit commented 3 years ago

Yeah, you're right. Do you have a sample playlist from Spotify that crashes because the duration value is None?

sigma67 commented 3 years ago

I don't have it anymore but it has definitely happened before or I wouldn't have added that part :)