# Youtube Favorites Downloader # By Christopher Genetti (10-5-2009) # # Would you like to automatically download all your favorite videos on youtube to your computer? You are in luck, # because this script will do just that! You need: # # - Python (tested with 2.6, don't know how well it'll work in older or newer versions) - Python.org # - Youtube-dl - http://bitbucket.org/rg3/youtube-dl/ # - Feedparser - http://feedparser.org # # It's only been tested on Mac OS 10.5.8, but should work on anything that runs python and the above two libraries. # # Run this script like so: # # python ytdl.py -u (username) -n (total number of videos to return) -s (number of the video to start at) # # It will then download all videos in the specified user's favorites up to the number provided (starting from the most recent) # into the same folder that ytdl.py is being run from. # # ytdl.py is probably really buggy and inefficient and terrible code. I'm not an expert Python programmer, but I do know # that this script has worked for me! If you have any issues, suggestions, or well-wishings, forward them to genettic@gmail.com, thanks. import feedparser from subprocess import * import optparse import time parser = optparse.OptionParser( usage='Usage: %prog [options] url...', version='INTERNAL', conflict_handler='resolve', ) parser.add_option('-u', '--username', dest='username', metavar='USERNAME', help='username to query') parser.add_option('-n', '--number', dest='number', metavar='NUMBER', help='number of results') parser.add_option('-s', '--start', dest='start', metavar='START', help='the number of the video to start at') (options, args) = parser.parse_args() if options.username is None: print 'You need to specify a username!' exit() start = options.start or 1 start = int(start) max_results = options.number or 25 max_results = int(max_results) while max_results > 0: if max_results > 50: num_results = 50 else: num_results = max_results feed_url = r'http://gdata.youtube.com/feeds/api/users/'+str(options.username)+'/favorites?max-results='+str(num_results)+'&start-index='+str(start)+'&alt=rss' d = feedparser.parse(feed_url) if max_results < 50: max_results = 0 else: max_results = int(max_results) - 50 start = int(start) + 50 for video in d.entries: p = Popen(['youtube-dl', str(video['link']), '-t']) while p.poll() is None: time.sleep(1)