]> code.delx.au - webdl/blobdiff - iview.py
Improved README
[webdl] / iview.py
index 15b5f43c25a0d9f6c5dc028b041ffac4af2c666d..cd203c2bc27ac096f4e10038ddd799dd7f580921 100644 (file)
--- a/iview.py
+++ b/iview.py
@@ -1,5 +1,6 @@
 from common import grab_json, grab_xml, Node, download_hls
-import urlparse
+import requests_cache
+import urllib.parse
 
 API_URL = "http://iview.abc.net.au/api"
 AUTH_URL = "http://iview.abc.net.au/auth"
@@ -20,31 +21,32 @@ class IviewEpisodeNode(Node):
     def find_hls_url(self, playlist):
         for video in playlist:
             if video["type"] == "program":
-                return video["hls-high"]
+                return video["hls-high"].replace("http:", "https:")
         raise Exception("Missing hls-high program stream for " + self.video_key)
 
     def get_auth_details(self):
-        auth_doc = grab_xml(AUTH_URL, 0)
+        with requests_cache.disabled():
+            auth_doc = grab_xml(AUTH_URL)
         NS = {
             "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
         }
         token = auth_doc.xpath("//auth:tokenhd/text()", namespaces=NS)[0]
         token_url = auth_doc.xpath("//auth:server/text()", namespaces=NS)[0]
-        token_hostname = urlparse.urlparse(token_url).netloc
+        token_hostname = urllib.parse.urlparse(token_url).netloc
         return token, token_hostname
 
-    def hack_url_auth_token(self, video_url, token, token_hostname):
-        parsed_url = urlparse.urlparse(video_url)
+    def add_auth_token_to_url(self, video_url, token, token_hostname):
+        parsed_url = urllib.parse.urlparse(video_url)
         hacked_url = parsed_url._replace(netloc=token_hostname, query="hdnea=" + token)
-        video_url = urlparse.urlunparse(hacked_url)
+        video_url = urllib.parse.urlunparse(hacked_url)
         return video_url
 
     def download(self):
-        info = grab_json(API_URL + "/programs/" + self.video_key, 3600)
+        info = grab_json(API_URL + "/programs/" + self.video_key)
         video_url = self.find_hls_url(info["playlist"])
         token, token_hostname= self.get_auth_details()
-        hack_url = lambda url: self.hack_url_auth_token(url, token, token_hostname)
-        return download_hls(self.filename, video_url, hack_url)
+        video_url = self.add_auth_token_to_url(video_url, token, token_hostname)
+        return download_hls(self.filename, video_url)
 
 
 class IviewIndexNode(Node):
@@ -67,7 +69,7 @@ class IviewIndexNode(Node):
         IviewEpisodeNode(episode_title, series_node, video_key)
 
     def fill_children(self):
-        info = grab_json(self.url, 3600)
+        info = grab_json(self.url)
         for index_list in info["index"]:
             for ep_info in index_list["episodes"]:
                 self.add_episode(ep_info)
@@ -86,7 +88,7 @@ class IviewFlatNode(Node):
         IviewEpisodeNode(episode_title, self, video_key)
 
     def fill_children(self):
-        info = grab_json(self.url, 3600)
+        info = grab_json(self.url)
         for ep_info in info:
             self.add_episode(ep_info)