Skip to content

Instantly share code, notes, and snippets.

@abhiomkar
Created May 12, 2010 12:26
Show Gist options
  • Save abhiomkar/398518 to your computer and use it in GitHub Desktop.
Save abhiomkar/398518 to your computer and use it in GitHub Desktop.
# Author: Abhinay Omkar
# Youtube Downloader
import sys
from urllib import urlopen, unquote
from urlparse import parse_qs, urlparse
youtube_watchurl = sys.argv[1]
url_query = urlparse(youtube_watchurl).query
video_id = parse_qs(url_query)['v'][0]
url_data = urlopen('http://www.youtube.com/get_video_info?&video_id=' + video_id).read()
url_info = parse_qs(unquote(url_data.decode('utf-8')))
if url_info['status'][0]=='fail':
print "ERROR: Unable to download this video!"
sys.exit(1)
token_value = url_info['token'][0]
video_title = url_info['title'][0]
download_url = "http://www.youtube.com/get_video?video_id={0}&t={1}&fmt=18".format(video_id, token_value)
print "Downloading: %s..." % video_title
print "It may take something, Please wait..."
filename = video_title+"mp4"
download = urlopen(download_url).read()
f = open(filename, 'wb')
f.write(download)
f.close()
print "Completed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment