Download multiple youtube videos + Linux Python code

For those of you who like downloading videos from, I made a simple Python code so you guys can download as many as you like at the same time.

For those of you who don’t know how to download videos from yet,here’s a simple guide:

In’s page, copy the url of the video you want to download, shown here encircled in red, for example:


Then create a text file in this format:

<youtube video url 1>,<filename1>

<youtube video url 2>,<filename2>

for example:,mgs3 full story part1,mgs3 full story part2

Place all the video urls you want to download at the same time (including the filename of the videos) in that text file. Remember to press the Return (Enter) button after every url/filename line on the text file. The video url and video filename you want for the file should be separated only by a single comma. The white spaces in the video filename you’ll give will be transformed into underscores (e.g. “video 1 part – 1” becomes “video_1_part_-_1”).

To run the program I made type

 ./  --file=<text file with youtube video url>

Anyway, there’s a help message included.

The code also assumes you have youtube-dl (found here) code in your $PATH. Copy/download the youtube-dl code and save it on your PC. You can just do a

 chmod 775 youtube-dl

to make the code executable. Then copy it to, say, your bin folder (which is in your $PATH by default):

 cp -v youtube-dl /usr/bin

Here’s the code:

	import commands, os, sys, string, getopt
except ImportError, msg1:

	options, xarguments = getopt.getopt(sys.argv[1:],'h', ['file=','version'])
except getopt.error:
	print "Error: You tried to use an unknown option or the argument for an option that requires it was missing. Try ` -h' for more information."

def isempty(self) :
    return (len(self) == 0) 

def help_message():
	print '''This program assumes youtube-dl is in $PATH. You basically create a text file containing all the youtube videos that you want to download in this format:
	The title and the link must be separated by a single comma only, as seen from the example above.
	-h		displays this help message
	--file=		give the text file containing the formatted ,
	--version	displays Python version

def youtubedl(dl_list):
#change my_proxy to whatever proxy you want to use. If you don't want any, just delete the line after this.
		os.system("export http_proxy=my_proxy")
		file = open(dl_list,"r")
		lines = file.readlines()
		for x in lines:
			lnknme = x.split(",")
			namae = lnknme[1][:-1].replace(' ',"_")
#replace username and passwd with your youtube username and password. If you don't have any, just remove this part: '-u username -p passwd'
			os.system("youtube-dl -u username -p passwd -o "+namae+".flv "+lnknme[0])
			print namae
	except ValueError, msg:

if isempty(options):

for a in options[:]:
    if a[0] == '-h':

for a in options[:]:
	if a[0] == '--file' and a[1] != '':
	elif a[0] == '--file' and a[1] == '':
		print '--file expects an argument'

for a in options[:]:
    if a[0] == '--version':
        print ' version 1.0'

If you have comments/suggestion/questions, please feel free to post and ask them.

You can download the source code as an odt file here=>dl-youtube.odt

Remember to save it as a text file with a .py extension for the Python interpreter. Unfortunately, WordPress only accepts jpg, jpeg, png, gif, pdf, doc, ppt, and odt for file uploads so I wasn’t able to upload the code. Just be sure to remember that indention is very important to Python.

Or better yet, if you don’t want to download the source code, you can view this page’s source code (in Firefox, right-click page then click View Page Source) and just copy the original and correct code with proper indentions, to a text editor, and save it with a .py extension.


Tags: , , ,

9 Responses to “Download multiple youtube videos + Linux Python code”

  1. Bluebeetle(one) Says:


    How long have spent writing your Python script?

    I’m currently testing an open source software named Miro, previously called Democracy Player.

    It allows researches & of course also downloads from:
    – YouTube
    – DailyMotion
    – Google video
    – & a few more I don’t even heard about before.


  2. f241vc15 Says:

    Hi Bluebeetle,
    I actually wrote the whole Python script in less than an hour. It’s just actually a combination of my hobbies (programming + watching/downloading videos) so I don’t really get bothered.
    Anyhow, I have heard/read about Democracy before, but I didn’t know it’s been changed to Miro.
    I would think that it is a great addition to one’s collection of software for playing/getting videos.
    But if you only have python and would like to get downloading from youtube done with, my good old code would fit nicely (^)__(^) Like what I used to say, I guess I’m just a bit old-fashioned, always getting away with things in the command line.
    Anyway, I haven’t checked how Miro does it. Any idea?

  3. youtube download script update « F241vc15′ Weblog Says:

    […] download script update Actually, there’s no real update at my older post regarding the python script I created for automatically downloading multiple youtube videos. And there’s also nothing wrong with it. Problem is, I tried downloading videos last week and […]

  4. Mr.Legend Says:

    I use to download and save youtube videos
    Here you can also search, watch and download youtue videos.
    All in One 🙂

  5. f241vc15 Says:

    Wow that’s great 🙂 will check it out asap. Do they also let you queue up video downloads so you won’t have to wait for every single video to load, just like in my python program?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: