sigma67 / spotify_to_ytmusic

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

match.py crashes on privated videos #58

Closed hscasn closed 1 year ago

hscasn commented 1 year ago

match.py iterates through the results from YouTube and scores them. However, if a privated video is fed to it, it will crash.

This happened to me when I was trying to import All My Loving - The Beetles. I got the following response from YouTube:

{'category': 'More from YouTube', 'resultType': 'video', 'title': None, 'videoId': 'VadsG2xoHHE', 'videoType': None, 'duration': None, 'year': None, 'artists': [], 'thumbnails': [{'url': 'https://i.ytimg.com/vi/VadsG2xoHHE/mqdefault.jpg', 'width': 0, 'height': 0}]}

Because the video does not have a title, match.py crashes on this line:

https://github.com/sigma67/spotify_to_ytmusic/blob/master/spotify_to_ytmusic/match.py#L27

A simple workaround is to add a continue to ignore the video. I tried this, and it worked:

if ytm["resultType"] == "video":
    if not title:
        # If the video has been made private, it will not have a title
         continue
    else:
        title_split = title.split("-")
        if len(title_split) == 2:
            title = title_split[1]