fix(musicseerr): implement proxy fallback for Spotify playlist scraping
Build and Push Docker Images / deploy (push) Blocked by required conditions Details
Build and Push Docker Images / build (musicseerr) (push) Failing after 3m9s Details
Build and Push Docker Images / build (nextgen) (push) Failing after 10s Details
Build and Push Docker Images / build (api) (push) Failing after 5m34s Details
Build and Push Docker Images / build (web) (push) Successful in 7m26s Details
Build and Push Docker Images / build (worker) (push) Has been cancelled Details

This commit is contained in:
fchinembiri 2026-07-10 10:24:07 +02:00
parent d91a4abee4
commit 4164bde79b
1 changed files with 26 additions and 22 deletions

View File

@ -275,14 +275,16 @@ def scrape_spotify_playlist(url: str, proxy_url: str) -> list:
playlist_id = match.group(1) playlist_id = match.group(1)
embed_url = f"https://open.spotify.com/embed/playlist/{playlist_id}" embed_url = f"https://open.spotify.com/embed/playlist/{playlist_id}"
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
headers = { headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
} }
# Try with proxy first, then without proxy
logger.info(f"Scraping Spotify playlist via embed URL: {embed_url}") for use_proxy in [True, False]:
current_proxies = {"http": proxy_url, "https": proxy_url} if (use_proxy and proxy_url) else None
proxy_desc = f"via proxy {proxy_url}" if current_proxies else "directly"
logger.info(f"Scraping Spotify playlist via embed URL: {embed_url} ({proxy_desc})")
try: try:
response = requests.get(embed_url, headers=headers, proxies=proxies, timeout=15) response = requests.get(embed_url, headers=headers, proxies=current_proxies, timeout=15)
if response.status_code == 200: if response.status_code == 200:
next_data_match = re.search(r'<script id="__NEXT_DATA__" type="application/json">(.*?)</script>', response.text) next_data_match = re.search(r'<script id="__NEXT_DATA__" type="application/json">(.*?)</script>', response.text)
if next_data_match: if next_data_match:
@ -298,8 +300,10 @@ def scrape_spotify_playlist(url: str, proxy_url: str) -> list:
elif title: elif title:
track_queries.append(title) track_queries.append(title)
return track_queries return track_queries
logger.warning(f"Failed to scrape Spotify playlist {proxy_desc}: HTTP {response.status_code}")
except Exception as e: except Exception as e:
logger.warning(f"Failed to scrape Spotify playlist: {e}") logger.warning(f"Failed to scrape Spotify playlist {proxy_desc}: {e}")
return [] return []