我正在使用youtube-dl
从YouTube下载视频。但在我的办公室,互联网将断开每20Mb
次下载。 [错误:远程服务器强行关闭连接]。
我必须再次输入网址才能恢复下载,并且在'20Mb'后它将再次断开连接
我希望youtube-dl
重新连接并重试下载该文件。
我尝试使用--retries
开关,但一旦断开连接就不会重试。
是否有任何内置方法或解决此问题?
答案 0 :(得分:9)
通过steve's win-bash
,new windows10/Ubuntu或[{3}}
bash
像这样调用youtube-dl:
while ! youtube-dl <video_uri> -c --socket-timeout 5; do echo DISCONNECTED; done
您可能希望在重试之间添加一些休眠时间。
while ! youtube-dl <video_uri> -c --socket-timeout 5; do echo DISCONNECTED; sleep 5; done
应该有一个等效的power shell,或者是一个丑陋的批cygwin
检查while loop
答案 1 :(得分:4)
我最好的猜测是指定一个缓存目录,如果可能的话,使用-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
答案 2 :(得分:1)
等效批次:
for /L %%? in (0,0,1) do @(youtube-dl <video_uri> -c --socket-timeout 5 && break)
这包括5秒钟的睡眠时间:
for /L %%? in (0,0,1) do @(youtube-dl <video_uri> -c --socket-timeout 5 && break || timeout /t 5 >NUL)
答案 3 :(得分:0)
等效的powershell:
Do { youtube-dl.exe <video_uri> -c } until ($?)
答案 4 :(得分:0)
试试retry-cli。您需要先安装 Node.js(使用 npm)
npm install --global retry-cli
retry youtube-dl <URL>