youtube-dl下载太慢了,我选yt-dlp - 程序设计实验室
source link: https://www.cnblogs.com/deali/p/17066534.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最近过年嘛,过年前照例来下载一些贺岁歌曲,现在国内没啥人做贺岁专辑,这方面还得看马来西亚华人,他们每年都有出专辑,质量很不错!
国内平台自然是没有(或者不全的),需要在YouTube下载~
之前我都是用Chrome插件下载完再使用脚本合并视频,有点繁琐,今年试试自动下载的黑科技~
作为对比的这俩工具,都用 pip 安装即可
pip install youtube-dl
pip install yt-dlp
youtube-dl
PS:youtube-dl 之前曾经被Github封禁了,后面应该是迫于开源界的压力,又恢复了这个仓库
首先这是项目地址: https://github.com/ytdl-org/youtube-dl
具体咋用,文档写得很详细
参数很复杂
最主要的问题是下载速度太慢了(一秒50、60k) (应该是被YouTube之类的网站识别出来,限流了)
下载合集中的多个视频
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"
下面这俩组合起来表示下载合集里第1-9个视频
--playlist-start 1
--playlist-end 9
-f
后面跟着的一大串,表示从1080p开始下载,不行的话就逐步降级到480p
设置代理啥的就不说了
yt-dlp
使用体验非常不错,推荐!
这是一个后面新出的工具,参数简化了很多,而且支持使用外部下载器(例如 Aria2)
先看看基本用到的命令长啥样~
下载单个视频
yt-dlp -f 137+140 --proxy http://127.0.0.1:10809 --merge-output-format mp4 https://www.youtube.com/watch?v=xxx
下载合集中的多个视频
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"
选择格式使用的是下面这样的参数
-f 137+140
初看可能一头雾水,但其实这是YouTube的画质代码
在YouTube上面,1080p及以上分辨率的视频,画面和声音是分开的,画面一般是mp4或者webm这种格式,声音是m4a格式,所以要下载高清视频,需要分别下载画面和声音,然后自行合并。
PS:在之前我确实是分开下载然后写个脚本使用ffmpeg来批量合并的,不过用这个工具就不用这么复杂了,它可以自动调用ffmpeg来合并视频(不过要确保系统中已经安装了ffmpeg哈)。
上面这个 137 和 140 就是画面和声音的代码。
那这么知道各种画质和音质的代码是啥呢?使用 -F
参数就行。
yt-dlp -F --proxy http://127.0.0.1:10809 "https://www.youtube.com/watch?v=xxx"
用了这个参数,就可以把指定视频的各种画质代码都显示出来,按需选择组合就行
[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
从这结果就可以看出,上面的 137 是 1080p 的 mp4视频;140 是 129k 的音频。
至于外部下载器,我没搞,默认下载速度就很快了,一秒几m,够用就不折腾了。
__EOF__
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK