Spaces:
Sleeping
Sleeping
Enhance YouTube job ID resolution to include video title and update progress messages
Browse files- app.py +11 -9
- modules/cookies.txt +6 -6
app.py
CHANGED
|
@@ -58,7 +58,7 @@ def _extract_video_id(video_input: str) -> str:
|
|
| 58 |
if prefix in path_parts:
|
| 59 |
prefix_index = path_parts.index(prefix)
|
| 60 |
if prefix_index + 1 < len(path_parts):
|
| 61 |
-
return path_parts[prefix_index + 1]
|
| 62 |
|
| 63 |
return ""
|
| 64 |
|
|
@@ -84,14 +84,14 @@ def _prepare_uploaded_audio(uploaded_audio: str) -> tuple[str, str]:
|
|
| 84 |
return str(target_path), job_id
|
| 85 |
|
| 86 |
|
| 87 |
-
def _resolve_youtube_job_id(video_input: str) -> tuple[str, str]:
|
| 88 |
video_id = _extract_video_id(video_input)
|
| 89 |
if not video_id:
|
| 90 |
-
return "", ""
|
| 91 |
|
| 92 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 93 |
-
|
| 94 |
-
return video_id, sanitize_job_id(
|
| 95 |
# ---------------------------------------------------------------------------
|
| 96 |
# AudioGallery CSS — injected inline so the component is self-contained
|
| 97 |
# ---------------------------------------------------------------------------
|
|
@@ -124,7 +124,7 @@ def _process_video_impl(video_id: str, progress=None):
|
|
| 124 |
def on_progress(message):
|
| 125 |
progress_messages.append(message)
|
| 126 |
|
| 127 |
-
video_id, job_id = _resolve_youtube_job_id(video_id)
|
| 128 |
if not video_id:
|
| 129 |
return (
|
| 130 |
"<p style='color:red;'>Please enter a YouTube video ID or URL.</p>",
|
|
@@ -132,6 +132,7 @@ def _process_video_impl(video_id: str, progress=None):
|
|
| 132 |
)
|
| 133 |
|
| 134 |
try:
|
|
|
|
| 135 |
if progress is not None:
|
| 136 |
progress(0.0, desc="Preparing request")
|
| 137 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
|
@@ -173,7 +174,7 @@ def process_video(video_id: str, progress=gr.Progress(track_tqdm=True)) -> str:
|
|
| 173 |
Returns:
|
| 174 |
HTML string containing the AudioGallery with all separated stems.
|
| 175 |
"""
|
| 176 |
-
video_id, job_id = _resolve_youtube_job_id(video_id)
|
| 177 |
if not video_id:
|
| 178 |
return "<p style='color:red;'>Please enter a YouTube video ID or URL.</p>"
|
| 179 |
|
|
@@ -208,7 +209,7 @@ def process_video_with_progress(
|
|
| 208 |
audio_path, job_id = _prepare_uploaded_audio(uploaded_audio)
|
| 209 |
status_lines.append("Using uploaded audio file.")
|
| 210 |
else:
|
| 211 |
-
video_id, job_id = _resolve_youtube_job_id(video_id)
|
| 212 |
if not video_id:
|
| 213 |
yield (
|
| 214 |
"<p style='color:red;'>Please enter a YouTube video ID or URL, or upload an audio file.</p>",
|
|
@@ -216,9 +217,10 @@ def process_video_with_progress(
|
|
| 216 |
)
|
| 217 |
return
|
| 218 |
|
|
|
|
| 219 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 220 |
progress(0.05, desc="Downloading audio")
|
| 221 |
-
yield "", "Downloading audio from YouTube..."
|
| 222 |
audio_path = download_audio(url, job_id, progress_callback=on_progress)
|
| 223 |
|
| 224 |
progress(0.4, desc="Separating tracks")
|
|
|
|
| 58 |
if prefix in path_parts:
|
| 59 |
prefix_index = path_parts.index(prefix)
|
| 60 |
if prefix_index + 1 < len(path_parts):
|
| 61 |
+
return path_parts[prefix_index + ][1]
|
| 62 |
|
| 63 |
return ""
|
| 64 |
|
|
|
|
| 84 |
return str(target_path), job_id
|
| 85 |
|
| 86 |
|
| 87 |
+
def _resolve_youtube_job_id(video_input: str) -> tuple[str, str, str]:
|
| 88 |
video_id = _extract_video_id(video_input)
|
| 89 |
if not video_id:
|
| 90 |
+
return "", "", ""
|
| 91 |
|
| 92 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 93 |
+
youtube_title = get_title(url)
|
| 94 |
+
return video_id, youtube_title, sanitize_job_id(youtube_title or video_id)
|
| 95 |
# ---------------------------------------------------------------------------
|
| 96 |
# AudioGallery CSS — injected inline so the component is self-contained
|
| 97 |
# ---------------------------------------------------------------------------
|
|
|
|
| 124 |
def on_progress(message):
|
| 125 |
progress_messages.append(message)
|
| 126 |
|
| 127 |
+
video_id, youtube_title, job_id = _resolve_youtube_job_id(video_id)
|
| 128 |
if not video_id:
|
| 129 |
return (
|
| 130 |
"<p style='color:red;'>Please enter a YouTube video ID or URL.</p>",
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
try:
|
| 135 |
+
on_progress(f"YouTube title: {youtube_title}")
|
| 136 |
if progress is not None:
|
| 137 |
progress(0.0, desc="Preparing request")
|
| 138 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
|
|
|
| 174 |
Returns:
|
| 175 |
HTML string containing the AudioGallery with all separated stems.
|
| 176 |
"""
|
| 177 |
+
video_id, _youtube_title, job_id = _resolve_youtube_job_id(video_id)
|
| 178 |
if not video_id:
|
| 179 |
return "<p style='color:red;'>Please enter a YouTube video ID or URL.</p>"
|
| 180 |
|
|
|
|
| 209 |
audio_path, job_id = _prepare_uploaded_audio(uploaded_audio)
|
| 210 |
status_lines.append("Using uploaded audio file.")
|
| 211 |
else:
|
| 212 |
+
video_id, youtube_title, job_id = _resolve_youtube_job_id(video_id)
|
| 213 |
if not video_id:
|
| 214 |
yield (
|
| 215 |
"<p style='color:red;'>Please enter a YouTube video ID or URL, or upload an audio file.</p>",
|
|
|
|
| 217 |
)
|
| 218 |
return
|
| 219 |
|
| 220 |
+
status_lines.append(f"YouTube title: {youtube_title}")
|
| 221 |
url = f"https://www.youtube.com/watch?v={video_id}"
|
| 222 |
progress(0.05, desc="Downloading audio")
|
| 223 |
+
yield "", "\n".join(status_lines + ["Downloading audio from YouTube..."])
|
| 224 |
audio_path = download_audio(url, job_id, progress_callback=on_progress)
|
| 225 |
|
| 226 |
progress(0.4, desc="Separating tracks")
|
modules/cookies.txt
CHANGED
|
@@ -7,10 +7,10 @@
|
|
| 7 |
.youtube.com TRUE / TRUE 1809672953 __Secure-1PSIDTS sidts-CjQBhkeRdzNqWsCZmJ3-gkQi5XfDWk2kp9iiQgPaUxmrZjRZ_3ej2OAxYImFfurTjFOv5VO9EAA
|
| 8 |
.youtube.com TRUE / TRUE 1809672953 __Secure-3PSIDTS sidts-CjQBhkeRdzNqWsCZmJ3-gkQi5XfDWk2kp9iiQgPaUxmrZjRZ_3ej2OAxYImFfurTjFOv5VO9EAA
|
| 9 |
.youtube.com TRUE / TRUE 1809673265 __Secure-3PSIDCC AKEyXzWBoEdxrm5iyQK7QFba8BjySeE4Hvz49k1X8zhdAxwfePNf2bUDY2yaA8Buaq0yV5a9IA
|
| 10 |
-
.youtube.com TRUE / TRUE
|
| 11 |
-
.youtube.com TRUE / TRUE
|
| 12 |
-
.youtube.com TRUE / TRUE
|
| 13 |
-
.youtube.com TRUE / TRUE
|
| 14 |
.youtube.com TRUE / TRUE 0 SOCS CAI
|
| 15 |
-
.youtube.com TRUE / TRUE
|
| 16 |
-
.youtube.com TRUE / TRUE 0 YSC
|
|
|
|
| 7 |
.youtube.com TRUE / TRUE 1809672953 __Secure-1PSIDTS sidts-CjQBhkeRdzNqWsCZmJ3-gkQi5XfDWk2kp9iiQgPaUxmrZjRZ_3ej2OAxYImFfurTjFOv5VO9EAA
|
| 8 |
.youtube.com TRUE / TRUE 1809672953 __Secure-3PSIDTS sidts-CjQBhkeRdzNqWsCZmJ3-gkQi5XfDWk2kp9iiQgPaUxmrZjRZ_3ej2OAxYImFfurTjFOv5VO9EAA
|
| 9 |
.youtube.com TRUE / TRUE 1809673265 __Secure-3PSIDCC AKEyXzWBoEdxrm5iyQK7QFba8BjySeE4Hvz49k1X8zhdAxwfePNf2bUDY2yaA8Buaq0yV5a9IA
|
| 10 |
+
.youtube.com TRUE / TRUE 1793911520 VISITOR_INFO1_LIVE 0HOxtcrbVL8
|
| 11 |
+
.youtube.com TRUE / TRUE 1793911520 VISITOR_PRIVACY_METADATA CgJVUxIEGgAgaw%3D%3D
|
| 12 |
+
.youtube.com TRUE / TRUE 1793909089 __Secure-ROLLOUT_TOKEN CObY3I_n2pG-tQEQ1bTnseyZkwMYl-LqtICtlAM%3D
|
| 13 |
+
.youtube.com TRUE / TRUE 1793909089 __Secure-YNID 18.YT=NzrPvqyRCLAUbQJ28SrvqHRms1nJpo4_90Tl4_tz8JL4qPZRhG97lTXGTc2at_2djnmFAdeL-dhvaQdpvRPK0SxSEb-XaZzTRR7Z8W7Z5OTuc7vPeetUskgcn4eay_7Y1A94vmHz21GOl0hfqjhsshQgemoFZ9-dtMbSsGTiWyH8CewdXEUpJ8DD41gTNab324Q2SGbAamINBYNkgZFHqgLILBbeiJ_m-5AZVUitF52Ddy0h2b__oWjNZ2O-89P6Ksg8CBHPKAtrjbzbykzc9RVHg1MaFIcpdOxiZlyW8xRG55bdPV73OGmt6i2t6NXHL4zUxiZ4i3zZPHyxvPhq-Q
|
| 14 |
.youtube.com TRUE / TRUE 0 SOCS CAI
|
| 15 |
+
.youtube.com TRUE / TRUE 1778361319 GPS 1
|
| 16 |
+
.youtube.com TRUE / TRUE 0 YSC TN6JJIg8dG4
|