Update to newer code on svtplay.
authorMikael Frykholm <mikael@frykholm.com>
Tue, 10 Jul 2012 08:01:09 +0000 (10:01 +0200)
committerMikael Frykholm <mikael@frykholm.com>
Tue, 10 Jul 2012 08:01:09 +0000 (10:01 +0200)
README.md
svtplaydump.py

index 803bd2a92c21d84c34b47718165a94f18f9dcd62..e540726dd3d104d736cc99a0fc96833b7a954656 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
 svtplaydump
 ===========
 
-svtplaydump downloads svtplay content
\ No newline at end of file
+svtplaydump downloads svtplay content for offline viewing.
+Use like this:
+svtplaydump.py http://www.svtplay.se/video/128812/jakten-pa-bernhard
index 00be1b649c0bc3b15e0ed64dcc99ce48096771cf..c61c36e8b05b1cdefff369f75b80c195f0b275f7 100755 (executable)
@@ -21,6 +21,8 @@
 
 from BeautifulSoup import BeautifulSoup
 from subprocess import *
+import re
+import json
 try:
     import urlparse
 except ImportError:
@@ -35,11 +37,13 @@ import sys
 def main(argv=None):
     if argv is None:
         argv=sys.argv
-    soup = BeautifulSoup(urllib2.urlopen(argv[1]).read())
-    flashvars = urlparse.parse_qs(soup.find("param", {"name":"flashvars",'value':True})['value'])
-    title = None
+    videoid = re.findall("/video/(.*)[/]*",argv[1])[0]
+    
+    soup = BeautifulSoup(urllib2.urlopen("http://www.svtplay.se/video/%s/?type=embed"%videoid).read())
+    
+    flashvars = json.loads(soup.find("param", {"name":"flashvars",'value':True})['value'][5:])
     try:
-        title = soup.find("div","info").ul.li.h2.string
+        title = flashvars['statistics']['title']
     except:
         title = "unnamed"
     if 'dynamicStreams' in flashvars:
@@ -50,6 +54,11 @@ def main(argv=None):
         rtmp = flashvars['pathflv'][0]
         filename = title+".flv"
         print Popen(["mplayer","-dumpstream","-dumpfile",filename, rtmp], stdout=PIPE).communicate()[0]
+    if 'video' in flashvars:
+        url = sorted(flashvars['video']['videoReferences'], key=lambda k: k['bitrate'])[-1]['url']
+        filename = title+".mp4"
+        print Popen(["rtmpdump",u"-o"+filename,"-r", url], stdout=PIPE).communicate()[0]
+
     else:
         print "Could not find any streams"
         return