-
Notifications
You must be signed in to change notification settings - Fork 75
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
ZeroDivisionError: float division by zero #32
Comments
I think we need a 0 check for song['duration'] what do you think @sigma67 I'm trying it right now in this huge playlist of 1200 songs. If it works I can get a pr out or something. |
Can you point the specific song this is happening with? Could certainly introduce a workaround for the case that the duration is missing |
Alternatively please link the playlist in question |
I have the same problem, I was trying with this playlist |
I think we need to find a song where this consistently occurs, it no longer works for me with the above playlist |
I will try to work on this bug in my spare time. I will let you know what I find |
This isn't a consistent bug and I think it is in the way the YTMusic library parses songs, sometimes one of the search results will be empty and thats when the bug occurs. I tried with the following code to print the song information: durationMatch = None
if 'duration' in res and res['duration']:
durationItems = res['duration'].split(':')
duration = int(durationItems[0]) * 60 + int(durationItems[1])
print(song)
durationMatch = 1 - abs(duration - song['duration']) * 2 / song['duration'] and the output is:
as you can see the last result is has all the values empty. Maybe to work out this bug, we can remove the "bad" results (or skip it directly) and then do all the math so this problem can't happen. Let me know what do you think |
Oh so the dictionary is completely empty? That seems like it would be a bug in ytmusicapi. Can you post the search query used for this empty result? |
Yes, it seems to be a ytmusic library problem. When I come back home I'll post the search query. |
Turns out that the search query is empty: Query: Don Toliver Kali Uchis Drugs N Hella Melodies
Query: Don Toliver Travis Scott Flocky Flocky
Query:
Traceback (most recent call last):
File "/Users/samurai/Documents/progetti/spotifyplaylist_to_ytmusic/YouTube.py", line 201, in <module>
main()
File "/Users/samurai/Documents/progetti/spotifyplaylist_to_ytmusic/YouTube.py", line 193, in main
videoIds = ytmusic.search_songs(playlist['tracks'])
File "/Users/samurai/Documents/progetti/spotifyplaylist_to_ytmusic/YouTube.py", line 78, in search_songs
targetSong = self.get_best_fit_song_id(result, song)
File "/Users/samurai/Documents/progetti/spotifyplaylist_to_ytmusic/YouTube.py", line 35, in get_best_fit_song_id
durationMatch = 1 - abs(duration - song['duration']) * 2 / song['duration']
ZeroDivisionError: float division by zero Very strange |
After debugging for some time I found what was causing the bug for me. |
Got this error today, any workaround? |
I got this today and what I did was to check where it is failling in the console:
With that, go to your Spotify playlist and check for the songs after "360". One of them will probably be a 0:00 minute song. |
Traceback (most recent call last):
File "YouTube.py", line 190, in
main()
File "YouTube.py", line 182, in main
videoIds = ytmusic.search_songs(playlist['tracks'])
File "YouTube.py", line 74, in search_songs
targetSong = self.get_best_fit_song_id(result, song)
File "YouTube.py", line 32, in get_best_fit_song_id
durationMatch = 1 - abs(duration - song['duration']) * 2 / song['duration']
ZeroDivisionError: float division by zero
The text was updated successfully, but these errors were encountered: