diff --git a/deezer_downloader/web/music_backend.py b/deezer_downloader/web/music_backend.py index c354bde..76f5d07 100644 --- a/deezer_downloader/web/music_backend.py +++ b/deezer_downloader/web/music_backend.py @@ -47,7 +47,7 @@ def update_mpd_db(songs, add_to_playlist): return mpd_client.update() if add_to_playlist: - songs = [songs] if type(songs) != list else songs + songs = [songs] if type(songs) is not list else songs songs = make_song_paths_relative_to_mpd_root(songs) while len(mpd_client.search("file", songs[0])) == 0: # c.update() does not block so wait for it @@ -96,7 +96,7 @@ def download_song_and_get_absolute_filename(search_type, song, playlist_name=Non os.mkdir(album_dir) absolute_filename = os.path.join(album_dir, song_filename) elif search_type == TYPE_PLAYLIST: - assert type(playlist_name) == str + assert type(playlist_name) is str playlist_name = clean_filename(playlist_name) playlist_dir = os.path.join(config["download_dirs"]["playlists"], playlist_name) if not os.path.exists(playlist_dir): @@ -156,9 +156,12 @@ def download_deezer_album_and_queue_and_zip(album_id, add_to_playlist, create_zi songs_absolute_location = [] for i, song in enumerate(songs): report_progress(i, len(songs)) - assert type(song) == dict - absolute_filename = download_song_and_get_absolute_filename(TYPE_ALBUM, song) - songs_absolute_location.append(absolute_filename) + assert type(song) is dict + try: + absolute_filename = download_song_and_get_absolute_filename(TYPE_ALBUM, song) + songs_absolute_location.append(absolute_filename) + except Exception as e: + print(f"Warning: {e}. Continuing with album...") update_mpd_db(songs_absolute_location, add_to_playlist) if create_zip: return [create_zip_file(songs_absolute_location)] @@ -171,8 +174,11 @@ def download_deezer_playlist_and_queue_and_zip(playlist_id, add_to_playlist, cre songs_absolute_location = [] for i, song in enumerate(songs): report_progress(i, len(songs)) - absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, playlist_name) - songs_absolute_location.append(absolute_filename) + try: + absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, playlist_name) + songs_absolute_location.append(absolute_filename) + except Exception as e: + print(f"Warning: {e}. Continuing with playlist...") update_mpd_db(songs_absolute_location, add_to_playlist) songs_with_m3u8_file = create_m3u8_file(songs_absolute_location) if create_zip: @@ -192,8 +198,11 @@ def download_spotify_playlist_and_queue_and_zip(playlist_name, playlist_id, add_ try: track_id = deezer_search(song_of_playlist, TYPE_TRACK)[0]['id'] #[0] can throw IndexError song = get_song_infos_from_deezer_website(TYPE_TRACK, track_id) - absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, playlist_name) - songs_absolute_location.append(absolute_filename) + try: + absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, playlist_name) + songs_absolute_location.append(absolute_filename) + except Exception as e: + print(f"Warning: {e}. Continuing with Spotify playlist...") except (IndexError, Deezer403Exception, Deezer404Exception) as msg: print(msg) print(f"Could not find Spotify song ({song_of_playlist}) on Deezer?") @@ -223,8 +232,11 @@ def download_deezer_favorites(user_id: str, add_to_playlist: bool, create_zip: b report_progress(i, len(favorite_songs)) try: song = get_song_infos_from_deezer_website(TYPE_TRACK, fav_song) - absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, output_directory) - songs_absolute_location.append(absolute_filename) + try: + absolute_filename = download_song_and_get_absolute_filename(TYPE_PLAYLIST, song, output_directory) + songs_absolute_location.append(absolute_filename) + except Exception as e: + print(f"Warning: {e}. Continuing with favorties...") except (IndexError, Deezer403Exception, Deezer404Exception) as msg: print(msg) print(f"Could not find song ({fav_song}) on Deezer?")