连接断开时重试不起作用
Retry when connection disconnect not working
我正在使用 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
通过 steve's win-bash
, the new windows10/Ubuntu thing or cygwin
获取 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
应该有一个功率 shell 等效的,或者一个丑陋的批次 while loop checking ERRORLEVEL
powershell 等价物:
Do { youtube-dl.exe <video_uri> -c } until ($?)
等效批次:
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)
尝试retry-cli。您需要先安装 Node.js(使用 npm)
npm install --global retry-cli
retry youtube-dl <URL>
我正在使用 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
通过 steve's win-bash
, the new windows10/Ubuntu thing or cygwin
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
应该有一个功率 shell 等效的,或者一个丑陋的批次 while loop checking ERRORLEVEL
powershell 等价物:
Do { youtube-dl.exe <video_uri> -c } until ($?)
等效批次:
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)
尝试retry-cli。您需要先安装 Node.js(使用 npm)
npm install --global retry-cli
retry youtube-dl <URL>