我正在使用 youtube-dl
用于从 YouTube 下载视频。但是在我的办公室,互联网会每隔 20Mb
断开一次。的下载。 [错误:连接被远程服务器强行关闭]。
我必须再次输入 URL 才能继续下载,并且在“20Mb”之后它将再次断开连接
我要 youtube-dl
重新连接并重试下载文件。
我尝试使用 --retries
切换,但一旦断开连接就不会重试。
是否有任何内置方法或解决方法?
最佳答案
有根据的猜测
我最好的猜测是指定一个缓存目录,并使用 -c
标志以强制它在可能的情况下继续下载。
来源:youtube-dl 手册页
--cache-dir DIR
Location in the filesystem where youtube-dl can store some downloaded information permanently. By default
$XDG_CACHE_HOME /youtube-dl or ~/.cache/youtube-dl . At the moment, only YouTube player files (for videos with obfus‐
cated signatures) are cached, but that may change.
-c, --continue
Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.
替代方案
如果您想尝试一下 Python,这个脚本应该可以通过一些小的调整来满足您的需求。
import sys
import youtube_dl
def download_no_matter_what(url):
try:
youtube_dl.YoutubeDL(options).download([url])
except OSError:
download_no_matter_what(url)
except KeyboardInterrupt:
sys.exit()
if __name__ == '__main__':
# Read the URL from the command line
url = sys.argv[1]
# Specify extra command line options here
options = {}
# GET THAT VIDEO!
download_no_matter_what(url)
youtube_dl API 引用:https://github.com/rg3/youtube-dl/blob/master/README.md#readme
关于youtube-dl - 当连接断开不起作用时重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401603/