]>
code.delx.au - webdl/blob - iview.py
2 # vim:ts=4:sts=4:sw=4:noet
4 from common
import grab_xml
, grab_json
, download_rtmp
, Node
5 from datetime
import datetime
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"
11 "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
14 class IviewNode(Node
):
15 def __init__(self
, title
, parent
, params
, vpath
):
16 Node
.__init
__(self
, title
, parent
)
19 self
.can_download
= True
22 auth_doc
= grab_xml(self
.params
["auth"], 0)
23 vbase
= auth_doc
.xpath("//auth:server/text()", namespaces
=NS
)[0]
24 token
= auth_doc
.xpath("//auth:token/text()", namespaces
=NS
)[0]
25 vbase
+= "?auth=" + token
26 vpath
, ext
= self
.vpath
.rsplit(".", 1)
27 vpath
= ext
+ ":" + vpath
28 filename
= self
.title
+ "." + ext
29 return download_rtmp(filename
, vbase
, vpath
, HASH_URL
)
32 class IviewSeriesNode(Node
):
33 def __init__(self
, title
, parent
, params
, series_id
):
34 Node
.__init
__(self
, title
, parent
)
36 self
.series_id
= series_id
38 def fill_children(self
):
39 series_doc
= grab_json(self
.params
["api"] + "series=" + self
.series_id
, 3600)
42 for episode
in series_doc
[0]["f"]:
44 episode_title
= episode
["b"].strip()
45 if not episode_title
.startswith(self
.title
):
46 episode_title
= self
.title
+ " " + episode_title
47 if episode_title
.lower().endswith(" (final)"):
48 episode_title
= episode_title
[:-8]
49 IviewNode(episode_title
, self
, self
.params
, vpath
)
51 class IviewRootNode(Node
):
52 def __init__(self
, parent
):
53 Node
.__init
__(self
, "ABC iView", parent
)
55 def fill_children(self
):
56 config_doc
= grab_xml(CONFIG_URL
, 24*3600)
57 params
= dict((p
.attrib
["name"], p
.attrib
["value"]) for p
in config_doc
.xpath("/config/param"))
59 categories_doc
= grab_xml(BASE_URL
+ params
["categories"], 24*3600)
61 for category
in categories_doc
.xpath("//category[@genre='true']"):
62 cid
= category
.attrib
["id"]
63 category_name
= category
.xpath("name/text()")[0]
64 category_node
= Node(category_name
, self
)
65 categories_map
[cid
] = category_node
67 # Create a duplicate of each series within each category that it appears
68 series_list_doc
= grab_json(params
["api"] + "seriesIndex", 3600)
69 for series
in series_list_doc
:
70 categories
= series
["e"].split()
73 series_title
= series
["b"].replace("&", "&")
74 for cid
in categories
:
75 category_node
= categories_map
.get(cid
, None)
77 IviewSeriesNode(series_title
, category_node
, params
, sid
)
81 def fill_nodes(root_node
):
82 IviewRootNode(root_node
)