youtube-dl is too slow, I chose yt-dlp
Preface It's Chinese New Year recently, so as usual before the New Year I download some New Year songs. Nowadays hardly anyone in China makes New Year albums; for that we have to look to Malaysian Chinese, who release albums every year, and the quality is quite good! Naturally they're not on domestic platforms (or incomplete), so we need to download from YouTube~ Previously I used a Chrome extension to download then used a script to merge the videos, which was a bit tedious. This year I'll try the black magic of automatic downloading~ The two tools being compared can both be installed with pip pip install youtube-dl pip install
目录4 个章节
Preface
It's Chinese New Year recently, so as usual before the New Year I download some New Year songs. Nowadays hardly anyone in China makes New Year albums; for that we have to look to Malaysian Chinese, who release albums every year, and the quality is quite good!
Naturally they're not on domestic platforms (or incomplete), so we need to download from YouTube~
Previously I used a Chrome extension to download then used a script to merge the videos, which was a bit tedious. This year I'll try the black magic of automatic downloading~
The two tools being compared can both be installed with pip
pip install youtube-dl
pip install yt-dlp
youtube-dl
PS: youtube-dl was previously banned by GitHub; later, presumably under pressure from the open-source community, the repository was restored
First, here's the project URL: https://github.com/ytdl-org/youtube-dl
How to use it specifically is documented in great detail
The parameters are quite complex
The main problem is that the download speed is too slow (50–60k per second) (probably identified by sites like YouTube and rate-limited)
Downloading multiple videos from a playlist
youtube-dl --proxy http://127.0.0.1:10809 -f "bestvideo[ext=mp4,height<=1080]+bestaudio[ext=m4a]/bestvideo[ext=mp4,height<=720]+bestaudio[ext=m4a]/bestvideo[ext=mp4,height<=480]+bestaudio[ext=m4a]/best[ext=mp4,height<=480]/best" -o "%(title)s.%(ext)s" --embed-thumbnail --playlist-start 1 --playlist-end 9 "https://www.youtube.com/watch?v=xxx&list=xxx"
Parameter explanation
Combining the following two means downloading videos 1–9 from the playlist
--playlist-start 1
--playlist-end 9
The long string after -f means starting the download from 1080p, and if that's not available, gradually falling back to 480p
I won't go into setting up a proxy and such
yt-dlp
The experience is excellent, highly recommended!
This is a newer tool that came out later. The parameters are much simpler, and it supports using an external downloader (e.g. Aria2)
Let's first look at what the basic commands look like~
Download a single video
yt-dlp -f 137+140 --proxy http://127.0.0.1:10809 --merge-output-format mp4 https://www.youtube.com/watch?v=xxx
Download multiple videos from a playlist
yt-dlp -I 1:9 --proxy http://127.0.0.1:10809 --merge-output-format mp4 "https://www.youtube.com/watch?v=xxx&list=xxx"
Format selection uses a parameter like this
-f 137+140
At first glance it might be confusing, but these are actually YouTube quality codes
On YouTube, for videos at 1080p and above, the video and audio are separate. The video is generally in a format like mp4 or webm, and the audio is m4a, so to download HD video you need to download the video and audio separately and then merge them yourself.
PS: Previously I did indeed download them separately and then wrote a script to batch-merge them with ffmpeg, but with this tool you don't need to go through all that—it can automatically call ffmpeg to merge the video (though you need to make sure ffmpeg is already installed on your system).
The 137 and 140 above are the codes for video and audio.
So how do you know what the various video and audio quality codes are? Just use the -F parameter.
yt-dlp -F --proxy http://127.0.0.1:10809 "https://www.youtube.com/watch?v=xxx"
With this parameter, you can display all the quality codes for the specified video, then pick and combine them as needed
[youtube] Extracting URL: https://www.youtube.com/watch?v=kjuB12RFtDE
[youtube] kjuB12RFtDE: Downloading webpage
[youtube] kjuB12RFtDE: Downloading android player API JSON
[info] Available formats for kjuB12RFtDE:
ID EXT RESOLUTION FPS CH │ FILESIZE TBR PROTO │ VCODEC VBR ACODEC ABR ASR MORE INFO
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
sb2 mhtml 48x27 0 │ mhtml │ images storyboard
sb1 mhtml 80x45 1 │ mhtml │ images storyboard
sb0 mhtml 160x90 1 │ mhtml │ images storyboard
140 m4a audio only 2 │ 4.42MiB 129k https │ audio only mp4a.40.2 129k 44k medium, m4a_dash
251 webm audio only 2 │ 4.66MiB 137k https │ audio only opus 137k 48k medium, webm_dash
22 mp4 1280x720 25 2 │ ~ 44.82MiB 1284k https │ avc1.64001F 1284k mp4a.40.2 0k 44k 720p
136 mp4 1280x720 25 │ 39.41MiB 1155k https │ avc1.4d401f 1155k video only 720p, mp4_dash
247 webm 1280x720 25 │ 39.53MiB 1158k https │ vp9 1158k video only 720p, webm_dash
137 mp4 1920x1080 25 │ 117.11MiB 3431k https │ avc1.640028 3431k video only 1080p, mp4_dash
248 webm 1920x1080 25 │ 75.15MiB 2202k https │ vp9 2202k video only 1080p, webm_dash
From this result you can see that 137 above is 1080p mp4 video; 140 is 129k audio.
As for an external downloader, I didn't bother. The default download speed is already fast, several MB per second, which is enough so I didn't mess with it.
References
_EOF_
youtube-dl is too slow, I chose yt-dlp
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
喆大师写给前端的一些建议
书籍推荐 《 jvascript高级程序设计(第三版) 》 偏字典书籍,江湖人称望远镜,红宝石书,红皮书,更多叫法等你去发现 《 javascript权威指南(第五版)》 就是字典,江湖人称 犀牛书,特点:厚,全 《 javascript语言精粹 》 一位在 js 界很有权威的人写的书,作者是json的发明者 江湖人称 蝴蝶书,特点:薄 完全就是在讲 js 语法,不涉及前端,顺便屌了一些开发人员
2021-12-18 · 杂七杂八 · 约 1 分钟
摆脱数据线和网盘!LocalSend让文件传输更简单
LocalSend是一款无需互联网、支持局域网点对点加密传输的文件分享工具,操作简便,传输速度快,支持全平台。它解决了传统传输方式中的痛点,如依赖外网、文件压缩、隐私泄露等问题,为用户带来简单、快速、安全、高效的文件传输体验。
2025-04-16 · 杂七杂八 · 约 1 分钟
解决Chrome浏览器强制http重定向到https的问题
在chrome地址栏中输入 chrome://net-internals/ 选择 Domain Security Policy 在 Delete domain security policies 标签里输入要删除的域名
2021-12-18 · 杂七杂八 · 约 1 分钟
Nokia-5230的远古截图,怀念一下S60v5
Nokia 5230的截图,S60v5的怀旧盛宴?呵,像素低得像石器时代。怀念那些界面?现在看真是‘经典’的反义词。
2023-01-22 · 杂七杂八 · 约 1 分钟
讨论
共 0 条加载评论中…