Download Stage6 videos using Python
Posted by Taoufix on Dec 5th, 2007 in Computers
Here is a quick and dirty python script to download Stage6 videos.
[python]#!/usr/bin/env python
# -*- Python -*-
import urllib, sgmllib, sys, string, os, time, re
class MyParser(sgmllib.SGMLParser):
def parse(self, s):
self.feed(s)
self.close()
def __init__(self, verbose=0):
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
self.inside_a_element = 0
def start_input(self, attributes):
found = False
for name, value in attributes:
if name == “onclick”:
found = True
continue
if found == True and name == “value”:
self.hyperlinks.append(value)
self.inside_a_element = 1
def end_input(self):
self.inside_a_element = 0
def get_data(self):
return self.hyperlinks[0]
class AppURLopener(urllib.FancyURLopener):
def __init__(self, *args):
self.version = “Lynx”
urllib.FancyURLopener.__init__(self, *args)
urllib._urlopener = AppURLopener()
try:
url = sys.argv[1]
except IndexError:
print “Usage:”, sys.argv[0], “URL”
sys.exit(1)
f = urllib.urlopen(url)
s = f.read()
myparser = MyParser()
myparser.parse(s)
data = myparser.get_data()
p = re.compile(“.*(http://video.stage6.com/.*/.divx).*”)
try:
m = p.match(data)
video_url = m.group(1)
except AttributeError:
print “Video not found”
sys.exit(1)
def hook(*a):
print ‘%s: %s’ % (fn, a)
fn = os.path.basename(url) + “.avi”
print url, “->”, fn
urllib.urlretrieve(video_url, fn, hook)[/python]
To use it:
[shell]$ ./stage6.py http://www.stage6.com/user/Rudimc/video/1907059/Iaido—Batto—Takeda-Ryu-Tameshigiri[/shell]







Dec 5th