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 许可协议。转载请注明出处!
相关文章
鸡哥无界14x的固件折腾
三线品牌的BIOS果然是草台班子,充电限制这种基础功能都能写错,还得靠刷Slimbook的固件来救。开源控制中心倒是不错,不过鸡哥这省钱省得,用户全成测试工程师了。
2026-08-13 · 杂七杂八 · 约 1 分钟
Chrome浏览器单独删除已保存的地址
步骤 在地址栏中输入地址,按方向键选择需要删除的地址, Windows/Linux Shift + Delete 删除。
2021-12-18 · 杂七杂八 · 约 1 分钟
我的新博客上线了,附上Hexo博客折腾记录
鉴于简书和知乎经常以各种理由删除我的博客,之前我的WordPress博客又已经坏掉了,所以我一直想搞一个新的博客,这不看上了hexo静态博客了,直接托管在github上方便又免费。 配置啥的官方文档都很详细了,不再赘述。 博客地址:http://blog.deali.cn/ 各种配置,我还花了一天时间来写脚本把我的旧的博客导入,图片下载,做了替换等等工作,期间也出了很多问题,感觉很烦,很浪费时间,
2021-12-18 · 杂七杂八 · 约 1 分钟
Nokia-5230的远古截图,怀念一下S60v5
Nokia 5230的截图,S60v5的怀旧盛宴?呵,像素低得像石器时代。怀念那些界面?现在看真是‘经典’的反义词。
2023-01-22 · 杂七杂八 · 约 1 分钟
讨论
共 0 条加载评论中…