YouTube Downloaderv1
Download one authorized YouTube video or audio file to a folder you choose.
6 steps · runs code · uses 2 tools
Show its 6 stepsHide steps
Steps
In the order they run.
1.Step 1: Prepare safe download
Runs codejavascriptSafely encode the URL and select the requested download branch.
No network access. · Times out after 30s
Show code · 22 linesHide code
async function run(input, ctx) { const bytes = []; for (const ch of input.url.trim()) { const cp = ch.codePointAt(0); if (cp <= 0x7f) bytes.push(cp); else if (cp <= 0x7ff) bytes.push(0xc0 | (cp >> 6), 0x80 | (cp & 0x3f)); else if (cp <= 0xffff) bytes.push(0xe0 | (cp >> 12), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f)); else bytes.push(0xf0 | (cp >> 18), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f)); } const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; let out = ''; for (let i = 0; i < bytes.length; i += 3) { const a = bytes[i]; const b = i + 1 < bytes.length ? bytes[i + 1] : 0; const c = i + 2 < bytes.length ? bytes[i + 2] : 0; const n = (a << 16) | (b << 8) | c; out += alphabet[(n >> 18) & 63] + alphabet[(n >> 12) & 63]; out += i + 1 < bytes.length ? alphabet[(n >> 6) & 63] : '='; out += i + 2 < bytes.length ? alphabet[n & 63] : '='; } return { choice: input.choice, url_b64: out, overwrite: true }; }Show data passed inHide data passed in
{ "url": "{{input.youtube_url}}", "choice": "{{input.download_type}}" }2.Step 2: Download video
Uses a toolshell_runDownload the best directly available MP4 video with audio.
Runs only when Prepare safe download reports
choice is "video".Show data passed inHide data passed in
{ "command": "URL_B64='{{nodes.prepare.output.url_b64}}'; URL=$(printf '%s' \"$URL_B64\" | base64 -d); rm -f youtube-download.mp4 youtube-download.f*; yt-dlp --js-runtimes node --no-playlist --format 'bv*[ext=mp4]+ba[ext=m4a]/bv*+ba/b' --merge-output-format mp4 --output youtube-download.mp4 \"$URL\"" }3.Step 3: Download audio
Uses a toolshell_runDownload the best directly available M4A audio stream.
Runs only when Prepare safe download reports
choice is "audio".Show data passed inHide data passed in
{ "command": "URL_B64='{{nodes.prepare.output.url_b64}}'; URL=$(printf '%s' \"$URL_B64\" | base64 -d); rm -f youtube-download.m4a; yt-dlp --js-runtimes node --no-playlist --format 'bestaudio[ext=m4a]' --output youtube-download.m4a \"$URL\"" }4.Step 4: Save video
Uses a toolfile_copyCopy the completed MP4 file to the chosen folder.
Show data passed inHide data passed in
{ "source": "youtube-download.mp4", "overwrite": "{{nodes.prepare.output.overwrite}}", "destination": "{{input.destination_folder}}/youtube-download.mp4" }5.Step 5: Save audio
Uses a toolfile_copyCopy the completed M4A file to the chosen folder.
Show data passed inHide data passed in
{ "source": "youtube-download.m4a", "overwrite": "{{nodes.prepare.output.overwrite}}", "destination": "{{input.destination_folder}}/youtube-download.m4a" }6.Step 6: Report saved file
Runs codejavascriptReturn the path and type of the file that was saved.
No network access. · Times out after 30s
Show code · 9 linesHide code
async function run(input, ctx) { const folder = input.folder.replace(/\/$/, ''); const filename = input.media_type === 'video' ? 'youtube-download.mp4' : 'youtube-download.m4a'; return { file_path: folder + '/' + filename, media_type: input.media_type, note: 'Download completed. Only save content you are authorized to download.' }; }Show data passed inHide data passed in
{ "folder": "{{input.destination_folder}}", "media_type": "{{input.download_type}}" }