[HOWTO] Modify youtube-dl to make it bandwidth friendly by adding option to download lowest quality video

youtube-dl is a command line utility that can be used to download Youtube videos. It has many command line switches ; most notably -t to save the video with title of the video as filename, -c to continue the download instead of starting over. It can be installed in Ubuntu Lucid Lynx and Maverick Meerkat via Synaptic by enabling universe repository. Then running the following command will update it to the latest version:

sudo youtube-dl -U

If you want to use it in older Ubuntu releases or other Linux distros, visit the official site.
It also has a switch -f with which you can select a Youtube Video Format to download. Like this:

youtube-dl -f 34 "http://www.youtube.com/watch?v=2_VFKqw1q2Q"

That will download video with format code 34 if available. 34 is 360p flv format. You will need to know the formats to be able to use this options and all this information is available in Youtube Wikipedia Article. If the format you requested is not available, it will print the message:

ERROR: unable to download video (format may not be available)

I don’t know why someone would like to do it, but an option f-1 is available which downloads all available qualities of the video. If you don’t provide any format information, it will download the best quality version of the video. You can always try your luck with the following formats that are supported for youtube, arranged in decreasing quality:
38, 37, 22, 45, 35, 34, 43, 18, 6, 5, 17, 13
That is, if format 38 is available, it will download it and if it isn’t it will download 37 and so on.

But what if you want to download the lowest quality or worst quality of video to be able to download quickly? It currently does not have such an option and we will add it. To do so, open it up in a text editor. I’m using gedit:

gksu gedit /usr/bin/youtube-dl

and then find the following code (in the version 2010.08.04 that I have, it starts in line 938):

			if requested_format is None:
				video_url_list = [(existing_formats[0], get_video_template % existing_formats[0])] # Best quality
			elif requested_format == '-1':
				video_url_list = [(f, get_video_template % f) for f in existing_formats] # All formats
				video_url_list = [(requested_format, get_video_template % requested_format)] # Specific format

and now add an elif block as shown below:

			if requested_format is None:
				video_url_list = [(existing_formats[0], get_video_template % existing_formats[0])] # Best quality
			elif requested_format == '-1':
				video_url_list = [(f, get_video_template % f) for f in existing_formats] # All formats
			elif requested_format == '0':
				video_url_list = [(existing_formats[len(existing_formats)-1], get_video_template % existing_formats[len(existing_formats)-1])] # worst quality
				video_url_list = [(requested_format, get_video_template % requested_format)] # Specific format

Now, to download the worst quality version available, you can just pass -f 0 option i.e.

youtube-dl -f 0 "http://www.youtube.com/watch?v=2_VFKqw1q2Q"

This should download the worst quality version and make the download size smaller. However, sometimes worst quality in the list does not mean smallest size (I had seen examples of this while I was doing a youtube downloader project a year ago, but don’t know any examples to point out right now), they should almost always be so.

If the developers want to implement this (the lowest size download feature) in the main project, I think the best way to do it is to actually query header information of the video url and find the actually sizes, compare them and then download the one with the least size.

[SOLVED] Adobe FlashPlugin Problem in Ubuntu 10.04 Lucid Lynx 64bit

I had posted about flash plugin controls not working in Ubuntu 9.10 Karmic Koala 64 bit here. I had moved to Ubuntu 32 bit for quite sometime and recently made a move back to Ubuntu 64 bit. I found the same problem with flash plugin controls in Ubuntu 64 bit. Sometimes it works, and sometimes it doesn’t. I haven’t found any specific patterns to when it does and when it doesn’t. If someone has, please do share.

In my previous post regarding the issue, I had suggested the installation of Adobe flash player 64 bit version from Adobe Labs website. The solution worked fine for me and it seems for most of the others, but the plugin was experimental and when someone needed to update, it was not available via repositories. It has been provided in a launchpad ppa repository currently which can be added by adding ppa:sevenmachines/ppa to Repositories in Synaptic, but it seems it is not updated as of now and the latest version available in the ppa is while Adobe has already released version 10.1rc4. But since the latest version is not recognized by youtube, I think we should stay with the version in the repository.

Simply open up synaptic and navigate to Settings>Repositories>Other Software and click on Add. In the apt-line, enter ppa:sevenmachines/flash and close it. Then Click on the Reload button. Now, search for flashplugin64-installer, mark it for installation and click on apply.

When done, restart firefox and flash should run fine.

Please share your flash player 10 experience in Linux.

[SOLVED]: flashplugin Controls not Working in Ubuntu 9.10 Karmic Koala

Please find the latest post here.

UPDATE Nov 2, 2009: If you want to make flash work normal in 64-bit Ubuntu 9.10 Karmic Koala, the following commands shall help. So start your terminal and get going:

sudo apt-get remove flashplugin-installer flashplugin-nonfree swdec-mozilla mozilla-plugin-gnash
cd /tmp
wget http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-
tar xf libflashplayer-
sudo mv libflashplayer.so /usr/lib/mozilla/plugins/

and restart firefox. If this does not work or you want to keep track of what has happened here, read on.

UPDATE Nov 2, 2009: The problem persisted for me even after I upgraded to the latest version. Using 64-bit flash plugin from Adobe Labs helps for me now. For this you will need to download the latest plugin from http://labs.adobe.com/downloads/flashplayer10.html and extract it to /home/YOUR_USER_NAME/.mozilla/plugins or /usr/lib/mozilla/plugins. If you intend to extract it to /usr/lib/mozilla/plugins then you will need root privileges. One way of getting root privileges is launching nautilus as “gksu nautilus /usr/lib/mozilla/plugins” in the Run Application dialog (Alt+F2). Then copy the extracted libflashplayer.so in that directory and restart Firefox.

UPDATE: I had problems with swfdec-gnome also. When I used to close any tabs with active flash content, firefox would simply crash. I removed it and installed flashplugin via flashplug-installer (in synaptic) and now it is working fine. I disabled some plugins and maybe thats what worked. Not sure. Anyone came up with whats actually happening?

ORIGINAL POST 10 Aug, 2009: I recently installed Karmic Koala (Ubuntu 9.10) alpha 4 amd64 version and have been facing problem with flashplugin for Firefox 3.5. The flashplugin is a large download (as it depends on 32 bit libraries.. they have 32 bit version of the plugin now in amd64 too) and does not work well with YouTube videos, the flash applications do not respond user clicks. I have removed flashplugin via Synaptic Package Manager and installed swfdec-mozilla instead (firefox restart required after you do). This one has worked fine for me till now.

Hope this was helpful. Hope this is solved in the stable release.

Thanks to “Fatal Toenail Infection”.

[HOWTO]Install Google Chrome in your Ubuntu 9.04 Jaunty Jackalope and Enable Flash on It

I have Ubuntu 9.04 Jaunty Jackalope 64bit and wanted to give Google Chrome Browser a try to see what it feels like to be running Google Chrome OS (which will be based on Linux and run Google  Chrome Browser).

UPDATE Nov 21: Just adding the repository:
deb http://dl.google.com/linux/deb/ stable main
will let you install Google Chrome right from Synaptic.

UPDATE: Now I have Ubuntu Karmic Koala (9.10) alpha 4 and same works for Karmic too.