youtube-dl 格式选项 API
youtube-dl format options API
youtube API 是否提供您从 youtube 收听的原始音频作为下载选项?可能是 --extract-audio 选项?
默认情况下,youtube-dl 会尝试下载可用的最佳质量,即如果您想要最好的质量,则无需通过任何特殊选项,youtube-dl 默认会为您猜测。
自 2015 年 4 月末和版本 2015.04.26 起,youtube-dl 使用 -f bestvideo+bestaudio/best 作为默认格式选择(参见#5447(https://github.com/ytdl-org/youtube-dl/issues/5447), #5456(https://github.com/ytdl-org/youtube-dl/issues/5456))。
如果您想保留旧的格式选择行为(在 youtube-dl 2015.04.26 之前),即您想要下载质量最好的媒体作为单个文件,您应该明确指定您的选择 -最好。你可能想将它添加到配置文件中,以免每次你都输入它 运行 youtube-dl。
参考:https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme
如果这有帮助,请告诉我。如果没有,我们可以具体了解一下。
更新
以下是一些可能派上用场的命令;
# 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'
更灵活(使用 shell 别名)
如前所述,默认设置为从提供的视频中下载最高质量 URL。
这并不等同于说它将永远如此,而且肯定不会一直如此。
我是稳定性的粉丝,并且在直接指定选项方面有更好的经验,因为默认值会随着版本/更新而改变,但使用特定选项仍然有效,否则你会得到警告或错误。
使用直接选项我知道我最终会得到什么。
它也更灵活。
您可以选择要优先处理的首选格式,如果请求的 format/quality 不可用,您可以自动合并最兼容的视频 + 音频,您可以指定格式字符串来命名下载的文件,并决定在哪里它最终会结束(默认情况下它是当前工作目录)。
您可以使用单独的设置文件,在 Mac 默认情况下:
~/.config/youtube-dl/config
或者,您可以使用 shell 中定义的别名
(我将别名命名为 :ytdl
)所以我只是这样做:
:ytdl link_to_single_video
并将其设置为自动下载首选 video/audio 格式,并将它们合并到我的 shell 启动文件中 alias 命令指定的位置,使用我决定的命名约定它使用。
我还有一个 :ytdlpl playlist_id
别名,可以将完整的播放列表下载到指定文件夹:
/playlists/[name_from_playlist_title]/[episode_num_and_name_from_playlist].[ext]
我通过设置两个别名来完成此操作:
# Download best mp4 format available or other format if no mp4 is available
alias :ytdl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(title)s.%(ext).s"'
# Download YouTube playlist videos in separate directory indexed by video order in a playlist
alias :ytdlpl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s"'
您选择如何执行此操作是个人喜好,但这至少可以完美满足我的需求!
youtube API 是否提供您从 youtube 收听的原始音频作为下载选项?可能是 --extract-audio 选项?
默认情况下,youtube-dl 会尝试下载可用的最佳质量,即如果您想要最好的质量,则无需通过任何特殊选项,youtube-dl 默认会为您猜测。
自 2015 年 4 月末和版本 2015.04.26 起,youtube-dl 使用 -f bestvideo+bestaudio/best 作为默认格式选择(参见#5447(https://github.com/ytdl-org/youtube-dl/issues/5447), #5456(https://github.com/ytdl-org/youtube-dl/issues/5456))。
如果您想保留旧的格式选择行为(在 youtube-dl 2015.04.26 之前),即您想要下载质量最好的媒体作为单个文件,您应该明确指定您的选择 -最好。你可能想将它添加到配置文件中,以免每次你都输入它 运行 youtube-dl。
参考:https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme
如果这有帮助,请告诉我。如果没有,我们可以具体了解一下。
更新
以下是一些可能派上用场的命令;
# 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'
更灵活(使用 shell 别名)
如前所述,默认设置为从提供的视频中下载最高质量 URL。 这并不等同于说它将永远如此,而且肯定不会一直如此。
我是稳定性的粉丝,并且在直接指定选项方面有更好的经验,因为默认值会随着版本/更新而改变,但使用特定选项仍然有效,否则你会得到警告或错误。
使用直接选项我知道我最终会得到什么。
它也更灵活。
您可以选择要优先处理的首选格式,如果请求的 format/quality 不可用,您可以自动合并最兼容的视频 + 音频,您可以指定格式字符串来命名下载的文件,并决定在哪里它最终会结束(默认情况下它是当前工作目录)。
您可以使用单独的设置文件,在 Mac 默认情况下:
~/.config/youtube-dl/config
或者,您可以使用 shell 中定义的别名
(我将别名命名为 :ytdl
)所以我只是这样做:
:ytdl link_to_single_video
并将其设置为自动下载首选 video/audio 格式,并将它们合并到我的 shell 启动文件中 alias 命令指定的位置,使用我决定的命名约定它使用。
我还有一个 :ytdlpl playlist_id
别名,可以将完整的播放列表下载到指定文件夹:
/playlists/[name_from_playlist_title]/[episode_num_and_name_from_playlist].[ext]
我通过设置两个别名来完成此操作:
# Download best mp4 format available or other format if no mp4 is available
alias :ytdl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(title)s.%(ext).s"'
# Download YouTube playlist videos in separate directory indexed by video order in a playlist
alias :ytdlpl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s"'
您选择如何执行此操作是个人喜好,但这至少可以完美满足我的需求!