]> git.frykholm.com Git - svtplaydump.git/blame_incremental - svtplaydump.py
Initial upload.
[svtplaydump.git] / svtplaydump.py
... / ...
CommitLineData
1#!/usr/bin/env python
2#
3# (C) Copyright 2010 Mikael Frykholm <mikael@frykholm.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>
17#
18# Changelog:
19# 0.2 added python 2.4 urlparse compatibility
20# 0.1 initial release
21
22from BeautifulSoup import BeautifulSoup
23from subprocess import *
24try:
25 import urlparse
26except ImportError:
27 pass
28import urllib2
29try:
30 import urllib2.urlparse as urlparse
31except ImportError:
32 pass
33import sys
34
35def main(argv=None):
36 if argv is None:
37 argv=sys.argv
38 soup = BeautifulSoup(urllib2.urlopen(argv[1]).read())
39 flashvars = urlparse.parse_qs(soup.find("param", {"name":"flashvars",'value':True})['value'])
40 title = None
41 try:
42 title = soup.find("div","info").ul.li.h2.string
43 except:
44 title = "unnamed"
45 if 'dynamicStreams' in flashvars:
46 url = flashvars['dynamicStreams'][0].split('url:')[1].split('.mp4,')[0] +'.mp4'
47 filename = title+".mp4"
48 print Popen(["rtmpdump",u"-o"+filename,"-r", url], stdout=PIPE).communicate()[0]
49 if 'pathflv' in flashvars:
50 rtmp = flashvars['pathflv'][0]
51 filename = title+".flv"
52 print Popen(["mplayer","-dumpstream","-dumpfile",filename, rtmp], stdout=PIPE).communicate()[0]
53 else:
54 print "Could not find any streams"
55 return
56
57if __name__ == "__main__":
58 sys.exit(main())