80k/s
被限速问题
事因
最近youtube-dl一直会被限速在80k/s,开始没有在意,基本上重启命令后,速度就会恢复,但是下载一堆链接时,还是挺烦的
直到今天,发现重启几次,都没有用,连续尝试几个链接无果
搜了一下issues,发现很多人都遇到这个问题,但是相同的链接,有的人却没问题
如果是ip的问题,尝试更换代理后,还是无解
测速也是跑满宽带,怎么回事呢
倾向于谷歌可能检测到youtube-dl的一些请求特征吧
解决办法
解决办法:使用yt-dlp这个youtube-dl的增强库
因为算是拓展,所以之前的参数选项都不需要更改
注意到yt-dlp请求的是 Android API JSON,这点和youtube-dl不同
恢复正常
下载字幕问题
youtube-dl关于youtube字幕的参数选项:
--write-sub 写字幕文件
--write-auto-sub 编写自动字幕文件(仅限YouTube)
--all-subs 下载关于视频的所有字幕
--list-subs 列出关于视频所有可用的字幕
--sub-format FORMAT 字幕格式,接受格式首选项,如"srt"或"ass/srt/best",这个选项一般不指定,因为指定的格式可能没有
--sub-lange LANGS 要下载字幕的语言(可选),以逗号分隔,事业IETF语言标签,如"en,pt"
--proxy 要求youtube-dl下载的路线为代理
只下载youtube视频字幕
如果只下载youtube视频字幕可以用下面的例子:
youtube-dl --write-sub --sub-lang en --skip-download URL/URI
--write-sub : 写入字幕文件,如果想下载自动字幕可以换成--write-auto-sub
--sub-lang en : 获取英文字幕
--sub-format srt : 获取字幕的格式为srt
--skip-download : 不 下载视频
URL : https://www.youtube.com/watch?v=tFq6Q_muwG0 (换成你自己要下载的视频URL)
URI : tFq6Q_muwG0 视频的识别码(换成你自己要下载的视频识别码)
下载码率或者分辨率问题
youtube-dl不带f参数时,默认是下载最高的画质,不过偶尔不是太智能.
比如, 默认情况下, 是根据解析到的码率进行判断,但是,如果碰到返回的解析结果,最低码率带着
# 例子
youtube-dl --list-format URL
480P(best)
720P
1080P
官方文档中的参数
You can also use special names to select particular edge case formats:
- `best`: Select the best quality format represented by a single file with video and audio.
- `worst`: Select the worst quality format represented by a single file with video and audio.
- `bestvideo`: Select the best quality video-only format (e.g. DASH video). May not be available.
- `worstvideo`: Select the worst quality video-only format. May not be available.
- `bestaudio`: Select the best quality audio only-format. May not be available.
- `worstaudio`: Select the worst quality audio only-format. May not be available.
- `filesize`: The number of bytes, if known in advance
- `width`: Width of the video, if known
- `height`: Height of the video, if known
- `tbr`: Average bitrate of audio and video in KBit/s
- `abr`: Average audio bitrate in KBit/s
- `vbr`: Average video bitrate in KBit/s
- `asr`: Audio sampling rate in Hertz
- `fps`: Frame rate
- `ext`: File extension
- `acodec`: Name of the audio codec in use
- `vcodec`: Name of the video codec in use
- `container`: Name of the container format
- `protocol`: The protocol that will be used for the actual download, lower-case (`http`, `https`, `rtsp`, `rtmp`, `rtmpe`, `mms`, `f4m`, `ism`, `http_dash_segments`, `m3u8`, or `m3u8_native`)
- `format_id`: A short description of the format
- `language`: Language code
使用
# 官方例子
# Download best mp4 format available or any other best if no mp4 available
$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
# Download best format available but no better than 480p
$ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'
# Download best video only format but no bigger than 50 MB
$ youtube-dl -f 'best[filesize<50M]'
# Download best format available via direct link over HTTP/HTTPS protocol
$ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'
# Download the best video format and the best audio format without merging them
$ youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'
# 针对我最开始指出的情况,选择一个合适的码率即可
# 码率
youtube-dl -f "best[tbr>3000]"
python调用问题
记录几个常用参数ydl_opts
def down(data,name):
ydl_opts = {
'nooverwrites': True,
'ignoreerrors': True,
'retries': True,
'outtmpl': name,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([data])
基本用法(早期笔记)
关于
- -ciw 默认带上
- 网络状况不好情况下, aria2 效果较好
- 使用基于网卡 tun/tap 的代理软件(比如 netchx)避免很多麻烦
常见参数和例子
# demo
youtube-dl --external-downloader aria2c --external-downloader ar
ia2c --external-downloader-args "-x 16 -k 1M" -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --proxy 'http://127.0.0.1:10809'
# 代理
youtube-dl --proxy 'http://127.0.0.1:1080'
# 下载引擎
--external-downloader aria2c
# 格式
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4
# cookies
youtube-dl -cookies cookies.tx
# 忽略错误警告
youtube-dl -ciw
# 下载视频列表
youtube-dl --playlist-items
# 可用格式
youtube-dl --list-formats
# 用户名密码
youtube -u username -p password
# 下载参数(不常用)
--external-downloader-args "-x 16 -k 1M"
# 栗子 1(下载 4k 转为 mp4)
youtube-dl -ciw -f 'bestvideo[ext=webm]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 URL
# 栗子 2(下载 1080p 转为 mkv)
youtube-dl -ciw -f 'bestvideo[ext=mp4]+bestaudio[ext=mp4]/bestvideo+bestaudio' --merge-output-format mkv URL
# 栗子 3(自动寻找分辨率大于等于 1080p 的可用格式进行下载)
youtube-dl -ciw -f best[height>=1080] URL
# 栗子4(指定文件名与格式)
youtube-dl -ciw --output "%(title)s.mp4" URL