使用youtbe-dl来下载youtube的视频,相信大家都不陌生了,youtbe-dl可以在win上和linux上使用,这次就在debian 10上安装吧。

安装超级简单,两条命令完成

wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
chmod a+rx /usr/local/bin/youtube-dl

然后在安装ffmpeg,以便在下载时,可以音频和视频一起下载合成

apt-get update
apt-get install -y ffmpeg

安装完成后,报错如下:

root@debian:~# youtube-dl -U
WARNING: Assuming --restrict-filenames since file system encoding cannot encode all characters. Set the LC_ALL environment variable to fix this.
ERROR: can't find the current version. Please try again later.

显示字符有问题,解决如下:

export LANG=en_US.UTF-8
export LANGUAGE=en_US:en

使用方法:

youtube-dl -F [url]

显示可下载的列表,如下:

youtube-dl -F https://www.youtube.com/watch?v=yITr127KZtQ
[youtube] yITr127KZtQ: Downloading webpage
[info] Available formats for yITr127KZtQ:
format code  extension  resolution note
249          webm       audio only tiny   63k , opus @ 50k (48000Hz), 2.42MiB
250          webm       audio only tiny   82k , opus @ 70k (48000Hz), 3.15MiB
140          m4a        audio only tiny  130k , m4a_dash container, mp4a.40.2@128k (44100Hz), 5.68MiB
251          webm       audio only tiny  155k , opus @160k (48000Hz), 5.97MiB
394          mp4        230x144    144p   67k , av01.0.00M.08, 30fps, video only, 2.55MiB
160          mp4        230x144    144p   98k , avc1.4d400c, 30fps, video only, 2.66MiB
133          mp4        384x240    240p  120k , avc1.4d400d, 30fps, video only, 3.34MiB
395          mp4        384x240    240p  132k , av01.0.00M.08, 30fps, video only, 4.62MiB
278          webm       230x144    144p  143k , webm container, vp9, 30fps, video only, 4.59MiB
242          webm       384x240    240p  159k , vp9, 30fps, video only, 4.84MiB
134          mp4        576x360    360p  211k , avc1.4d401e, 30fps, video only, 5.97MiB
243          webm       576x360    360p  253k , vp9, 30fps, video only, 7.61MiB
396          mp4        576x360    360p  261k , av01.0.01M.08, 30fps, video only, 8.24MiB
135          mp4        768x480    480p  311k , avc1.4d401f, 30fps, video only, 9.23MiB
244          webm       768x480    480p  359k , vp9, 30fps, video only, 10.39MiB
136          mp4        1152x720   720p  418k , avc1.4d401f, 30fps, video only, 12.93MiB
397          mp4        768x480    480p  439k , av01.0.04M.08, 30fps, video only, 13.50MiB
247          webm       1152x720   720p  604k , vp9, 30fps, video only, 17.12MiB
398          mp4        1152x720   720p  907k , av01.0.05M.08, 30fps, video only, 26.73MiB
18           mp4        576x360    360p  395k , avc1.42001E, 30fps, mp4a.40.2@ 96k (44100Hz), 17.35MiB
22           mp4        1152x720   720p  424k , avc1.64001F, 30fps, mp4a.40.2@192k (44100Hz) (best)

可以看到音频和视频都有编号,下载对应的编号即可


youtube-dl -f 140 [url]

下载对应编号的音频或视频


youtube-dl -f 134+140 [url]

下载音频视频合并文件,注意,视频编号要在前面

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=BaW_jenozKc

将音频下载为mp3格式

发表评论

电子邮件地址不会被公开。 必填项已用*标注