Skip to content

Commit

Permalink
Continue album/playlist download if single song fails
Browse files Browse the repository at this point in the history
  • Loading branch information
kmille committed Feb 7, 2025
1 parent 6bef924 commit 2592ebc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions deezer_downloader/web/music_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)]
Expand All @@ -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:
Expand All @@ -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?")
Expand Down Expand Up @@ -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?")
Expand Down

0 comments on commit 2592ebc

Please sign in to comment.