Linux.com

Feature

CLI Magic: Enhance your YouTube viewing pleasure

By Joe Barr on August 14, 2006 (8:00:00 AM)

Share    Print    Comments   

Publishing your own video on YouTube, or watching other people's videos, is all the rage these days. Why are we talking about YouTube, in a column about the CLI? Because this week we're writing about youtube-dl, a clever little CLI tool that's easy to install and use to fetch YouTube videos.

Youtube-dl is a Python script, licensed under the "non-copyleft" free software MIT/X11 license. It is not platform-specific; it can run under Linux, Mac OS X, or Windows platforms so long as a recent -- 2.4 or later -- version of Python is installed.

Installation consists of viewing a page in your browser and then saving it to your hard drive. Once that is done, you can check the MD5 checksum on the download page to make sure you saved an undefiled version. Assuming you have md5sum installed on your system, enter the following command at the CLI:

md5sum youtube-dl

You should see the following output:

faae21b5ffaa31a6ee5f06b77226d4ed youtube-dl

That's a match with the sum on the download page, so you're good to go. The MD5 checksum will change, of course, as the program is updated.

The next step is to make the file executable. As downloaded, youtube-dl permissions are probably "-rw-r--r--", so you wouldn't be able to execute the file as-is. To make it executable for the owner, enter the following command at the CLI in the directory containing the file:

chmod 744 youtube-dl

Then, as root, move the script into a directory in your path, such as /usr/bin. That's all there is to the install.

Using it is just as easy. All you need to do is enter the command youtube-dl followed by the URL of the video you want to fetch:

$ youtube-dl http://www.youtube.com/watch?v=p_YMigZmUuk
Retrieving video webpage... done.
Extracting video URL parameters... done.
Retrieving video data... 4590k of 4590k done.

Unless you specify the filename using the -o option, youtube-dl will save the file as videoid.flv; if your URL is http://youtube.com/watch?v=5Da9sc6YDBo, the video ID is 5Da9sc6YDBo.

Once you have the file, you can play it using MPlayer or another video player that supports ffmpeg. The youtube-dl page says that VLC should also work, but it refused to play the saved video on my systems.

Youtube-dl has a few simple command-line options. You can display all of the options by running youtube-dl -h:

$ youtube-dl -h
usage: youtube-dl [options] video_url

options:
  -h, --help            print this help text and exit
  -v, --version         print program version and exit
  -u USERNAME, --username=USERNAME
                        account username
  -p PASSWORD, --password=PASSWORD
                        account password
  -o FILE, --output=FILE
                        output video file name

In addition to the -o option, which allows you to change the video file name, you can also specify your YouTube username and password, if they're required to download certain content.

That's the whole thing. Youtube-dl is a small, focused, and very usable CLI tool that enhances your video enjoyment.

Share    Print    Comments   

Comments

on CLI Magic: Enhance your YouTube viewing pleasure

Note: Comments are owned by the poster. We are not responsible for their content.

Nice tool ... a few CLI addition to the article

Posted by: Anonymous Coward on August 14, 2006 08:08 PM
Since this is a "command line interface" article, why not download the script using wget (or curl)<nobr> <wbr></nobr>...




You can still check the md5sum, but it's probably unnessecary since wget is unlikely to munge the download like browsers sometimes do. It's a good idea if you are paranoid, however (which you should be<nobr> <wbr></nobr>:) ).



Also, you don't need to install the script as root right away<nobr> <wbr></nobr>... I'd suggest testing it out first, then installing it in<nobr> <wbr></nobr><tt>/usr/local/bin/</tt> if you want to install it system-wide. It will run just fine from your home directory.



Finally<nobr> <wbr></nobr>.. you can play your newly acquired videos using mplayer:

<tt>mplayer videoid.flv</tt>


Ta-da !!!

#

Re:Nice tool ... a few CLI addition to the article

Posted by: Anonymous Coward on August 15, 2006 09:39 PM
Of course MPlayer should be outputting to ASCII mode if you REALLY want to do it from the CLI<nobr> <wbr></nobr>:-)

#

Re:Nice tool ... a few CLI addition to the article

Posted by: Joe Barr on August 14, 2006 08:26 PM
As they say, there is more than one way to skin a cat. In this case, I am not sure there is any real advantage to using wget, and the philosophy behind this column is not to use the CLI every time, but to use it when it makes sense to do so, in terms of ease or speed or functionality.


The md5 checksum is needed more for security than for the possibility of munging data during download.

#

a bash version

Posted by: Anonymous Coward on August 14, 2006 11:19 PM
<a href="http://bashscripts.org/viewtopic.php?t=210" title="bashscripts.org">http://bashscripts.org/viewtopic.php?t=210</a bashscripts.org>
<tt>#!/bin/bash
bu="http://youtube.com/get_video.php<nobr>?<wbr></nobr> ";mkdir -p ~/YouTube;cd ~/YouTube;read -p "YouTube url? " ur;read -p "Name? " nv
wget ${ur} -O<nobr> <wbr></nobr>/tmp/y1;uf=${bu}`grep player2.swf<nobr> <wbr></nobr>/tmp/y1 | cut -d? -f2 | cut -d\" -f1`;wget "${uf}" -O<nobr> <wbr></nobr>/tmp/y.flv
ffmpeg -i<nobr> <wbr></nobr>/tmp/y.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${nv}.mpg;rm<nobr> <wbr></nobr>/tmp/y.flv; rm<nobr> <wbr></nobr>/tmp/y1;rm gmon.out; exit</tt>

#

chmod 744?

Posted by: Anonymous Coward on August 21, 2006 08:19 AM
Don't you mean chomd 755 so that it's executable by all?

#

Re:chmod 744?

Posted by: Anonymous Coward on August 21, 2006 02:19 PM
Propably not.
Executable only by owner, readable by others

#

Great tool...

Posted by: Administrator on March 16, 2007 10:42 PM
exactly what I was looking for

#

CLI Magic: Enhance your YouTube viewing pleasure

Posted by: Anonymous [ip: 200.199.23.105] on August 30, 2007 07:20 PM
<h1>teste</h1>

#

CLI Magic: Enhance your YouTube viewing pleasure

Posted by: Anonymous [ip: 202.88.246.131] on December 23, 2007 03:25 PM
You don't need to install it as root _or_ move to /usr/bin:

Just do:

$ python youtube-dl video-url

and you are good to go.

#

CLI Magic: Enhance your YouTube viewing pleasure

Posted by: Anonymous [ip: 213.220.225.116] on February 17, 2008 07:47 PM

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya