循环让 youtube-dl 下载其中一种格式(取决于错误)

Loop for youtube-dl to download one of either formats (depending on errors)

尝试下载 100 多个视频,其中大部分都以“-f 43 格式”提供,我有时会遇到错误 "ERROR: requested format not available"。

所以我想要一个循环,在这些情况下尝试相同的下载,但采用“-f 18”格式(足够相似)。

我认为这应该是可能的,可能在 bash 中,但我不清楚如何实现。非常感谢任何帮助!

无需外部编码; youtube-dl 本机包含此功能。只需在 -f 参数中添加斜杠即可。例如,如果您想要格式 43,如果 18 失败,并且失败只是最好的单个文件,请像这样调用 youtube-dl:

youtube-dl -f 43/18/best https://www.youtube.com/watch?v=BaW_jenozKc

有关详细信息,请参阅 official documentation on format selection