]> code.delx.au - webdl/blobdiff - iview.py
Handle URLs without scheme, fixes SBS issue #27
[webdl] / iview.py
index cfe5ec4a9ceab6e08eeac0a8e915e560155db4c6..03f730bf65ac0b6613a33c22c4820b687b661af4 100644 (file)
--- a/iview.py
+++ b/iview.py
@@ -1,5 +1,5 @@
 from common import grab_json, grab_xml, Node, download_hls
-import urlparse
+import urllib.parse
 
 API_URL = "http://iview.abc.net.au/api"
 AUTH_URL = "http://iview.abc.net.au/auth"
@@ -14,7 +14,7 @@ class IviewEpisodeNode(Node):
     def __init__(self, title, parent, video_key):
         Node.__init__(self, title, parent)
         self.video_key = video_key
-        self.filename = title + ".mp4"
+        self.filename = title + ".ts"
         self.can_download = True
 
     def find_hls_url(self, playlist):
@@ -30,21 +30,21 @@ class IviewEpisodeNode(Node):
         }
         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)
         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)
-        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):