]> code.delx.au - webdl/blob - iview.py
iView and SBS webdl stuff gets its own project, now it just needs a good name!
[webdl] / iview.py
1 #!/usr/bin/env python
2 # vim:ts=4:sts=4:sw=4:noet
3
4 from common import grab_xml, grab_json, download_rtmp, Node
5
6 BASE_URL = "http://www.abc.net.au/iview/"
7 CONFIG_URL = BASE_URL + "xml/config.xml"
8 HASH_URL = BASE_URL + "images/iview.jpg"
9 NS = {
10 "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
11 }
12
13 class IviewNode(Node):
14 def __init__(self, title, parent, vpath):
15 Node.__init__(self, title, parent)
16 self.vpath = vpath
17 self.can_download = True
18
19 def download(self):
20 auth_doc = grab_xml(PARAMS["auth"])
21 vbase = auth_doc.xpath("//auth:server/text()", namespaces=NS)[0]
22 token = auth_doc.xpath("//auth:token/text()", namespaces=NS)[0]
23 vbase += "?auth=" + token
24 vpath, ext = self.vpath.rsplit(".", 1)
25 vpath = ext + ":" + vpath
26 filename = self.title + "." + ext
27 download_rtmp(filename, vbase, vpath)
28
29
30 def fill_nodes(root_node):
31 config_doc = grab_xml(CONFIG_URL)
32 global PARAMS
33 PARAMS = dict((p.attrib["name"], p.attrib["value"]) for p in config_doc.xpath("/config/param"))
34
35 categories_doc = grab_xml(BASE_URL + PARAMS["categories"])
36 categories_map = {}
37 for category in categories_doc.xpath("//category[@genre='true']"):
38 cid = category.attrib["id"]
39 category_name = category.xpath("name/text()")[0]
40 category_node = Node(category_name, root_node)
41 categories_map[cid] = category_node
42
43 # Create a duplicate of each series within each category that it appears
44 series_list_doc = grab_json(PARAMS["api"] + "seriesIndex")
45 for series in series_list_doc:
46 categories = series["e"].split()
47 sid = series["a"]
48 series_title = series["b"].replace("&", "&")
49 series_nodes = []
50 for cid in categories:
51 category_node = categories_map.get(cid, None)
52 if category_node:
53 series_nodes.append(Node(series_title, category_node))
54 series_doc = grab_json(PARAMS["api"] + "series=" + sid)[0]
55 for episode in series_doc["f"]:
56 vpath = episode["n"]
57 episode_title = episode["b"].strip()
58 if series_title != episode_title:
59 episode_title = series_title + " " + episode_title
60 for series_node in series_nodes:
61 IviewNode(episode_title, series_node, vpath)
62
63