]>
code.delx.au - webdl/blob - plus7.py
2 # vim:ts=4:sts=4:sw=4:noet
5 from lxml
.cssselect
import CSSSelector
7 from common
import grab_html
, download_rtmp
, Node
9 METADATA
= "http://cosmos.bcst.yahoo.com/rest/v2/pops;id=%d;lmsoverride=1;element=stream;bw=1200"
10 BASE
= "http://au.tv.yahoo.com"
11 BROWSE
= BASE
+ "/plus7/browse/"
12 HASH_URL
= "http://d.yimg.com/nl/australia/au-tv/player.swf"
13 HASH_URL
= "http://d.yimg.com/m/up/ypp/au/player.swf"
15 class Plus7Node(Node
):
16 def __init__(self
, title
, parent
, url
):
17 Node
.__init
__(self
, title
, parent
)
19 self
.can_download
= True
22 doc
= grab_html(self
.url
, 3600)
23 for script
in doc
.xpath("//script"):
26 for line
in script
.text
.split("\n"):
27 if line
.find("vid : ") <= 0:
29 vid
= line
[line
.find("'")+1 : line
.rfind("'")]
32 raise Exception("Could not find vid on page " + self
.url
)
36 doc
= grab_html(METADATA
% vid
, 0)
37 content
= doc
.xpath("//content")[0]
38 vbase
= content
.attrib
["url"]
39 vpath
= content
.attrib
["path"]
40 filename
= self
.title
+ ".flv"
41 return download_rtmp(filename
, vbase
, vpath
, HASH_URL
)
44 class Plus7Series(Node
):
45 def __init__(self
, title
, parent
, url
):
46 Node
.__init
__(self
, title
, parent
)
49 def fill_children(self
):
50 doc
= grab_html(self
.url
, 3600)
51 for item
in CSSSelector("#related-episodes div.itemdetails")(doc
):
52 title
= CSSSelector("span.title")(item
)[0].text
53 subtitle
= CSSSelector("span.subtitle")(item
)[0].xpath("string()")
54 if subtitle
and subtitle
.strip():
55 title
+= " - " + subtitle
.strip().replace(" ", " ")
56 url
= CSSSelector("a")(item
)[0].attrib
["href"]
57 Plus7Node(title
, self
, BASE
+ url
)
59 class Plus7Root(Node
):
60 def __init__(self
, parent
=None):
61 Node
.__init
__(self
, "Yahoo Plus7", parent
)
63 def fill_children(self
):
64 doc
= grab_html(BROWSE
, 3600)
66 for script
in doc
.xpath("//script"):
67 if not script
.text
or not script
.text
.startswith("var shows = "):
69 shows
= script
.text
[12:]
70 shows
= shows
.rstrip("; \n")
71 shows
= json
.loads(shows
)
73 Plus7Series(show
["title"], self
, show
["url"])
75 def fill_nodes(root_node
):