Semak dokumentasi
Panduan
Salin arahan untuk video, audio, sari kata, set data dan menyambung pengumpulan.
Pada halaman ini
Peraturan dan Konvensyen Perintah
python -m pip install -U --pre "yt-dlp[default,curl-cffi]"
deno --version
ffmpeg -version
python -m yt_dlp --list-impersonate-targetsResep muat turun menggunakan Deno dan --impersonate="" sebagai garis asas. Yang terakhir memerlukan curl-cffi dan membolehkan ia memilih cap jari pelayar yang tersedia. Linux/macOS perintah menggunakan sintax Bash; bagi pekerja yang dirancang, juga membuat ketergantungan ini tersedia dalam persekitaran perkhidmatan itu.
Contoh terminal ini menggunakan pemasangan Python yt-dlp. Gunakan Python persekitaran maya anda, atau tukar Python -m yt_dlp dengan perintah yt-dlp yang berasingan. Gunakan Linux terlebih dahulu, dengan alternatif macOS dan Windows dalam panduan setup. Pemasangan FFmpeg/ffprobe untuk menggabungkan dan Deno untuk YouTube cabaran penyelesaian. Menggantikan contoh URL dengan sumber anda.
| Konvensyen | Kenapa penting |
|---|---|
| URL dan template | Shell sebaliknya menafsirkan watak-watak seperti &, ruang dan parentes. |
| %(ext)s disimpan dalam nama fil | Media yang dipilih dan post-proses menentukan perpanjangan. |
| Gunakan --no-playlist untuk url jam | Video yang dipautkan daripada senarai main tidak boleh secara tidak dijangka memperluaskan pekerjaan anda. |
| Periksa konfigurasi anda yang disimpan | Contoh boleh mewarisi konfigurasi global. gunakan --ignore-config untuk ujian terisolasi. |
| Windows .bat: dua kali ganda templat peratusan tanda | Gunakan %(id) dalam fail batch, tetapi %(id) dalam fail PowerShell interaktif dan fail konfigurasi biasa. |
Kualiti video dan MP4
Baseline: terbaru malam, Deno dan FFmpeg, dengan --impersonate="". Resep menggunakan Bash; menggantikan URL sampel dengan sumber anda.
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -P downloads \
-o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
-F "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -S "res:1080" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
-f "bv*[height<=1080]+ba/b[height<=1080]" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
-f "bv[vcodec^=avc1][height<=1080]+ba[acodec^=mp4a]/b[vcodec^=avc1][acodec^=mp4a][height<=1080]" \
--merge-output-format mp4 "https://www.youtube.com/watch?v=jNQXAC9IVRw"Kumpulan data AI: MP4 + captions + metadata
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
-f "bestvideo+bestaudio/best" --merge-output-format mp4 --remux-video mp4 \
--write-info-json --write-subs --write-auto-subs --sub-langs "en" --sub-format "vtt/best" \
--sleep-subtitles 5 --concurrent-fragments 1 -P dataset -o "%(id)s/%(id)s.%(ext)s" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"Penghantaran ke luar : aria2c
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist --downloader aria2c \
--downloader "dash,m3u8:native" --downloader-args "aria2c:-x 2 -s 2 -j 1" \
--concurrent-fragments 1 -P downloads "https://www.youtube.com/watch?v=jNQXAC9IVRw"aria2 mempunyai pelaksanaan rangkaian sendiri. yt-dlp impersonasi curl-cffi tidak mengkonfigurasi cap jari aria2. Jika hanya pemuat turun luaran gagal, gunakan --downloader asli dan bandingkan sumber dan laluan proxy yang sama.
Perbezaan antara audio dan MP3
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -f ba -P audio \
-o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -f ba -x \
--audio-format mp3 --audio-quality 192K -P audio \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -f "ba[ext=m4a]" -P audio \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist -f ba -x \
--audio-format mp3 --embed-metadata --embed-thumbnail -P audio \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"Tajuk dan subtitle
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--list-subs "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --skip-download --write-subs \
--sub-langs "en.*" --sub-format "vtt/best" -P captions -o "%(id)s.%(ext)s" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --skip-download --write-subs \
--write-auto-subs --sub-langs "en.*" --sub-format "vtt/best" -P captions \
-o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --skip-download --write-subs \
--write-auto-subs --sub-langs "en" --convert-subs srt -P captions \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --write-subs --sub-langs "en" \
--embed-subs --remux-video mkv -P downloads "https://www.youtube.com/watch?v=jNQXAC9IVRw"Meminta semua bahasa caption boleh meningkatkan jumlah permintaan dan fail. Pastikan bahasa yang diminta jelas untuk kerja rutin. Simpan ID sumber dan bahasa dalam inventori set data anda supaya transcripts tidak terpisah daripada media yang mereka jelaskan.
Metadata dan laluan output
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--dump-json "https://www.youtube.com/watch?v=jNQXAC9IVRw" > video.jsonpython -m yt_dlp --js-runtimes deno --impersonate="" --skip-download --write-info-json \
-P metadata -o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --skip-download --write-thumbnail \
-P thumbnails -o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--print after_move:filepath -P downloads -o "%(id)s.%(ext)s" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--print-to-file after_move:filepath completed-paths.txt -P downloads \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"Tempoh dan bab
python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--download-sections "*00:00:05-00:00:10" -o "clips/%(id)s-%(section_start)s.%(ext)s" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --no-playlist \
--download-sections "*00:00:05-00:00:10" --force-keyframes-at-cuts \
-o "clips/%(id)s-%(section_start)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --split-chapters -o "chapter:%(id)s-%(section_number)03d.%(ext)s" \
"https://www.youtube.com/watch?v=YOUR_VIDEO_ID"Gunakan dasar output atau arkib yang berbeza untuk klip dan video penuh. entri arkib peringkat sumber tidak menyulitkan start/end kali yang dipilih, jadi satu arkib yang dikongsi boleh memadamkan klip kemudian yang anda akan cipta.
Senarai dan senarai URL
python -m yt_dlp --no-playlist --batch-file urls.txt -P collection -o "%(id)s.%(ext)s"python -m yt_dlp --flat-playlist \
--dump-json "https://www.youtube.com/playlist?list=YOUR_PLAYLIST_ID" > playlist.jsonlpython -m yt_dlp --playlist-items 1:5 -P collection -o "%(playlist_index)03d-%(id)s.%(ext)s" \
"https://www.youtube.com/playlist?list=YOUR_PLAYLIST_ID"python -m yt_dlp --dateafter 20260101 --match-filters "!is_live & duration <= 1800" \
--batch-file urls.txtpython -m yt_dlp --download-archive archive.txt --max-downloads 10 --batch-file urls.txtArkib dan pemulihan
python -m yt_dlp --download-archive archive.txt --continue --no-abort-on-error -P collection \
-o "%(id)s.%(ext)s" --batch-file urls.txtpython -m yt_dlp --sleep-requests 1 --sleep-interval 5 --max-sleep-interval 10 --retries 3 \
--fragment-retries 3 --socket-timeout 30 --batch-file urls.txtpython -m yt_dlp --js-runtimes deno --impersonate="" --limit-rate 2M \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --concurrent-fragments 1 \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"Konfigurasi dan Filenama
python -m yt_dlp --ignore-config --config-locations yt-dlp-work.conf --batch-file urls.txtpython -m yt_dlp --js-runtimes deno --impersonate="" -P downloads \
-o "%(channel_id)s/%(upload_date)s-%(title).150B [%(id)s].%(ext)s" \
"https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" -P "home:downloads" -P "temp:work" \
-o "%(id)s.%(ext)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"Untuk koleksi jangka panjang, memutuskan sama ada nama filenam harus menjadi kunci aplikasi yang boleh dibaca oleh manusia atau stabil. Nama dan tajuk saluran boleh berubah. Channel/video ID adalah kunci yang lebih baik untuk deduplikasi, dengan medan deskriptif yang disimpan dalam metadata.
Cookies dan laluan runtime
python -m yt_dlp --js-runtimes deno --impersonate="" \
--cookies-from-browser "chrome:Profile 1" \
--no-playlist "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --cookies private/youtube-cookies.txt \
--no-playlist "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes "deno:/opt/deno/bin/deno" --impersonate="" \
--no-playlist "https://www.youtube.com/watch?v=jNQXAC9IVRw"Diagnosis dan pengesahan
python -m yt_dlp --js-runtimes deno --impersonate="" --ignore-config --verbose --simulate \
--no-playlist "https://www.youtube.com/watch?v=jNQXAC9IVRw"python -m yt_dlp --js-runtimes deno --impersonate="" --ignore-config --verbose --simulate \
--no-playlist "https://www.youtube.com/watch?v=jNQXAC9IVRw" > diagnostic.log 2>&1ffprobe -v error -show_entries format=duration,size:stream=codec_type,codec_name,width,height -of json "YOUR_OUTPUT_FILE"ffmpeg -v error -i "YOUR_OUTPUT_FILE" -f null -python -m pip install -U --pre "yt-dlp[default,curl-cffi]"
python -m yt_dlp --version