要执行此命令,您需要安装 ffmpeg(youtube-dl 用于转换的音频和视频转换器)
从单个电影下载音频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0
它只下载音频(没有视频)并将其转换为mp3。
选项--audio-quality 0 在那里非常重要!
如果没有此选项,您会在mp3 压缩过程中损失一些音质。
--audio-quality 0 告诉 youtube-dl 以最佳质量保存音频文件(转换为 mp3 时)。
如果没有这个选项,mp3 音频质量默认设置为0-9 scale 中的5,其中0 是最好的质量,9 是最差的质量。所以默认情况下质量更差。
面向非高级用户的 Youtube 流,可变比特率高达 160kbps,opus 格式。 Opus 格式比 mp3 更新,并且比 mp3 具有更好的压缩率,保持相同的质量。所以160kbps opus = ~256kbps mp3。
默认音频质量时(0-9 scale 中的5)mp3 比特率限制为160kbps,这意味着在压缩过程中会丢失一些音质。当音频质量设置为 0 时,mp3 会上升到 300kbps 保留原始质量。
从一个频道下载所有电影的音频
命令是一样的,但是你应该把链接放到频道而不是链接到单个视频:
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-quality 0 --audio-format mp3 https://www.youtube.com/c/someChannelName1232143/videos
从播放列表下载音频
您必须添加--yes-playlist 选项。
你可以放一个播放列表的链接(用playlist字链接):
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist https://www.youtube.com/playlist?list=c29tZVZpZGVvVVJMUGFy
或者在播放播放列表时链接到播放列表中的一首歌曲(使用list字链接):
youtube-dl -f "bestaudio/best" -ciw -o "%(title)s.%(ext)s" -v --extract-audio --audio-format mp3 --audio-quality 0 --yes-playlist "https://www.youtube.com/watch?v=c29tZVZpZGVvUGxheWxpc3RQYXJ0&list=c29tZVZpZGVvTGlzdFBhcnRzc29tZVZpZGVvTGlzdFBhcnRz&index=4"
命令选项说明:
-f "bestaudio/best" <- Choose the best audio format.
As there is only audio format listed only the audio is downloaded.
-c <- (--continue) Force resume of partially downloaded files.
By default, youtube-dl will resume downloads if possible.
As docs state maybe it is default, but I put it to make sure it is set.
-i <- (--ignore-errors) Continue on download errors,
for example to skip unavailable videos in a playlist.
-w <- (--no-overtwrites) Do not overwrite files
(If something was already downloaded
and is present in the directory then continue with the next video)
-o "%(title)s.%(ext)s" <- (--output) Output filename template,
in this case it gives you file named movieTitle.mp3
where movieTitle is the title of the video on youtube.
-v <- (--verbose) Print various debugging information
--extract-audio <- (-x) Convert video files to audio-only files
(requires ffmpeg or avconv and ffprobe or avprobe)
--audio-quality 0 <- Specify ffmpeg/avconv audio quality,
insert a value between 0 (better) and 9 (worse) for VBR or a specific
bitrate like 128K (default 5).
Youtube streams for nonpremium users with variable bitrate up to 160kbps in opus format.
Opus format is newer than mp3 and has better compression than mp3
preserving the same quality. So 160kbps opus = ~ 256kbps mp3.
When audio-quality is default (5 in 0-9 scale) mp3 bitrate
is limited to 160kbps which means that some sound quality is lost during compression.
When audio-quality is set to 0 mp3 goes up to 300kbps preserving original quality.
--audio-format mp3 <- Specify audio format: "best", "aac", "flac", "mp3", "m4a",
"opus", "vorbis", or "wav"; "best" by default; No effect without -x (--extract-audio).
In this case we choose mp3.
Alternatively you could choose for example opus which
is oryginally provided by youtube and is newer and better than mp3
or flac which is loseless codec.
我提供的所有链接都是假的。我只是在其中放了一些由 base64 编码的随机单词。因此,您必须用自己的链接替换它们才能使其正常工作。
提示:
Youtube-dl gives you opportunity to use your own youtube account to download stuff.
If your account is a premium account you can get
higher 320kbps opus bitrate which is equivalent of ~512kbps mp3.
Using your own account might be possible by setting --username and --pasword
(See Authentication Options in --help)