Monday, September 29, 2008

-"We're sorry, this video is no longer available" YouTube downloader

More often than not, when the planets and moons aren't oriented in the right manner, I get the dreaded "We're sorry, this video is no longer available" from YouTube. I know that the video is certainly NOT "no longer available" because its clearly viewable by other people.

Fortunately in the linux world, there is this little python utility called youtube-dl which can be run from the command line to download any YouTube file. So when you get this error, copy the URL of the YouTube file, and do this:

# sudo apt-get install youtube-dl
# youtube-dl http://www.youtube.com/watch?v=videofile001

if it doesn't work, it will complain with this verbose error:

Retrieving video webpage... done.
Extracting URL "t" parameter... done.
Requesting video file... failed.
Error: unable to download video data.
Try again several times. It may be a temporary problem.
Other typical problems:

* Video no longer exists.
* Video requires age confirmation but you did not provide an account.
* You provided the account data, but it is not valid.
* The connection was cut suddenly for some reason.
* YouTube changed their system, and the program no longer works.

Try to confirm you are able to view the video using a web browser.
Use the same video URL and account information, if needed, with this program.
When using a proxy, make sure http_proxy has http://host:port format.
Try again several times and contact me if the problem persists.

You can then repeat this process over and over again, until it succeeds. Unfortunately this requires effort. And we computer users hate expending any unnecessary energy if possible. After all, focusing on the terminal, clicking the up arrow and hitting return is so so tedious.

So I wrote a little bash script to complement youtube-dl as it sports a few extra features:
  1. It will automatically try and retry to youtube-download the file until it is successful (thanks to $?)
  2. It will rename the resultant flv video filename to the current date and time, instead of the random garbage filename. (using date +%F...)
  3. It terminates gracefully when the user hits Ctrl-C (by setting a trap ...)
  4. It promotes world peace by waiting a few seconds before trying again (sleep is always good)
And here it is:

#!/bin/bash

i=1
fname=`date +%F-%H%M`

result=1

while [ $result = 1 ]; do
echo Attempt $i "$fname".flv
trap "echo User killing the download; exit" INT TERM
youtube-dl $1 -o "$fname".flv
result=$?
let i=i+1
if [ $result = 1 ]; then
sleep 10
fi
done

Try it out. The most I had to wait was 24 attempts. Thats 46 keypresses saved!


yk.

5 lewsers:

Endless Nameless said...

Great post and script!
It saved a lot of key pressing!

I have a question: I was using youtube-dl inside a bash script. It worked for a while, and so, without any reason to me, it stoped. I did something like this inside the script

"youtube-dl $URL"

where URL="www.youtube.com/watch?v="$1
and $1 is the name of the file.

Now it says that URL doesn't exist. Any idea of what is going on?

Yoon Kit said...

Endless, thanks.

Im not sure why your bash script doesnt work. Seems straightforward enough and should just work .. ?

yk

Gagan said...

when this error appears on all the videos, what you do is disable your download manager and then try again !!

read this post of mine telling about this error in detail :

http://84productions.blogspot.com/2009/03/were-sorry-this-video-is-no-longer.html

Dean said...

greetings to all.
I would first like to thank the writers of this blog by sharing information, a few years ago I read a book called guanacaste costa rica in this book deal with questions like this one.

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.