#!/usr/bin/env python
# vim:ts=4:sts=4:sw=4:noet
-from common import grab_html, grab_json, grab_xml, download_rtmp, download_urllib, Node, append_to_qs
+from common import grab_text, grab_html, grab_json, grab_xml, download_rtmp, download_urllib, Node, append_to_qs
import collections
import urlparse
def download(self):
doc = grab_html(VIDEO_URL % self.video_id, 0)
- desc_url = None
- for script in doc.xpath("//script", namespaces=NS):
- if not script.text:
- continue
- for line in script.text.split("\n"):
- if line.find("player.releaseUrl") < 0:
- continue
- desc_url = line[line.find("\"")+1 : line.rfind("\"")]
- break
- if desc_url is not None:
- break
- if desc_url is None:
- raise Exception("Failed to get JSON URL for " + self.title)
-
- desc_url = append_to_qs(desc_url, {"manifest": None})
+ 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)
def __init__(self, title, parent, url):
Node.__init__(self, title, parent)
self.url = url
- self.sort_children = True
def fill_children(self):
try:
SbsNode(title, self, video_id)
class SbsRootNode(Node):
- def __init__(self, parent=None):
+ def __init__(self, parent):
Node.__init__(self, "SBS", parent)
def fill_children(self):
return
node = Node(cat_data["name"], parent)
- self.create_nav_node("Featured", node, cat_data, "furl")
- self.create_nav_node("Latest", node, cat_data, "url")
- self.create_nav_node("Most Popular", node, cat_data, "purl")
+ self.create_nav_node("-Featured", node, cat_data, "furl")
+ self.create_nav_node("-Latest", node, cat_data, "url")
+ self.create_nav_node("-Most Popular", node, cat_data, "purl")
children = cat_data.get("children", [])
if isinstance(children, dict):