- doc = grab_json(VIDEO_URL % self.video_id, 0)
- best_url = None
- best_bitrate = 0
- for d in doc["media$content"]:
- bitrate = d["plfile$bitrate"]
- if bitrate > best_bitrate or best_url is None:
- best_bitrate = bitrate
- best_url = d["plfile$url"]
-
- doc = grab_xml(best_url, 3600)
- if doc.xpath("//smil:meta/@base", namespaces=NS):
- vbase = doc.xpath("//smil:meta/@base", namespaces=NS)[0]
- vpath = doc.xpath("//smil:video/@src", namespaces=NS)[0]
- ext = vpath.rsplit(".", 1)[1]
- filename = self.title + "." + ext
- return download_rtmp(filename, vbase, vpath)
- else:
- from lxml import etree
- url = doc.xpath("//smil:video/@src", namespaces=NS)[0]
- ext = url.rsplit(".", 1)[1]
- filename = self.title + "." + ext
- url += "?v=2.5.14&fp=MAC%2011,1,102,55&r=FLQDD&g=YNANAXRIYFYO"
- return download_urllib(filename, url)
-
-def fill_entry(get_catnode, entry):
- title = entry["title"]
- video_id = entry["id"]
- info = collections.defaultdict(list)
- for d in entry["media$categories"]:
- if not d.has_key("media$scheme"):
- continue
- info[d["media$scheme"]].append(d["media$name"])
-
- if "Section/Promos" in info.get("Section", []):
- # ignore promos
- return
-
- for category in info.get("Genre", ["$UnknownCategory$"]):
- category = CATEGORY_MAP.get(category, category)
- parent_node = get_catnode(category)
- SbsNode(title, parent_node, video_id)
-
-
-def fill_section(get_catnode, section):
- index = 1
- while True:
- doc = grab_json(BASE + MENU_URL % (section, index), 3600)
+ doc = grab_html(VIDEO_URL % self.video_id, 0)
+ meta_video = doc.xpath("//meta[@property='og:video']")[0]
+ swf_url = meta_video.attrib["content"]
+ swf_url_qs = urlparse.parse_qs(urlparse.urlparse(swf_url).query)
+ desc_url = swf_url_qs["v"][0]
+
+ doc = grab_text(desc_url, 0)
+ doc_qs = urlparse.parse_qs(doc)
+ desc_url = doc_qs["releaseUrl"][0]
+
+ doc = grab_xml(desc_url, 0)
+ error = doc.xpath("//smil:param[@name='exception']/@value", namespaces=NS)
+ if error:
+ raise Exception("Error downloading, SBS said: " + error[0])
+
+ video = doc.xpath("//smil:video", namespaces=NS)[0]
+ video_url = video.attrib["src"]
+ if not video_url:
+ raise Exception("Unsupported video '%s': %s" % (self.title, desc_url))
+ ext = urlparse.urlsplit(video_url).path.rsplit(".", 1)[1]
+ filename = self.title + "." + ext
+ video_url = append_to_qs(video_url, VIDEO_MAGIC)
+ return download_urllib(filename, video_url, referrer=SWF_URL)
+
+class SbsNavNode(Node):
+ def __init__(self, title, parent, url):
+ Node.__init__(self, title, parent)
+ self.url = url
+
+ def fill_children(self):
+ try:
+ doc = grab_json(BASE + self.url, 3600)
+ except ValueError:
+ # SBS sends XML as an error message :\
+ return