tecuts commited on
Commit
1b5b18a
·
verified ·
1 Parent(s): 70f45b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -7,7 +7,6 @@ from datetime import datetime, timedelta
7
  import time
8
  import asyncio
9
  import cloudscraper
10
- from fastapi import FastAPI, BackgroundTasks, HTTPException
11
 
12
  app = Flask(__name__)
13
  ytmusic = YTMusic()
@@ -88,14 +87,15 @@ async def get_track_download_url(track_id: str) -> str:
88
  logger.info(f"Response status: {response.status_code}")
89
  logger.info(f"Response content: {response.content}")
90
 
91
- if response.status_code == 200:
92
- download_url = response.json().get("url")
93
- if download_url:
94
- api_rotator.update_last_successful(apis.index(api_url))
95
- logger.info(f"Successfully obtained download URL from {api_url}")
96
- return download_url
97
- except requests.exceptions.RequestException as e:
98
- logger.warning(f"Failed to get download URL from {api_url}: {str(e)}")
 
99
  continue
100
 
101
  logger.error(f"No download URL found")
 
7
  import time
8
  import asyncio
9
  import cloudscraper
 
10
 
11
  app = Flask(__name__)
12
  ytmusic = YTMusic()
 
87
  logger.info(f"Response status: {response.status_code}")
88
  logger.info(f"Response content: {response.content}")
89
 
90
+ if response.headers.get('content-type', '').startswith('application/json'):
91
+ json_response = response.json()
92
+ if "video.unavailable" in json_response.get("error", {}).get("code", ""):
93
+ break
94
+
95
+ api_rotator.update_last_successful(apis.index(api_url))
96
+ return json_response.get("url")
97
+ except Exception as e:
98
+ logger.error(f"Failed with {api_url}: {str(e)}")
99
  continue
100
 
101
  logger.error(f"No download URL found")