Quick and dirty tv4 downloader
authorMikael Frykholm <mikael@frykholm.com>
Wed, 20 Nov 2013 07:51:39 +0000 (08:51 +0100)
committerMikael Frykholm <mikael@frykholm.com>
Wed, 20 Nov 2013 07:51:39 +0000 (08:51 +0100)
Download stuff from tv4play based on a search expression. Needs
svtplaydump.py.

svtplaydump.py
tv4playdump.py [new file with mode: 0755]

index 05ea3f842d75a6c330eeae214c647d1749c51c35..e9a4a3b9c0d6cf29f57539c01670de268570a64c 100755 (executable)
@@ -198,7 +198,9 @@ def remux(video, xml=None):
     if 'genre' in video:
         if not os.path.exists(video['genre']):
             os.mkdir(video['genre'])
-    video['path'] = os.path.join(video['genre'],basename+'.mkv')
+        video['path'] = os.path.join(video['genre'],basename+'.mkv')
+    else:
+        video['path'] = basename+'.mkv'
     command = ["mkvmerge","-o",video['path'], '--title',video['title']]
 
     if xml:
diff --git a/tv4playdump.py b/tv4playdump.py
new file mode 100755 (executable)
index 0000000..5f20b4a
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+import requests
+import svtplaydump
+import os.path
+def get_hls_playlist(url):
+    ret = requests.get(url).json()
+    #import pdb;pdb.set_trace()
+    videourl = None
+    if isinstance(ret['playback']['items']['item'], list):
+        videourl = sorted(ret['playback']['items']['item'], key=lambda k: int(k['bitrate']))[-1]['url']
+    else:
+        videourl = ret['playback']['items']['item']['url']
+    return videourl
+
+res = requests.get("http://webapi.tv4play.se/video/programs/search.json?categoryids=pokemon&start=0&rows=1000").json()
+videos = []
+#import pdb;pdb.set_trace()
+for vid in res['results']:
+    video = {}
+    video['title'] = vid['name']
+    video['description'] = vid['lead']
+    video['url'] = get_hls_playlist("http://premium.tv4play.se/api/web/asset/{}/play.json?protocol=hls&videoFormat=MP4+WVM+SMI".format(vid['href']))
+    video['filename'] = "{} {}.ts".format(vid['ontime'],vid['name'])
+    videos.append(video)
+    basename = video['filename'].split('.ts')[0]
+    if os.path.exists(basename+'.mkv'):
+        print("Skipping {}".format(basename))
+        continue
+    svtplaydump.download_from_playlist(video)
+    svtplaydump.remux(video)
\ No newline at end of file