]>
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
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
.filename
= self
.title
+ "." + vpath
.rsplit(".", 1)[1]
20 self
.can_download
= True
23 auth_doc
= grab_xml(self
.params
["auth"], 0)
24 server
= self
.params
["server_streaming"]
25 token
= auth_doc
.xpath("//auth:token/text()", namespaces
=NS
)[0]
26 playpath
= auth_doc
.xpath("//auth:path/text()", namespaces
=NS
)[0]
27 if playpath
== "playback/_definst_/":
28 playpath
= "flash/" + playpath
29 vbase
= server
+ "?auth=" + token
30 vpath
, ext
= self
.vpath
.rsplit(".", 1)
31 vpath
= ext
+ ":" + playpath
+ vpath
32 return download_rtmp(self
.filename
, vbase
, vpath
, HASH_URL
)
34 class IviewSeriesNode(Node
):
35 def __init__(self
, title
, parent
, params
, series_id
):
36 Node
.__init
__(self
, title
, parent
)
38 self
.series_id
= series_id
40 def fill_children(self
):
41 series_doc
= grab_json(self
.params
["api"] + "series=" + self
.series_id
, 3600)
44 for episode
in series_doc
[0]["f"]:
46 episode_title
= episode
["b"].strip()
47 if not episode_title
.startswith(self
.title
):
48 episode_title
= self
.title
+ " " + episode_title
49 if episode_title
.lower().endswith(" (final)"):
50 episode_title
= episode_title
[:-8]
51 IviewNode(episode_title
, self
, self
.params
, vpath
)
53 class SeriesInfo(object):
54 def __init__(self
, title
, sid
, categories
):
57 self
.categories
= categories
59 class IviewRootNode(Node
):
60 def __init__(self
, parent
):
61 Node
.__init
__(self
, "ABC iView", parent
)
64 self
.categories_map
= {}
66 def load_params(self
):
67 config_doc
= grab_xml(CONFIG_URL
, 24*3600)
68 for p
in config_doc
.xpath("/config/param"):
69 key
= p
.attrib
["name"]
70 value
= p
.attrib
["value"]
71 self
.params
[key
] = value
73 def load_series(self
):
74 series_list_doc
= grab_json(self
.params
["api"] + "seriesIndex", 3600)
75 for series
in series_list_doc
:
76 title
= series
["b"].replace("&", "&")
78 categories
= series
["e"].split()
79 info
= SeriesInfo(title
, sid
, categories
)
80 self
.series_info
.append(info
)
82 def load_categories(self
):
83 categories_doc
= grab_xml(BASE_URL
+ self
.params
["categories"], 24*3600)
84 by_channel
= Node("By Channel", self
)
85 by_genre
= Node("By Genre", self
)
86 for category
in categories_doc
.xpath("//category"):
87 cid
= category
.attrib
["id"]
88 category_name
= category
.xpath("name/text()")[0]
89 if "genre" in category
.attrib
:
91 elif cid
in ["abc1", "abc2", "abc3", "abc4", "original"]:
93 elif cid
in ["featured", "recent", "last-chance", "trailers"]:
97 node
= Node(category_name
, parent
)
98 self
.categories_map
[cid
] = node
100 def link_series(self
):
101 # Create a duplicate within each category for each series
102 for s
in self
.series_info
:
103 for cid
in s
.categories
:
104 parent
= self
.categories_map
.get(cid
)
106 IviewSeriesNode(s
.title
, parent
, self
.params
, s
.sid
)
108 def fill_children(self
):
111 self
.load_categories()
115 def fill_nodes(root_node
):
116 IviewRootNode(root_node
)