]> code.delx.au - webdl/blob - iview.py
Don't redownload iView episodes tagged with (final)
[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 from datetime import datetime
6
7 BASE_URL = "http://www.abc.net.au/iview/"
8 CONFIG_URL = BASE_URL + "xml/config.xml"
9 HASH_URL = BASE_URL + "images/iview.jpg"
10 NS = {
11 "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
12 }
13
14 class IviewNode(Node):
15 def __init__(self, title, parent, vpath):
16 Node.__init__(self, title, parent)
17 self.vpath = vpath
18 self.can_download = True
19
20 def download(self):
21 auth_doc = grab_xml(PARAMS["auth"], 0)
22 vbase = auth_doc.xpath("//auth:server/text()", namespaces=NS)[0]
23 token = auth_doc.xpath("//auth:token/text()", namespaces=NS)[0]
24 vbase += "?auth=" + token
25 vpath, ext = self.vpath.rsplit(".", 1)
26 vpath = ext + ":" + vpath
27 filename = self.title + "." + ext
28 return download_rtmp(filename, vbase, vpath, HASH_URL)
29
30
31 class IviewSeries(Node):
32 def __init__(self, series_title, series_id, parent):
33 Node.__init__(self, series_title, parent)
34 self.series_title = series_title
35 self.series_id = series_id
36
37 def fill_children(self):
38 series_doc = grab_json(PARAMS["api"] + "series=" + self.series_id, 3600)[0]
39 for episode in series_doc["f"]:
40 vpath = episode["n"]
41 episode_title = episode["b"].strip()
42 if not episode_title.startswith(self.series_title):
43 episode_title = self.series_title + " " + episode_title
44 if episode_title.lower().endswith(" (final)"):
45 episode_title = episode_title[:-8]
46 IviewNode(episode_title, self, vpath)
47
48
49
50 def fill_nodes(root_node):
51 root_node = Node("ABC iView", root_node)
52
53 config_doc = grab_xml(CONFIG_URL, 24*3600)
54 global PARAMS
55 PARAMS = dict((p.attrib["name"], p.attrib["value"]) for p in config_doc.xpath("/config/param"))
56
57 categories_doc = grab_xml(BASE_URL + PARAMS["categories"], 24*3600)
58 categories_map = {}
59 for category in categories_doc.xpath("//category[@genre='true']"):
60 cid = category.attrib["id"]
61 category_name = category.xpath("name/text()")[0]
62 category_node = Node(category_name, root_node)
63 categories_map[cid] = category_node
64
65 # Create a duplicate of each series within each category that it appears
66 series_list_doc = grab_json(PARAMS["api"] + "seriesIndex", 3600)
67 for series in series_list_doc:
68 categories = series["e"].split()
69 sid = series["a"]
70
71 series_title = series["b"].replace("&", "&")
72 for cid in categories:
73 category_node = categories_map.get(cid, None)
74 if category_node:
75 IviewSeries(series_title, sid, category_node)
76