- 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)
+ with requests_cache.disabled():
+ doc = grab_html(VIDEO_URL % self.video_id)
+ player_params = self.get_player_params(doc)
+ release_url = player_params["releaseUrls"]["html"]
+
+ filename = self.title + ".ts"
+
+ hls_url = self.get_hls_url(release_url)
+ if hls_url:
+ return download_hls(filename, hls_url)
+ else:
+ return download_mpd(filename, release_url)
+
+ def get_player_params(self, doc):
+ for script in doc.xpath("//script"):
+ if not script.text:
+ continue
+ for line in script.text.split("\n"):
+ s = "var playerParams = {"
+ if s in line:
+ p1 = line.find(s) + len(s) - 1
+ p2 = line.find("};", p1) + 1
+ if p1 >= 0 and p2 > 0:
+ return json.loads(line[p1:p2])
+ raise Exception("Unable to find player params for %s: %s" % (self.video_id, self.title))
+
+ def get_hls_url(self, release_url):
+ with requests_cache.disabled():
+ doc = grab_xml("http:" + release_url.replace("http:", "").replace("https:", ""))
+ video = doc.xpath("//smil:video", namespaces=NS)
+ if not video:
+ return
+ video_url = video[0].attrib["src"]
+ return video_url