From d1e75c572b553628bc665deba1952e078d3cfff9 Mon Sep 17 00:00:00 2001 From: coolgitternotin Date: Thu, 20 Mar 2025 13:24:07 -0600 Subject: [PATCH] update git workers --- .github/workflows/docker-build.yml | 3 ++ docker-compose.yaml | 2 +- routes/utils/album.py | 27 ++++++++--------- routes/utils/celery_config.py | 2 +- routes/utils/celery_tasks.py | 31 +++++++++++++++++++- routes/utils/playlist.py | 27 ++++++++--------- routes/utils/track.py | 47 ++++++++++++++++++++---------- 7 files changed, 91 insertions(+), 48 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 441fbef..3f3842d 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -6,6 +6,8 @@ on: tags: [ 'v*' ] pull_request: branches: [ main, master ] + release: + types: [ published, released ] # Allow manual triggering workflow_dispatch: @@ -36,6 +38,7 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable=${{ github.event_name == 'release' }} type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} # Build and push Docker image diff --git a/docker-compose.yaml b/docker-compose.yaml index 3d21707..09ed90d 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,7 +9,7 @@ services: - ./logs:/app/logs # <-- Volume for persistent logs ports: - 7171:7171 - image: cooldockerizer93/spotizerr + image: spotizerr:dev container_name: spotizerr-app restart: unless-stopped environment: diff --git a/routes/utils/album.py b/routes/utils/album.py index 8d9a939..459a880 100755 --- a/routes/utils/album.py +++ b/routes/utils/album.py @@ -25,7 +25,15 @@ def download_album( # Load Spotify client credentials if available spotify_client_id = None spotify_client_secret = None - search_creds_path = Path(f'./creds/spotify/{main}/search.json') + + # Smartly determine where to look for Spotify search credentials + if service == 'spotify' and fallback: + # If fallback is enabled, use the fallback account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{fallback}/search.json') + else: + # Otherwise use the main account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{main}/search.json') + if search_creds_path.exists(): try: with open(search_creds_path, 'r') as f: @@ -78,23 +86,12 @@ def download_album( spo_creds_dir = os.path.join('./creds/spotify', fallback) spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) - # Check for Spotify client credentials in fallback account - fallback_client_id = spotify_client_id - fallback_client_secret = spotify_client_secret - fallback_search_path = Path(f'./creds/spotify/{fallback}/search.json') - if fallback_search_path.exists(): - try: - with open(fallback_search_path, 'r') as f: - fallback_search_creds = json.load(f) - fallback_client_id = fallback_search_creds.get('client_id') - fallback_client_secret = fallback_search_creds.get('client_secret') - except Exception as e: - print(f"Error loading fallback Spotify search credentials: {e}") + # We've already loaded the Spotify client credentials above based on fallback spo = SpoLogin( credentials_path=spo_creds_path, - spotify_client_id=fallback_client_id, - spotify_client_secret=fallback_client_secret, + spotify_client_id=spotify_client_id, + spotify_client_secret=spotify_client_secret, progress_callback=progress_callback ) spo.download_album( diff --git a/routes/utils/celery_config.py b/routes/utils/celery_config.py index 0eaa53d..0335942 100644 --- a/routes/utils/celery_config.py +++ b/routes/utils/celery_config.py @@ -7,7 +7,7 @@ from pathlib import Path logger = logging.getLogger(__name__) # Redis configuration - read from environment variables -REDIS_HOST = os.getenv('REDIS_HOST', 'redis') +REDIS_HOST = os.getenv('REDIS_HOST', 'localhost') REDIS_PORT = os.getenv('REDIS_PORT', '6379') REDIS_DB = os.getenv('REDIS_DB', '0') REDIS_URL = os.getenv('REDIS_URL', f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}") diff --git a/routes/utils/celery_tasks.py b/routes/utils/celery_tasks.py index 71f156a..31dcf7a 100644 --- a/routes/utils/celery_tasks.py +++ b/routes/utils/celery_tasks.py @@ -467,6 +467,13 @@ def download_track(self, **task_data): # Get the service from config service = config_params.get("service") + # DEBUG: Log the config parameters + print(f"DEBUG: celery_tasks.py config_params:") + print(f"DEBUG: service = {service}") + print(f"DEBUG: spotify = {config_params.get('spotify', '')}") + print(f"DEBUG: deezer = {config_params.get('deezer', '')}") + print(f"DEBUG: fallback_enabled = {config_params.get('fallback', False)}") + # Determine main, fallback, and quality parameters based on service and fallback setting fallback_enabled = config_params.get("fallback", False) @@ -479,6 +486,11 @@ def download_track(self, **task_data): fallback = config_params.get("spotify", "") quality = config_params.get("deezerQuality", "MP3_128") fall_quality = config_params.get("spotifyQuality", "NORMAL") + + # DEBUG: Log the values after fallback logic + print(f"DEBUG: Spotify with fallback enabled:") + print(f"DEBUG: main (Deezer account) = {main}") + print(f"DEBUG: fallback (Spotify account) = {fallback}") else: # If fallback is disabled with Spotify service: # - main is the Spotify account @@ -487,6 +499,10 @@ def download_track(self, **task_data): fallback = None quality = config_params.get("spotifyQuality", "NORMAL") fall_quality = None + + # DEBUG: Log the values + print(f"DEBUG: Spotify without fallback:") + print(f"DEBUG: main (Spotify account) = {main}") elif service == 'deezer': # For Deezer service: # - main is the Deezer account @@ -495,12 +511,20 @@ def download_track(self, **task_data): fallback = None quality = config_params.get("deezerQuality", "MP3_128") fall_quality = None + + # DEBUG: Log the values + print(f"DEBUG: Deezer service:") + print(f"DEBUG: main (Deezer account) = {main}") else: # Default to Spotify if unknown service main = config_params.get("spotify", "") fallback = None quality = config_params.get("spotifyQuality", "NORMAL") fall_quality = None + + # DEBUG: Log the values + print(f"DEBUG: Unknown service defaulting to Spotify:") + print(f"DEBUG: main (Spotify account) = {main}") # Get remaining parameters from task_data or config url = task_data.get("url", "") @@ -510,7 +534,12 @@ def download_track(self, **task_data): pad_tracks = task_data.get("pad_tracks", config_params.get("tracknum_padding", True)) # Log task parameters for debugging - logger.debug(f"Track download parameters: service={service}, quality={quality}, real_time={real_time}") + print(f"DEBUG: Final parameters for download_track_func:") + print(f"DEBUG: service = {service}") + print(f"DEBUG: main = {main}") + print(f"DEBUG: fallback = {fallback}") + print(f"DEBUG: quality = {quality}") + print(f"DEBUG: fall_quality = {fall_quality}") # Execute the download function with progress callback download_track_func( diff --git a/routes/utils/playlist.py b/routes/utils/playlist.py index 9c05a2b..cb3113d 100755 --- a/routes/utils/playlist.py +++ b/routes/utils/playlist.py @@ -25,7 +25,15 @@ def download_playlist( # Load Spotify client credentials if available spotify_client_id = None spotify_client_secret = None - search_creds_path = Path(f'./creds/spotify/{main}/search.json') + + # Smartly determine where to look for Spotify search credentials + if service == 'spotify' and fallback: + # If fallback is enabled, use the fallback account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{fallback}/search.json') + else: + # Otherwise use the main account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{main}/search.json') + if search_creds_path.exists(): try: with open(search_creds_path, 'r') as f: @@ -78,23 +86,12 @@ def download_playlist( spo_creds_dir = os.path.join('./creds/spotify', fallback) spo_creds_path = os.path.abspath(os.path.join(spo_creds_dir, 'credentials.json')) - # Check for Spotify client credentials in fallback account - fallback_client_id = spotify_client_id - fallback_client_secret = spotify_client_secret - fallback_search_path = Path(f'./creds/spotify/{fallback}/search.json') - if fallback_search_path.exists(): - try: - with open(fallback_search_path, 'r') as f: - fallback_search_creds = json.load(f) - fallback_client_id = fallback_search_creds.get('client_id') - fallback_client_secret = fallback_search_creds.get('client_secret') - except Exception as e: - print(f"Error loading fallback Spotify search credentials: {e}") + # We've already loaded the Spotify client credentials above based on fallback spo = SpoLogin( credentials_path=spo_creds_path, - spotify_client_id=fallback_client_id, - spotify_client_secret=fallback_client_secret, + spotify_client_id=spotify_client_id, + spotify_client_secret=spotify_client_secret, progress_callback=progress_callback ) spo.download_playlist( diff --git a/routes/utils/track.py b/routes/utils/track.py index bc92634..bd1d306 100755 --- a/routes/utils/track.py +++ b/routes/utils/track.py @@ -22,16 +22,30 @@ def download_track( progress_callback=None ): try: + # DEBUG: Print parameters + print(f"DEBUG: track.py received - service={service}, main={main}, fallback={fallback}") + # Load Spotify client credentials if available spotify_client_id = None spotify_client_secret = None - search_creds_path = Path(f'./creds/spotify/{main}/search.json') + + # Smartly determine where to look for Spotify search credentials + if service == 'spotify' and fallback: + # If fallback is enabled, use the fallback account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{fallback}/search.json') + print(f"DEBUG: Using Spotify search credentials from fallback: {search_creds_path}") + else: + # Otherwise use the main account for Spotify search credentials + search_creds_path = Path(f'./creds/spotify/{main}/search.json') + print(f"DEBUG: Using Spotify search credentials from main: {search_creds_path}") + if search_creds_path.exists(): try: with open(search_creds_path, 'r') as f: search_creds = json.load(f) spotify_client_id = search_creds.get('client_id') spotify_client_secret = search_creds.get('client_secret') + print(f"DEBUG: Loaded Spotify client credentials successfully") except Exception as e: print(f"Error loading Spotify search credentials: {e}") @@ -45,6 +59,19 @@ def download_track( try: deezer_creds_dir = os.path.join('./creds/deezer', main) deezer_creds_path = os.path.abspath(os.path.join(deezer_creds_dir, 'credentials.json')) + + # DEBUG: Print Deezer credential paths being used + print(f"DEBUG: Looking for Deezer credentials at:") + print(f"DEBUG: deezer_creds_dir = {deezer_creds_dir}") + print(f"DEBUG: deezer_creds_path = {deezer_creds_path}") + print(f"DEBUG: Directory exists = {os.path.exists(deezer_creds_dir)}") + print(f"DEBUG: Credentials file exists = {os.path.exists(deezer_creds_path)}") + + # List available directories to compare + print(f"DEBUG: Available Deezer credential directories:") + for dir_name in os.listdir('./creds/deezer'): + print(f"DEBUG: ./creds/deezer/{dir_name}") + with open(deezer_creds_path, 'r') as f: deezer_creds = json.load(f) dl = DeeLogin( @@ -68,27 +95,17 @@ def download_track( max_retries=max_retries ) except Exception as e: + print(f"DEBUG: Deezer download attempt failed: {e}") # 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')) - # Check for Spotify client credentials in fallback account - fallback_client_id = spotify_client_id - fallback_client_secret = spotify_client_secret - fallback_search_path = Path(f'./creds/spotify/{fallback}/search.json') - if fallback_search_path.exists(): - try: - with open(fallback_search_path, 'r') as f: - fallback_search_creds = json.load(f) - fallback_client_id = fallback_search_creds.get('client_id') - fallback_client_secret = fallback_search_creds.get('client_secret') - except Exception as e: - print(f"Error loading fallback Spotify search credentials: {e}") + # We've already loaded the Spotify client credentials above based on fallback spo = SpoLogin( credentials_path=spo_creds_path, - spotify_client_id=fallback_client_id, - spotify_client_secret=fallback_client_secret, + spotify_client_id=spotify_client_id, + spotify_client_secret=spotify_client_secret, progress_callback=progress_callback ) spo.download_track(