]>
code.delx.au - monosys/blob - ripping/iview-downloader
e8d2ba032b78bfe9b707ba2d6d98e6137eb5e0ea
9 BASE_URL
= "http://www.abc.net.au/iview/"
10 CONFIG_URL
= BASE_URL
+ "xml/config.xml"
11 HASH_URL
= BASE_URL
+ "images/iview.jpg"
13 "auth": "http://www.abc.net.au/iView/Services/iViewHandshaker",
17 f
= urllib
.urlopen(path
)
23 f
= urllib
.urlopen(path
)
28 def choose(options
, allow_multi
):
29 skeys
= sorted(options
.keys())
30 for i
, key
in enumerate(skeys
):
31 print " %d) %s" % (i
+1, key
)
35 values
= map(int, raw_input("Choose> ").split())
40 values
= [options
[skeys
[value
-1]] for value
in values
]
49 def download_rtmp(filename
, vbase
, vpath
):
58 p
= subprocess
.Popen(cmd
)
60 except KeyboardInterrupt:
61 print "Cancelled", cmd
65 except KeyboardInterrupt:
66 p
.send_signal(signal
.SIGKILL
)
69 def download_video(title
, vpath
):
70 auth_doc
= grab_xml(PARAMS
["auth"])
71 vbase
= auth_doc
.xpath("//auth:server/text()", namespaces
=NS
)[0]
72 token
= auth_doc
.xpath("//auth:token/text()", namespaces
=NS
)[0]
73 vbase
+= "?auth=" + token
74 vpath
, ext
= vpath
.rsplit(".", 1)
75 vpath
= ext
+ ":" + vpath
76 filename
= title
+ "." + ext
77 download_rtmp(filename
, vbase
, vpath
)
80 categories_doc
= grab_xml(BASE_URL
+ PARAMS
["categories"])
82 for category
in categories_doc
.xpath("//category[@genre='true']"):
83 cid
= category
.attrib
["id"]
84 name
= category
.xpath("name/text()")[0]
85 categories
[name
] = cid
88 def get_episodes(cid
):
89 series_list_doc
= grab_json(PARAMS
["api"] + "seriesIndex")
91 for series
in series_list_doc
:
92 categories
= series
["e"].split()
93 if cid
not in categories
:
96 series_title
= series
["b"].replace("&", "&")
97 series_doc
= grab_json(PARAMS
["api"] + "series=" + sid
)[0]
98 for episode
in series_doc
["f"]:
100 episode_title
= episode
["b"].strip()
101 if series_title
!= episode_title
:
102 episode_title
= series_title
+ " " + episode_title
103 episode_list
[episode_title
] = (episode_title
, vpath
)
109 config_doc
= grab_xml(CONFIG_URL
)
111 PARAMS
= dict((p
.attrib
["name"], p
.attrib
["value"]) for p
in config_doc
.xpath("/config/param"))
114 cid
= choose(get_categories(), allow_multi
=False)
118 generator
= choose(get_episodes(cid
), allow_multi
=True)
119 if generator
is None:
121 for title
, vpath
in generator
:
122 download_video(title
, vpath
)
124 if __name__
== "__main__":
127 except (KeyboardInterrupt, EOFError):