Download Stage6 videos using Python

December 5, 2007

Submitted by: Taoufix

Category: Computers

138 views

Here is a quick and dirty python script to download Stage6 videos.

#!/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)

To use it:

$ ./stage6.py http://www.stage6.com/user/Rudimc/video/1907059/Iaido---Batto---Takeda-Ryu-Tameshigiri
If you liked this, please share it at your favorite sites:
  • Digg
  • Reddit
  • del.icio.us
  • Wikio
  • Facebook
  • Google
  • Technorati
  • TwitThis
  • MySpace
  • N4G
  • NewsVine
  • StumbleUpon
  • BlogMemes
  • Blogsvine
  • blogtercimlap
  • description
  • eKudos
  • Faves
  • Fleck
  • Scoopeo
  • Socialogs
  • Upnews
  • Yigg
  • E-mail this story to a friend!
  • Mixx

4 Responses :D Pretty Cool

Leave a Reply

:D :) :cry: :( 8O :twisted: :!: :vangry: :XO: :up: ;) :mrgreen: :halo: :kiss: :roll: :? 8) :evil: :oops: :| :?: :x :$: more »