Skip to content

Commit

Permalink
vl-download
Browse files Browse the repository at this point in the history
videolectures.net video downloader
Version 0.1
  • Loading branch information
mayankjuneja committed Dec 19, 2011
0 parents commit 02fefe5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
============================================
vl-download
Version 0.1
videolectures.net video-download
Mayank Juneja
mayankjuneja1[AT]gmail[DOT]com
============================================

PREREQUISITES:
Python (>=2.7)
BeautifulSoup,optparse (Python Modules)
rtmpdump (http://rtmpdump.mplayerhq.hu/)

RUNNING
vl-download -u URL -o OUTFILE
87 changes: 87 additions & 0 deletions vl-download
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python

######################################################################
#
# vl-download.py : Download videos from videolectures.net
# Author : Mayank Juneja (mayankjuneja1[AT]gmail[DOT]com)
# Version : 0.1
#
######################################################################


import urllib2
import re
import os
import sys
from BeautifulSoup import BeautifulSoup
from optparse import OptionParser

# Script Description
desc = "videolectures.net video downloader"
vers = "0.1"
# Initialize Option Parser
parser = OptionParser(description=desc,version = vers)

# Add options

parser.add_option("-u","--url",
dest="url",
help="videolecture.net URL",
metavar="URL")

parser.add_option("-o","--outfile",
dest="outfile",
help="Output file Name",
metavar="outfile")


# Parse arguments
(options,args) = parser.parse_args()

# Check for some mandatory Options
if options.url is None:
# No URL specified
parser.error("--url option is required")

sys.exit(1)
if options.outfile is None :
# Output file not specified
options.outfile = ""

url = options.url
outfile = options.outfile

request_headers = {
'User-Agent' : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1',
'Accept' : 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'en-us,en;q=0.5',
'Accept-Charset' : 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive' : '300',
'Proxy-Connection' : 'keep-alive',
'Cache-Control' : 'max-age=0'
}


req = urllib2.Request(url, None, request_headers)
response = urllib2.urlopen(req)
html_page = response.read()

html_page = BeautifulSoup(html_page)

## Find the metadata (Author, Title, Date)
metadata = html_page.findAll(id='vl_desc')[0]
title = metadata.findAll('h2')[0].contents[0].encode('ascii','ignore')
author = metadata.findAll("div",{"class":"lec_data"})[0].findAll("a")[0].contents[0].encode('ascii','ignore')

## Find the rtmp data
rtmp_section = html_page.findAll('script')[5].contents[0]
rtmp_path = re.findall('clip.url.*\n',rtmp_section)[0].split("=")[1][2:-3]
rtmp_url = re.findall('clip.netConnectionUrl.*\n',rtmp_section)[0].split("=")[1][2:-3]

## Begin downloading

if(outfile==""):
outfile = author.replace(" ","_") + "-" + title.replace(" ","_")
cmd = ("rtmpdump -r %s -y %s -o \"%s.flv\"")%(rtmp_url, rtmp_path, outfile)
os.system(cmd)

0 comments on commit 02fefe5

Please sign in to comment.