Skip to content

Instantly share code, notes, and snippets.

@weakish
Created May 19, 2011 02:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weakish/980061 to your computer and use it in GitHub Desktop.
Save weakish/980061 to your computer and use it in GitHub Desktop.
Download videos via flvcd.com
#!/usr/bin/env python3.2
# by Jakukyo Friel <weakish@gmail.com> under GPL v2
# Download videos via flvcd.com
# Usage: flvcd url
# TODO:
# - Some sites divide video into clips, we need to support it.
# - flvcd.com may use '...' in the link address displayed. This script fails under this condition.
# Credits
# malic's flvpython http://malic.yo2.cn/articles/flvpython.html
import urllib.parse
import urllib.request
import sys
import re
from subprocess import Popen
# CONFIG
USER_AGENT = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3'
# ENDCONFIG
def PARSE_URL(url):
"""Parse url for the real video address.
url -> (title, actual_url)
"""
para = {'flag' : '', 'format' : '', 'kw' : url}
flvcd = 'http://www.flvcd.com/parse.php?'
req = flvcd + urllib.parse.urlencode(para)
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', USER_AGENT)]
data = opener.open(req).read().decode('gb2312')
title = re.search('document\.title = "([^"]*)"', data).group(1)
link = re.search('>(http://[^<]*)</a>',data).group(1)
return title, link
def FETCH_VIDEO(pair):
"""Download videos."""
title, link = pair
Popen(['wget','-c', link, '-U', USER_AGENT,
'-O', title + '.flv']).wait()
def main():
FETCH_VIDEO(PARSE_URL(sys.argv[1]))
if __name__ == "__main__":
main()
#!/usr/bin/env rc
endnum = $1
playlistid = $2
seq 1 $endnum | xargs -I '{}' flvcd http://www.letv.com/ptv/pplay/$playlistid/'{}'.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment