Skip to content

Instantly share code, notes, and snippets.

@rainly
Created August 12, 2012 12:15
Show Gist options
  • Select an option

  • Save rainly/3331632 to your computer and use it in GitHub Desktop.

Select an option

Save rainly/3331632 to your computer and use it in GitHub Desktop.
A simple python script that takes a youku video url or video id as argument and output the video playlist.
#!/usr/bin/env python2
import sys
import urllib
from HTMLParser import HTMLParser
class FlvcdParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "a":
self.inHref = True
attrDict = { attrName: attrValue for attrName, attrValue in attrs }
if 'onclick' in attrDict:
print attrDict['href']
if len(sys.argv) > 1:
if sys.argv[1].startswith("http://"):
youkuUrl = sys.argv[1]
else:
youkuUrl = 'http://v.youku.com/v_show/id_%s.html' % sys.argv[1]
flvcdUrl = 'http://www.flvcd.com/parse.php?kw=%s&format=super' % urllib.quote_plus(youkuUrl)
parser = FlvcdParser()
parser.feed(urllib.urlopen(flvcdUrl ).read())
else:
print "Usage: %s [ videoid | videourl ]" % sys.argv[0]
# Sample usage: ./youku.py "http://v.youku.com/v_show/id_ABCDEFGHI1234.html" | xargs mplayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment