Hello friends, I want to write simple script to download youtube videos, but I have problem... I use One-liner for this, the file is downloaded but it's empty (0 bytes). Can someone help me about my problem ?

Here is my code:

# Author: Abhinay Omkar
# Title: One-liner to download youtube video in Python
from urllib import urlopen, unquote
from urlparse import parse_qs, urlparse

youtube_watchurl = "http://www.youtube.com/watch?v=RsEOXZlYLbo"

video_id = parse_qs(urlparse(youtube_watchurl).query)['v'][0]

open(video_id+'.mp4', 'wb').write(urlopen("http://www.youtube.com/get_video?video_id=%s&t=%s&fmt=18"%(video_id, parse_qs(unquote(urlopen('http://www.youtube.com/get_video_info?&video_id=' + video_id).read().decode('utf-8')))['token'][0])).read())

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.