Spaces:
Sleeping
Sleeping
Improve yt-dlp extraction, cookies, and user guidance
Browse filesUpdated README and Gradio UI with detailed yt-dlp extractor and secure cookie usage instructions. Enhanced yt_audio_get_tracks.py for better cookie handling and player_client preference. Updated requirements.txt to use yt-dlp[default,curl-cffi]. Refreshed cookies.txt for improved authenticated extraction.
- README.md +20 -1
- app.py +10 -1
- modules/cookies.txt +5 -4
- modules/yt_audio_get_tracks.py +12 -1
- requirements.txt +1 -2
README.md
CHANGED
|
@@ -32,7 +32,7 @@ and view the results in a Gradio AudioGallery UI with MCP support.
|
|
| 32 |
|
| 33 |
## Usage
|
| 34 |
|
| 35 |
-
Run the app locally:
|
| 36 |
|
| 37 |
```bash
|
| 38 |
pip install -r requirements.txt
|
|
@@ -58,3 +58,22 @@ Separated files are written under `separated/htdemucs_6s/{job_id}/`.
|
|
| 58 |
For YouTube sources, `job_id` is the extracted video ID. For uploaded audio,
|
| 59 |
`job_id` is a sanitized version of the uploaded filename stem.
|
| 60 |
Each stem card in the gallery can be played in place or downloaded directly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Usage
|
| 34 |
|
| 35 |
+
Run the app locally (not admin):
|
| 36 |
|
| 37 |
```bash
|
| 38 |
pip install -r requirements.txt
|
|
|
|
| 58 |
For YouTube sources, `job_id` is the extracted video ID. For uploaded audio,
|
| 59 |
`job_id` is a sanitized version of the uploaded filename stem.
|
| 60 |
Each stem card in the gallery can be played in place or downloaded directly.
|
| 61 |
+
|
| 62 |
+
## Extractors & Cookies
|
| 63 |
+
|
| 64 |
+
For details about yt-dlp extractor behavior, see the official documentation:
|
| 65 |
+
|
| 66 |
+
- https://github.com/yt-dlp/yt-dlp-wiki/blob/master/Extractors.md
|
| 67 |
+
|
| 68 |
+
If you need authenticated extraction (for age-restricted or otherwise protected
|
| 69 |
+
content), one way to provide cookies safely is via a private/incognito browser
|
| 70 |
+
session:
|
| 71 |
+
|
| 72 |
+
1. Open a new private browsing/incognito window and log into YouTube.
|
| 73 |
+
2. In the same window and same tab from step 1, navigate to
|
| 74 |
+
https://www.youtube.com/robots.txt (this should be the only
|
| 75 |
+
private/incognito browsing tab open).
|
| 76 |
+
3. Export youtube.com cookies from the browser, then close the private/
|
| 77 |
+
incognito window so that the session is never opened in the browser again.
|
| 78 |
+
|
| 79 |
+
Upload the exported cookies file in the app UI when prompted.
|
app.py
CHANGED
|
@@ -248,6 +248,7 @@ with gr.Blocks(title="SeparateTracks") as demo:
|
|
| 248 |
"using [Demucs htdemucs\\_6s](https://github.com/adefossez/demucs)."
|
| 249 |
)
|
| 250 |
|
|
|
|
| 251 |
with gr.Row():
|
| 252 |
video_id_input = gr.Textbox(
|
| 253 |
label="YouTube Video ID or URL",
|
|
@@ -268,7 +269,15 @@ with gr.Blocks(title="SeparateTracks") as demo:
|
|
| 268 |
3. Click extension → Export cookies
|
| 269 |
4. Upload the file here
|
| 270 |
""")
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
upload_input = gr.File(
|
| 273 |
label="Audio File Override (.wav or .mp3)",
|
| 274 |
file_types=[".wav", ".mp3"],
|
|
|
|
| 248 |
"using [Demucs htdemucs\\_6s](https://github.com/adefossez/demucs)."
|
| 249 |
)
|
| 250 |
|
| 251 |
+
|
| 252 |
with gr.Row():
|
| 253 |
video_id_input = gr.Textbox(
|
| 254 |
label="YouTube Video ID or URL",
|
|
|
|
| 269 |
3. Click extension → Export cookies
|
| 270 |
4. Upload the file here
|
| 271 |
""")
|
| 272 |
+
gr.Markdown(
|
| 273 |
+
"\n\nFor details about yt-dlp's extractor behavior, see: https://github.com/yt-dlp/yt-dlp-wiki/blob/master/Extractors.md\n\n"
|
| 274 |
+
"One way to provide cookies safely is through a private browsing/incognito window:\n\n"
|
| 275 |
+
"1. Open a new private browsing/incognito window and log into YouTube.\n"
|
| 276 |
+
"2. chrome://extensions and specify Allow in Incognito.\n"
|
| 277 |
+
"2. In the same window and same tab from step 1, navigate to https://www.youtube.com/robots.txt (this should be the only private/incognito browsing tab open).\n"
|
| 278 |
+
"3. Export youtube.com cookies from the browser, then close the private browsing/incognito window so that the session is never opened in the browser again.\n"
|
| 279 |
+
)
|
| 280 |
+
# https://github.com/yt-dlp/yt-dlp-wiki/
|
| 281 |
upload_input = gr.File(
|
| 282 |
label="Audio File Override (.wav or .mp3)",
|
| 283 |
file_types=[".wav", ".mp3"],
|
modules/cookies.txt
CHANGED
|
@@ -7,9 +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 1793681123 __Secure-ROLLOUT_TOKEN CObY3I_n2pG-tQEQ1bTnseyZkwMYx9-alq-mlAM%3D
|
| 13 |
.youtube.com TRUE / TRUE 1793681123 __Secure-YNID 18.YT=Tx0A40MPkqhXx1ssHRZzuknGzSYMu4HquWBxKZVhu_0va9vVL6-pj-hgIxnNj494GkolBTXqTIRUTUC6fOJCobVAekeq8te87cIsbGIO2g_jPtJnm9zE0kpjWOKceLvXzON4m1GZqXSjj5c-IjmVR2V8_43Iqnn5sEdQDd9cDor11A7gsHRNqJVIsOMuKB2n1Np9oHkp3xMIZWg38MUB13NSur0Rr3SgGIvHZBEZ1z_MTrqCYndzX5CPDbSdhT1QfUR6lC85Y1o29OlpOE3hsSUq8xROpXOX016gCc8PsSbpu54DQOw2FHydbuW4FcWEtODp1vJ3ob5QbdAN6oYeeQ
|
| 14 |
-
.youtube.com TRUE / TRUE
|
| 15 |
-
.youtube.com TRUE / TRUE
|
|
|
|
|
|
| 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 1793737731 VISITOR_INFO1_LIVE 0HOxtcrbVL8
|
| 11 |
+
.youtube.com TRUE / TRUE 1793737731 VISITOR_PRIVACY_METADATA CgJVUxIEGgAgaw%3D%3D
|
| 12 |
.youtube.com TRUE / TRUE 1793681123 __Secure-ROLLOUT_TOKEN CObY3I_n2pG-tQEQ1bTnseyZkwMYx9-alq-mlAM%3D
|
| 13 |
.youtube.com TRUE / TRUE 1793681123 __Secure-YNID 18.YT=Tx0A40MPkqhXx1ssHRZzuknGzSYMu4HquWBxKZVhu_0va9vVL6-pj-hgIxnNj494GkolBTXqTIRUTUC6fOJCobVAekeq8te87cIsbGIO2g_jPtJnm9zE0kpjWOKceLvXzON4m1GZqXSjj5c-IjmVR2V8_43Iqnn5sEdQDd9cDor11A7gsHRNqJVIsOMuKB2n1Np9oHkp3xMIZWg38MUB13NSur0Rr3SgGIvHZBEZ1z_MTrqCYndzX5CPDbSdhT1QfUR6lC85Y1o29OlpOE3hsSUq8xROpXOX016gCc8PsSbpu54DQOw2FHydbuW4FcWEtODp1vJ3ob5QbdAN6oYeeQ
|
| 14 |
+
.youtube.com TRUE / TRUE 0 SOCS CAI
|
| 15 |
+
.youtube.com TRUE / TRUE 1778185936 GPS 1
|
| 16 |
+
.youtube.com TRUE / TRUE 0 YSC sG4KsUxH1Ew
|
modules/yt_audio_get_tracks.py
CHANGED
|
@@ -30,12 +30,13 @@ def download_audio(url, video_id, progress_callback=None):
|
|
| 30 |
'quiet': False,
|
| 31 |
'no_warnings': False,
|
| 32 |
'nocheckcertificate': True,
|
| 33 |
-
'extractor_args': {'youtube': {'player_client':
|
| 34 |
'http_headers': {'Referer': 'https://www.youtube.com/'},
|
| 35 |
'socket_timeout': 60,
|
| 36 |
'retries': 10,
|
| 37 |
'compat_opts': compat_opts,
|
| 38 |
}
|
|
|
|
| 39 |
if is_hf:
|
| 40 |
ydl_opts['impersonate'] = 'chrome'
|
| 41 |
if is_hf or os.path.exists(cookie_path):
|
|
@@ -44,6 +45,16 @@ def download_audio(url, video_id, progress_callback=None):
|
|
| 44 |
else:
|
| 45 |
ydl_opts['cookiesfrombrowser'] = ('chrome', None, None, None)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 48 |
ydl.download([url])
|
| 49 |
_emit_progress(progress_callback, 'Converting downloaded audio to WAV...')
|
|
|
|
| 30 |
'quiet': False,
|
| 31 |
'no_warnings': False,
|
| 32 |
'nocheckcertificate': True,
|
| 33 |
+
'extractor_args': {'youtube': {'player_client':['web', 'android', 'ios']}},
|
| 34 |
'http_headers': {'Referer': 'https://www.youtube.com/'},
|
| 35 |
'socket_timeout': 60,
|
| 36 |
'retries': 10,
|
| 37 |
'compat_opts': compat_opts,
|
| 38 |
}
|
| 39 |
+
|
| 40 |
if is_hf:
|
| 41 |
ydl_opts['impersonate'] = 'chrome'
|
| 42 |
if is_hf or os.path.exists(cookie_path):
|
|
|
|
| 45 |
else:
|
| 46 |
ydl_opts['cookiesfrombrowser'] = ('chrome', None, None, None)
|
| 47 |
|
| 48 |
+
# with yt_dlp.YoutubeDL({**ydl_opts, 'quiet': True}) as ydl:
|
| 49 |
+
# info = ydl.extract_info(url, download=False)
|
| 50 |
+
# print(ydl.list_formats(info))
|
| 51 |
+
# audio = [f for f in info.get('formats', [])
|
| 52 |
+
# if f.get('ext') in ('webm','m4a','mp4','opus') and f.get('acodec') != 'none']
|
| 53 |
+
# if not audio:
|
| 54 |
+
# _emit_progress(progress_callback, "No webm/mp4 audio available")
|
| 55 |
+
# return None
|
| 56 |
+
# _emit_progress(progress_callback, f"Found {len(audio)} audio formats")
|
| 57 |
+
|
| 58 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 59 |
ydl.download([url])
|
| 60 |
_emit_progress(progress_callback, 'Converting downloaded audio to WAV...')
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# core audio pipeline
|
| 2 |
-
yt-dlp>=2026.3.17
|
| 3 |
demucs
|
| 4 |
pydub
|
| 5 |
youtube-transcript-api
|
|
@@ -13,4 +13,3 @@ python-dotenv
|
|
| 13 |
numpy
|
| 14 |
Pillow
|
| 15 |
requests
|
| 16 |
-
yt-dlp[curl-cffi]
|
|
|
|
| 1 |
# core audio pipeline
|
| 2 |
+
yt-dlp[default,curl-cffi]>=2026.3.17
|
| 3 |
demucs
|
| 4 |
pydub
|
| 5 |
youtube-transcript-api
|
|
|
|
| 13 |
numpy
|
| 14 |
Pillow
|
| 15 |
requests
|
|
|