Spaces:
Paused
Paused
WIP
Browse files
app.py
CHANGED
|
@@ -84,16 +84,9 @@ def get_youtube_audio_url(url):
|
|
| 84 |
"inputs": {
|
| 85 |
"url": url,
|
| 86 |
"download_type": "audio",
|
| 87 |
-
"
|
| 88 |
-
"include_audio": True,
|
| 89 |
"start_time": 0,
|
| 90 |
-
"end_time": -1
|
| 91 |
-
"include_metadata": False,
|
| 92 |
-
"metadata_fields": ["title", "thumbnail", "description", "tags", "duration"],
|
| 93 |
-
"include_subtitles": False,
|
| 94 |
-
"subtitle_languages": ["en"],
|
| 95 |
-
"video_format": "mp4",
|
| 96 |
-
"audio_format": "mp3"
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
|
@@ -103,6 +96,7 @@ def get_youtube_audio_url(url):
|
|
| 103 |
|
| 104 |
for attempt in range(max_retries):
|
| 105 |
try:
|
|
|
|
| 106 |
response = requests.post(
|
| 107 |
f"{SIEVE_API_URL}/push",
|
| 108 |
headers={"X-API-Key": SIEVE_API_KEY, "Content-Type": "application/json"},
|
|
@@ -111,10 +105,12 @@ def get_youtube_audio_url(url):
|
|
| 111 |
)
|
| 112 |
response.raise_for_status()
|
| 113 |
response_data = response.json()
|
|
|
|
| 114 |
|
| 115 |
job_id = response_data.get("id")
|
| 116 |
if not job_id:
|
| 117 |
if attempt < max_retries - 1:
|
|
|
|
| 118 |
time.sleep(retry_delay)
|
| 119 |
continue
|
| 120 |
raise gr.Error("Failed to get job ID from Sieve API")
|
|
@@ -122,6 +118,7 @@ def get_youtube_audio_url(url):
|
|
| 122 |
|
| 123 |
except requests.exceptions.RequestException as e:
|
| 124 |
if attempt < max_retries - 1:
|
|
|
|
| 125 |
time.sleep(retry_delay)
|
| 126 |
continue
|
| 127 |
raise
|
|
@@ -134,6 +131,7 @@ def get_youtube_audio_url(url):
|
|
| 134 |
poll_count += 1
|
| 135 |
|
| 136 |
try:
|
|
|
|
| 137 |
job_response = requests.get(
|
| 138 |
f"{SIEVE_API_URL}/jobs/{job_id}",
|
| 139 |
headers={"X-API-Key": SIEVE_API_KEY},
|
|
@@ -141,6 +139,7 @@ def get_youtube_audio_url(url):
|
|
| 141 |
)
|
| 142 |
job_response.raise_for_status()
|
| 143 |
job_data = job_response.json()
|
|
|
|
| 144 |
|
| 145 |
status = job_data.get("status")
|
| 146 |
|
|
@@ -164,10 +163,12 @@ def get_youtube_audio_url(url):
|
|
| 164 |
if not audio_url.startswith(('http://', 'https://')):
|
| 165 |
raise gr.Error(f"Invalid audio URL scheme: {audio_url}")
|
| 166 |
|
|
|
|
| 167 |
return audio_url
|
| 168 |
|
| 169 |
elif status == "failed":
|
| 170 |
error_msg = job_data.get("error", "Unknown error")
|
|
|
|
| 171 |
raise gr.Error(f"Job failed: {error_msg}")
|
| 172 |
|
| 173 |
if poll_count >= max_polls:
|
|
@@ -178,9 +179,11 @@ def get_youtube_audio_url(url):
|
|
| 178 |
except requests.exceptions.RequestException as e:
|
| 179 |
if poll_count >= max_polls:
|
| 180 |
raise gr.Error("Failed to check job status. Please try again.")
|
|
|
|
| 181 |
time.sleep(2)
|
| 182 |
|
| 183 |
except Exception as e:
|
|
|
|
| 184 |
raise gr.Error(f"Failed to get YouTube audio URL: {str(e)}")
|
| 185 |
|
| 186 |
def check_api_health():
|
|
|
|
| 84 |
"inputs": {
|
| 85 |
"url": url,
|
| 86 |
"download_type": "audio",
|
| 87 |
+
"audio_format": "mp3",
|
|
|
|
| 88 |
"start_time": 0,
|
| 89 |
+
"end_time": -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
|
|
|
| 96 |
|
| 97 |
for attempt in range(max_retries):
|
| 98 |
try:
|
| 99 |
+
logger.info(f"Sending request to Sieve API (attempt {attempt + 1}/{max_retries})")
|
| 100 |
response = requests.post(
|
| 101 |
f"{SIEVE_API_URL}/push",
|
| 102 |
headers={"X-API-Key": SIEVE_API_KEY, "Content-Type": "application/json"},
|
|
|
|
| 105 |
)
|
| 106 |
response.raise_for_status()
|
| 107 |
response_data = response.json()
|
| 108 |
+
logger.info(f"Sieve API response: {response_data}")
|
| 109 |
|
| 110 |
job_id = response_data.get("id")
|
| 111 |
if not job_id:
|
| 112 |
if attempt < max_retries - 1:
|
| 113 |
+
logger.warning(f"No job ID received, retrying in {retry_delay} seconds")
|
| 114 |
time.sleep(retry_delay)
|
| 115 |
continue
|
| 116 |
raise gr.Error("Failed to get job ID from Sieve API")
|
|
|
|
| 118 |
|
| 119 |
except requests.exceptions.RequestException as e:
|
| 120 |
if attempt < max_retries - 1:
|
| 121 |
+
logger.warning(f"Request failed: {str(e)}, retrying in {retry_delay} seconds")
|
| 122 |
time.sleep(retry_delay)
|
| 123 |
continue
|
| 124 |
raise
|
|
|
|
| 131 |
poll_count += 1
|
| 132 |
|
| 133 |
try:
|
| 134 |
+
logger.info(f"Polling job status (attempt {poll_count}/{max_polls})")
|
| 135 |
job_response = requests.get(
|
| 136 |
f"{SIEVE_API_URL}/jobs/{job_id}",
|
| 137 |
headers={"X-API-Key": SIEVE_API_KEY},
|
|
|
|
| 139 |
)
|
| 140 |
job_response.raise_for_status()
|
| 141 |
job_data = job_response.json()
|
| 142 |
+
logger.info(f"Job response: {job_data}")
|
| 143 |
|
| 144 |
status = job_data.get("status")
|
| 145 |
|
|
|
|
| 163 |
if not audio_url.startswith(('http://', 'https://')):
|
| 164 |
raise gr.Error(f"Invalid audio URL scheme: {audio_url}")
|
| 165 |
|
| 166 |
+
logger.info(f"Successfully got audio URL: {audio_url}")
|
| 167 |
return audio_url
|
| 168 |
|
| 169 |
elif status == "failed":
|
| 170 |
error_msg = job_data.get("error", "Unknown error")
|
| 171 |
+
logger.error(f"Job failed: {error_msg}")
|
| 172 |
raise gr.Error(f"Job failed: {error_msg}")
|
| 173 |
|
| 174 |
if poll_count >= max_polls:
|
|
|
|
| 179 |
except requests.exceptions.RequestException as e:
|
| 180 |
if poll_count >= max_polls:
|
| 181 |
raise gr.Error("Failed to check job status. Please try again.")
|
| 182 |
+
logger.warning(f"Request failed: {str(e)}, retrying in 2 seconds")
|
| 183 |
time.sleep(2)
|
| 184 |
|
| 185 |
except Exception as e:
|
| 186 |
+
logger.exception(f"Error during YouTube URL fetch: {str(e)}")
|
| 187 |
raise gr.Error(f"Failed to get YouTube audio URL: {str(e)}")
|
| 188 |
|
| 189 |
def check_api_health():
|