Try again when the connection is disconnected does not work

I use youtube-dl to download videos from YouTube. But in my office, the Internet will turn off every 20Mb downloads. Error: The connection is forcibly closed by the remote server.

I need to type the url again to resume the download and it will shut down again after '20Mb' I want youtube-dl to reconnect and try to download the file again.

I tried using the --retries switch, but it does not restart after a shutdown.

Is there any inbuild or Work for this method?

+5
source share
2 answers

Educated guess

It would be best to specify the cache directory and use the -c flag to force the download to continue, if possible.

Source: youtube-dl page

 --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. 

Alternative solution

If you want to try python, this script should do what you need with a little tweaking.

 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) 

Link for youtube_dl API: https://github.com/rg3/youtube-dl/blob/master/README.md#readme

+2
source

Get bash , either through steve win-bash , a new version of windows10 / Ubuntu or cygwin

Call youtube-dl as follows:

 while ! youtube-dl <video_uri> -c --socket-timeout 5; do echo DISCONNECTED; done 

You might want to add some sleep time between attempts.

 while ! youtube-dl <video_uri> -c --socket-timeout 5; do echo DISCONNECTED; sleep 5; done 

There should be an equivalent shell wrapper or an ugly while while package checking for ERRORLEVEL

+5
source

Source: https://habr.com/ru/post/1246403/


All Articles