Retry when connection disconnect not working

Olivarsham picture Olivarsham · Apr 4, 2016 · Viewed 11k times · Source

I am using youtube-dl for downloading the videos from YouTube. But in my office the internet will disconnect every 20Mb of download. [Error: Connection forcibly closed by remote server].

I have to type the URL again to resume the download and again it will disconnect after '20Mb' I want youtube-dl to reconnect and retry to download the file.

I tried using --retries switch but it is not retrying once disconnected.

Is there any inbuild method or Work around for this?

Answer

xvan picture xvan · Apr 13, 2016

Get a bash , either via steve's win-bash, the new windows10/Ubuntu thing or cygwin

Call youtube-dl like this:

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

You may want to add some sleep time between retries.

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

There should be a power shell equivalent, or an ugly batch while loop checking ERRORLEVEL