youtube-dl - 当连接断开不起作用时重试

标签 youtube-dl

我正在使用 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/

相关文章:

php - 带有PHP的YouTube下载器

python-2.7 - Mac上ffprobe/avprobe和youtube_dl的Python问题

html - 从 YouTube-DL 自动生成 HTML5 <video> 标签

bash - youtube-dl 获取 channel /播放列表名称并将其传递给 bash 一行脚本

python - youtube dl 如何从播放列表下载所有音频

python - 为什么 youtube-dl 仍在下载 'keepvideo' :False? 的视频

ffmpeg - 使用 youtube-dl 和 ffmpeg(或 vlc)将 YouTube 直播流转码为 rtsp rtmp udp rtp

node.js - 使用 Node youtube-dl和MeteorJS保存视频文件