For those of you who like downloading videos from youtube.com, 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 youtube.com yet,here’s a simple guide:
In youtube.com’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:
http://youtube.com/watch?v=skwY-Uij19U,mgs3 full story part1
http://youtube.com/watch?v=9thb0F98OOg,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
./dl-youtube.py --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:
#!/usr/bin/python
try:
import commands, os, sys, string, getopt
except ImportError, msg1:
exit(msg1)
try:
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 `dl-youtube.py -h' for more information."
sys.exit(0)
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:
,video_title
e.g.
The title and the link must be separated by a single comma only, as seen from the example above.
Options:
-h displays this help message
--file= give the text file containing the formatted ,
--version displays Python version
'''
sys.exit(0)
def youtubedl(dl_list):
try:
#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:
exit(msg)
file.close()
if isempty(options):
help_message()
for a in options[:]:
if a[0] == '-h':
help_message()
for a in options[:]:
if a[0] == '--file' and a[1] != '':
youtubedl(a[1])
options.remove(a)
break
elif a[0] == '--file' and a[1] == '':
print '--file expects an argument'
sys.exit(0)
for a in options[:]:
if a[0] == '--version':
print 'dl-youtube.py version 1.0'
sys.exit(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 dl-youtube.py 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: download youtube, python, youtube, youtube-dl

July 26, 2008 at 7:21 pm |
I browse and saw you website and I found it very interesting.Thank you for the good work, greetings
July 26, 2008 at 7:23 pm |
Thanks Timmy.
I have a lot of interests and the ones that manifest them mostly here in my weblog is Linux, computing, and philosophy/critical thinking.
September 15, 2008 at 8:56 pm |
thanks for this page!
October 22, 2009 at 8:17 pm |
wow awesome method .
Till now I was using http://www.tubeleecher.com