Friday, April 5, 2013

How to download PyCon US 2013 videos for offline viewing using youtube-dl


By Vasudev Ram


As Pythonistas would know, PyCon US 2013 happened recently.

While reading Python news on the Net, I saw that the videos of the conference were being uploaded to pyvideo.org.

I browsed the list of videos there. Since I had recently come across youtube-dl, a YouTube downloader tool, I thought of trying to download the PyCon videos using it.

When I went to the pyvideo site to do that, and played one or two videos available there, I was not sure at first whether they were from YouYube or not, so was not sure whether I could download them using youtube-dl.

A little experimentation showed that they were in fact hosted on YouTube, and I was able to find out how to download them, and then downloaded a few of them.

So I'm giving the steps for doing that below:

(Note: these steps worked for me - I could download a few videos using the steps, and none have given an error so far, but YMMV, depending on your OS, browser, Flash Player version, or other factors.)

Update: before (or after) reading these steps, you may wish to read the comments on this post. Some readers commented, and gave simpler methods of doing the same thing, in particular, some said that there is a direct link to download the video on some or all of the pyvideo video pages, and some said that the URL-fixing step is not needed since you can just right-click on the video to get the right URL without the extraneous stuff. Also, renaming the video to remove the extraneous stuff in the name can be avoided by using some command-line options of youtube-dl.

- Go to pyvideo.org in your browser.

- Select the category called PyCon US 2013 videos.

- Select one of the videos from that category and open the link to the video in another browser tab (or in the same tab).

For example, try Guido van Rossum's keynote at PyCon US 2013.

- Click the share video icon at the top right of the video screen; it looks like a V (with small knobs at its vertices), but rotated to the right by 90 degrees.

- The top left of the video screen will now show the URL for the video (along with buttons to share it on Facebook, Twitter, etc.)

- Hover your mouse over that URL and then right click it. You may have to right-click twice, or first click on the URL and then right-click on it.

- From the Adobe Flash Player pop-up menu that appears, select "Copy video URL".

- Now, open a DOS command prompt. I am using Windows in this example; adjust the steps for Linux or Mac OS X, i.e. use a bash or other shell and modify the steps for copy and paste below, to suit your OS.

- At the prompt (Windows), type the partial command:

youtube-dl -t (followed by a space)

- Then type Alt-Space, then E, then P.

- That brings up the Windows system menu for the DOS window, and then selects the Edit menu in it, and then the Paste option from that menu.

- So the video URL will get pasted to the end of youtube-dl command you typed earlier.

- Now, if you just try to run the command as it is, it may not work (for downloading by youtube-dl), because of some extra parameters in the URL, that youtube-dl cannot handle.

- For example, here is the copied video URL for the GvR keynote:

http://www.youtube.com/watch?feature=player_embedded&v=n6dUWXRdt48

- Edit the URL using arrow keys, backspace, delete key, etc., to remove the part from "feature" upto "embedded&"; in other words (using HTTP request terms), remove all the key-value pairs except for the "v=something" pair.

- Using the above GvR keynote example, the command-line should now look like this:

youtube-dl -t http://www.youtube.com/watch?v=n6dUWXRdt48

- Now hit Enter, and wait while the video downloads. The -t option to youtube-dl will add the title of the video as a prefix to the download filename. I typically rename the file to remove the cryptic characters after the title, like this:

c:\downloads> ren Keynote-n6dUWXRdt48.flv GvR-Keynote.flv

- Now you can play the video in VLC, MPlayer or any other suitable player.

Enjoy.

- Vasudev Ram - Dancing Bison Enterprises



8 comments:

Anonymous said...

Or you could just scroll down the pyvideo page a bit and click the "MP4" download link, and download it directly from archive.org in your browser ;)

But it's a good example of how to use youtube-dl, I suppose. On pyvideo they put a direct youtube link down the page under "Video Origin" which can be copied directly to the command line, no editing necessary, but for other sites that won't always be the case. I always just click the title of the video in the youtube player; that opens up the youtube page in a new tab, which I find the easiest-to-remember way to get at the basic youtube URL.

Jonathan Street said...

For many of the videos on pyvideo there is also a download link in the right sidebar.

As well as being easier when available the download links also tend to be faster.

Abdul Muneer said...

But this has to repeated for each video, right? The 'DownloadHelper' browser plugin for FF comes handy for that. I used it download the PyCon videos. You can also select the video quality like 360p or 480p etc.
I am looking for ways to automate the entire thing so that the whole series can be downloaded in one go.

PS: Your comment captcha are too hard.

Anonymous said...

Hi,

this process seems overly complicated to me. I'm using youtube-dl under Linux (so i can't test the behaviour on Windows).

- You can get the video URL much simpler by just clicking right on the video (not on the share button).
- youtube-dl is able to handle additional parameters (i.e. ignoring them). Perhaps you need to encapsulate the link in "". On Linux, the following works:
youtube-dl "http://www.youtube.com/watch?feature=player_embedded&v=n6dUWXRdt48"
- You do not need to rename afterwards as you can specify your own file name template using the "-o" option (see help for details):
youtube-dl -o "%(title)s.%(ext)s" "http://www.youtube.com/watch?feature=player_embedded&v=n6dUWXRdt48"
This would store the Keynote as "Keynote.flv" without the video id in the filename.

Vasudev Ram said...

Thanks for all the comments. I will check out the alternatives mentioned.

@Anonymous (4th comment): I had not tried it with double quotes around the video link. That may work, yes. I guess the issue when not using quotes may be that the DOS command shell interprets some characters from the video link as metacharacters.

Vasudev Ram said...

@Anonymous (4th comment): I do remember reading about those file naming options of youtube-dl when I first checked it out, but forgot about them when writing the download steps. Thanks for mentioning it.

Vasudev Ram said...

@Abdul Muneer: Sorry for the inconvenience with the captchas.

Actually I haven't modified the default captcha settings that Blogger/Blogspot provides, and I also have the same issue of captchas difficult to recognize with many sites that I visit.

I have not modified my blog settings for some time, but IIRC, the last time I did it, Blogger/Blogspot had no configurable settings for captchas.

You probably know this already, but yuu could try the audio captcha option. It may work.

Vasudev Ram said...

@Anonymous (4th comment): I tried downloading a video with double quotes around the URL, and it worked. Thanks again :)

Forgotten some of my DOS fu, since not worked on it for a while ...

If I was on Linux I probably would have tried that, and a lot of other things, almost automatically.

I still like DOS, though. It was the first OS I worked on, and only after a year or two, started on UNIX, though much more UNIX experience overall.

DOS software was really great (particularly given the limitations of both hardware and software at the time), in terms of speed, small size, etc.

WordStar, Lotus 1-2-3, Turbo Pascal, Turbo C, a lot of cool TSRs like SideKick, Lotus Manifest, ... I can go on ... :-)