]>
code.delx.au - webdl/blob - iview.py
1 from common
import grab_xml
, grab_json
, download_rtmp
, Node
4 BASE_URL
= "http://www.abc.net.au/iview/"
5 CONFIG_URL
= BASE_URL
+ "xml/config.xml"
6 HASH_URL
= BASE_URL
+ "images/iview.jpg"
8 "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
11 class IviewNode(Node
):
12 def __init__(self
, title
, parent
, params
, vpath
):
13 Node
.__init
__(self
, title
, parent
)
16 self
.filename
= self
.title
+ "." + vpath
.rsplit(".", 1)[1]
17 self
.can_download
= True
20 auth_doc
= grab_xml(self
.params
["auth"], 0)
21 server
= self
.params
["server_streaming"]
22 token
= auth_doc
.xpath("//auth:token/text()", namespaces
=NS
)[0]
23 playpath
= auth_doc
.xpath("//auth:path/text()", namespaces
=NS
)[0]
24 if playpath
== "playback/_definst_/":
25 playpath
= "flash/" + playpath
26 vbase
= server
+ "?auth=" + token
27 vpath
, ext
= self
.vpath
.rsplit(".", 1)
28 vpath
= ext
+ ":" + playpath
+ vpath
29 return download_rtmp(self
.filename
, vbase
, vpath
, HASH_URL
)
31 class IviewSeriesNode(Node
):
32 def __init__(self
, title
, parent
, params
, series_ids
):
33 Node
.__init
__(self
, title
, parent
)
35 self
.series_ids
= series_ids
37 def fill_children(self
):
38 for series_id
in self
.series_ids
:
39 self
.fill_children_for_id(series_id
)
41 def fill_children_for_id(self
, series_id
):
42 series_doc
= grab_json(self
.params
["api"] + "series=" + series_id
, 3600)
43 for episode_list
in series_doc
:
44 if episode_list
["a"] == series_id
:
45 episode_list
= episode_list
["f"]
50 for episode
in episode_list
:
52 episode_title
= episode
["b"].strip()
53 if not episode_title
.startswith(self
.title
):
54 episode_title
= self
.title
+ " " + episode_title
55 if episode_title
.lower().endswith(" (final)"):
56 episode_title
= episode_title
[:-8]
57 IviewNode(episode_title
, self
, self
.params
, vpath
)
59 class SeriesInfo(object):
60 def __init__(self
, title
):
62 self
.series_ids
= set()
63 self
.categories
= set()
65 def add_series_id(self
, series_id
):
66 self
.series_ids
.add(series_id
)
68 def add_categories(self
, categories
):
69 self
.categories
.update(categories
)
71 class IviewRootNode(Node
):
72 def __init__(self
, parent
):
73 Node
.__init
__(self
, "ABC iView", parent
)
76 self
.categories_map
= {}
78 def load_params(self
):
79 config_doc
= grab_xml(CONFIG_URL
, 24*3600)
80 for p
in config_doc
.xpath("/config/param"):
81 key
= p
.attrib
["name"]
82 value
= p
.attrib
["value"]
83 self
.params
[key
] = value
85 def load_series(self
):
86 series_list_doc
= grab_json(self
.params
["api"] + "seriesIndex", 3600)
87 for series
in series_list_doc
:
88 title
= series
["b"].replace("&", "&")
90 categories
= series
["e"].split()
91 info
= self
.series_info
.get(title
, None)
93 info
= SeriesInfo(title
)
94 self
.series_info
[title
] = info
95 info
.add_categories(categories
)
96 info
.add_series_id(sid
)
98 def load_categories(self
):
99 categories_doc
= grab_xml(BASE_URL
+ self
.params
["categories"], 24*3600)
100 by_channel
= Node("By Channel", self
)
101 by_genre
= Node("By Genre", self
)
102 for category
in categories_doc
.xpath("//category"):
103 cid
= category
.attrib
["id"]
104 category_name
= category
.xpath("name/text()")[0]
105 if "genre" in category
.attrib
:
107 elif cid
in ["abc1", "abc2", "abc3", "abc4", "original"]:
109 elif cid
in ["featured", "recent", "last-chance", "trailers"]:
113 node
= Node(category_name
, parent
)
114 self
.categories_map
[cid
] = node
116 def link_series(self
):
117 # Create a duplicate within each category for each series
118 for s
in self
.series_info
.itervalues():
119 for cid
in s
.categories
:
120 parent
= self
.categories_map
.get(cid
)
122 IviewSeriesNode(s
.title
, parent
, self
.params
, s
.series_ids
)
124 def fill_children(self
):
127 self
.load_categories()
131 def fill_nodes(root_node
):
132 IviewRootNode(root_node
)