From 3834a4bccc59b993ab37c0c80abd8433f937c43f Mon Sep 17 00:00:00 2001 From: "architect.in.git" Date: Sat, 22 Mar 2025 07:54:55 -0600 Subject: [PATCH] deezer error is reported immediately --- routes/utils/album.py | 107 +++++++++++++++++++++------------------ routes/utils/playlist.py | 9 +++- routes/utils/track.py | 69 +++++++++++++++---------- 3 files changed, 106 insertions(+), 79 deletions(-) diff --git a/routes/utils/album.py b/routes/utils/album.py index 459a880..312c403 100755 --- a/routes/utils/album.py +++ b/routes/utils/album.py @@ -49,61 +49,31 @@ def download_album( quality = 'FLAC' if fall_quality is None: fall_quality = 'HIGH' - # First attempt: use DeeLogin's download_albumspo with the 'main' (Deezer credentials) - try: - # Load Deezer credentials from 'main' under deezer directory - deezer_creds_dir = os.path.join('./creds/deezer', main) - deezer_creds_path = os.path.abspath(os.path.join(deezer_creds_dir, 'credentials.json')) - with open(deezer_creds_path, 'r') as f: - deezer_creds = json.load(f) - # Initialize DeeLogin with Deezer credentials and Spotify client credentials - dl = DeeLogin( - arl=deezer_creds.get('arl', ''), - spotify_client_id=spotify_client_id, - spotify_client_secret=spotify_client_secret, - progress_callback=progress_callback - ) - # Download using download_albumspo; pass real_time_dl accordingly and the custom formatting - dl.download_albumspo( - link_album=url, - output_dir="./downloads", - quality_download=quality, - recursive_quality=True, - recursive_download=False, - not_interface=False, - make_zip=False, - method_save=1, - custom_dir_format=custom_dir_format, - custom_track_format=custom_track_format, - pad_tracks=pad_tracks, - initial_retry_delay=initial_retry_delay, - retry_delay_increase=retry_delay_increase, - max_retries=max_retries - ) - except Exception as e: - # Load fallback Spotify credentials and attempt download + # First attempt: use DeeLogin's download_albumspo with the 'main' (Deezer credentials) + deezer_error = None try: - spo_creds_dir = os.path.join('./creds/spotify', fallback) - spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) - - # We've already loaded the Spotify client credentials above based on fallback - - spo = SpoLogin( - credentials_path=spo_creds_path, + # Load Deezer credentials from 'main' under deezer directory + deezer_creds_dir = os.path.join('./creds/deezer', main) + deezer_creds_path = os.path.abspath(os.path.join(deezer_creds_dir, 'credentials.json')) + with open(deezer_creds_path, 'r') as f: + deezer_creds = json.load(f) + # Initialize DeeLogin with Deezer credentials and Spotify client credentials + dl = DeeLogin( + arl=deezer_creds.get('arl', ''), spotify_client_id=spotify_client_id, spotify_client_secret=spotify_client_secret, progress_callback=progress_callback ) - spo.download_album( + # Download using download_albumspo; pass real_time_dl accordingly and the custom formatting + dl.download_albumspo( link_album=url, output_dir="./downloads", - quality_download=fall_quality, + quality_download=quality, recursive_quality=True, recursive_download=False, not_interface=False, - method_save=1, make_zip=False, - real_time_dl=real_time, + method_save=1, custom_dir_format=custom_dir_format, custom_track_format=custom_track_format, pad_tracks=pad_tracks, @@ -111,12 +81,49 @@ def download_album( retry_delay_increase=retry_delay_increase, max_retries=max_retries ) - except Exception as e2: - # If fallback also fails, raise an error indicating both attempts failed - raise RuntimeError( - f"Both main (Deezer) and fallback (Spotify) attempts failed. " - f"Deezer error: {e}, Spotify error: {e2}" - ) from e2 + except Exception as e: + deezer_error = e + # Immediately report the Deezer error + print(f"ERROR: Deezer album download attempt failed: {e}") + traceback.print_exc() + print("Attempting Spotify fallback...") + + # Load fallback Spotify credentials and attempt download + try: + spo_creds_dir = os.path.join('./creds/spotify', fallback) + spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) + + # We've already loaded the Spotify client credentials above based on fallback + + spo = SpoLogin( + credentials_path=spo_creds_path, + spotify_client_id=spotify_client_id, + spotify_client_secret=spotify_client_secret, + progress_callback=progress_callback + ) + spo.download_album( + link_album=url, + output_dir="./downloads", + quality_download=fall_quality, + recursive_quality=True, + recursive_download=False, + not_interface=False, + method_save=1, + make_zip=False, + real_time_dl=real_time, + custom_dir_format=custom_dir_format, + custom_track_format=custom_track_format, + pad_tracks=pad_tracks, + initial_retry_delay=initial_retry_delay, + retry_delay_increase=retry_delay_increase, + max_retries=max_retries + ) + except Exception as e2: + # If fallback also fails, raise an error indicating both attempts failed + raise RuntimeError( + f"Both main (Deezer) and fallback (Spotify) attempts failed. " + f"Deezer error: {deezer_error}, Spotify error: {e2}" + ) from e2 else: # Original behavior: use Spotify main if quality is None: diff --git a/routes/utils/playlist.py b/routes/utils/playlist.py index cb3113d..9b247a6 100755 --- a/routes/utils/playlist.py +++ b/routes/utils/playlist.py @@ -50,6 +50,7 @@ def download_playlist( if fall_quality is None: fall_quality = 'HIGH' # First attempt: use DeeLogin's download_playlistspo with the 'main' (Deezer credentials) + deezer_error = None try: # Load Deezer credentials from 'main' under deezer directory deezer_creds_dir = os.path.join('./creds/deezer', main) @@ -81,6 +82,12 @@ def download_playlist( max_retries=max_retries ) except Exception as e: + deezer_error = e + # Immediately report the Deezer error + print(f"ERROR: Deezer playlist download attempt failed: {e}") + traceback.print_exc() + print("Attempting Spotify fallback...") + # Load fallback Spotify credentials and attempt download try: spo_creds_dir = os.path.join('./creds/spotify', fallback) @@ -115,7 +122,7 @@ def download_playlist( # If fallback also fails, raise an error indicating both attempts failed raise RuntimeError( f"Both main (Deezer) and fallback (Spotify) attempts failed. " - f"Deezer error: {e}, Spotify error: {e2}" + f"Deezer error: {deezer_error}, Spotify error: {e2}" ) from e2 else: # Original behavior: use Spotify main diff --git a/routes/utils/track.py b/routes/utils/track.py index bd1d306..4b87bfc 100755 --- a/routes/utils/track.py +++ b/routes/utils/track.py @@ -56,6 +56,7 @@ def download_track( if fall_quality is None: fall_quality = 'HIGH' # First attempt: use Deezer's download_trackspo with 'main' (Deezer credentials) + deezer_error = None try: deezer_creds_dir = os.path.join('./creds/deezer', main) deezer_creds_path = os.path.abspath(os.path.join(deezer_creds_dir, 'credentials.json')) @@ -95,35 +96,47 @@ def download_track( max_retries=max_retries ) except Exception as e: - print(f"DEBUG: Deezer download attempt failed: {e}") + deezer_error = e + # Immediately report the Deezer error + print(f"ERROR: Deezer download attempt failed: {e}") + traceback.print_exc() + print("Attempting Spotify fallback...") + # If the first attempt fails, use the fallback Spotify credentials - spo_creds_dir = os.path.join('./creds/spotify', fallback) - spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) - - # We've already loaded the Spotify client credentials above based on fallback - - spo = SpoLogin( - credentials_path=spo_creds_path, - spotify_client_id=spotify_client_id, - spotify_client_secret=spotify_client_secret, - progress_callback=progress_callback - ) - spo.download_track( - link_track=url, - output_dir="./downloads", - quality_download=fall_quality, - recursive_quality=False, - recursive_download=False, - not_interface=False, - method_save=1, - real_time_dl=real_time, - custom_dir_format=custom_dir_format, - custom_track_format=custom_track_format, - pad_tracks=pad_tracks, - initial_retry_delay=initial_retry_delay, - retry_delay_increase=retry_delay_increase, - max_retries=max_retries - ) + try: + spo_creds_dir = os.path.join('./creds/spotify', fallback) + spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) + + # We've already loaded the Spotify client credentials above based on fallback + + spo = SpoLogin( + credentials_path=spo_creds_path, + spotify_client_id=spotify_client_id, + spotify_client_secret=spotify_client_secret, + progress_callback=progress_callback + ) + spo.download_track( + link_track=url, + output_dir="./downloads", + quality_download=fall_quality, + recursive_quality=False, + recursive_download=False, + not_interface=False, + method_save=1, + real_time_dl=real_time, + custom_dir_format=custom_dir_format, + custom_track_format=custom_track_format, + pad_tracks=pad_tracks, + initial_retry_delay=initial_retry_delay, + retry_delay_increase=retry_delay_increase, + max_retries=max_retries + ) + except Exception as e2: + # If fallback also fails, raise an error indicating both attempts failed + raise RuntimeError( + f"Both main (Deezer) and fallback (Spotify) attempts failed. " + f"Deezer error: {deezer_error}, Spotify error: {e2}" + ) from e2 else: # Directly use Spotify main account if quality is None: