-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
videolectures.net video downloader Version 0.1
- Loading branch information
0 parents
commit 02fefe5
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|