couldbejake / spotify2mp3

Simple free and unlimited Spotify playlist downloads. Spotify2mp3 - Spotify Downloader
MIT License
270 stars 42 forks source link

more resilient code for trying to convert with int() #17

Closed ElectricPotato closed 1 year ago

ElectricPotato commented 2 years ago

the line for getting "song_viewcount" can fail if yt_data['views'] contains the string "No views", a simple fix for this is

                sd_data = yt_data['duration'].split(':')
                try:
                    song_duration = int(sd_data[0]) * 60  + int(sd_data[1])
                except ValueError:
                    print(f"Song duration unavailable, got string {yt_data['duration']}")

                try:
                    song_viewcount = int(re.sub('[^0-9]','', yt_data['views']))
                except ValueError:
                    print(f"Song viewcount unavailable, got string {yt_data['views']}")

a recent example of this is "Larina Sin Valor", the 10th song in https://open.spotify.com/playlist/37i9dQZF1DWWQRwui0ExPn unless of course someone has viewed it once by now

couldbejake commented 2 years ago

Hi, sorry for the late reply.

Shouldn't sd_data = yt_data['duration'].split(':') be inside the try part of the try-catch statement?

I'm happy to make that change to the code, if you just submit a pull request!

It looks like this repo is taking off, so there will be other feature additions and this could definitely help!

Thanks, Jake

couldbejake commented 1 year ago

This bug was kindly patched by @DMaxence’s in their recent pull request.