]> code.delx.au - webdl/commitdiff
Download SBS player params from the API
authorPaul Wise <pabs3@bonedaddy.net>
Mon, 16 Aug 2021 14:03:58 +0000 (22:03 +0800)
committerPaul Wise <pabs3@bonedaddy.net>
Mon, 16 Aug 2021 14:03:58 +0000 (22:03 +0800)
The SBS embedded player params do not seem to be present any more.

Approach-from: youtube-dl
Fixes: https://bitbucket.org/delx/webdl/issues/119/sbs-not-finding-player-params
sbs.py

diff --git a/sbs.py b/sbs.py
index c3cbe528086e947dc3dc0934e2895b95ff6a1e36..deac6eb0de5d13716bf5dde0c8b934946063c99f 100644 (file)
--- a/sbs.py
+++ b/sbs.py
@@ -9,6 +9,7 @@ import sys
 BASE = "https://www.sbs.com.au"
 FULL_VIDEO_LIST = BASE + "/api/video_feed/f/Bgtm9B/sbs-section-programs/"
 VIDEO_URL = BASE + "/ondemand/video/single/%s"
+PARAMS_URL = BASE + "/api/video_pdkvars/id/%s?form=json"
 
 NS = {
     "smil": "http://www.w3.org/2005/SMIL21/Language",
@@ -24,7 +25,7 @@ class SbsVideoNode(Node):
     def download(self):
         with requests_cache.disabled():
             doc = grab_html(VIDEO_URL % self.video_id)
-        player_params = self.get_player_params(doc)
+        player_params = grab_json(PARAMS_URL % self.video_id)
 
         error = player_params.get("error", None)
         if error:
@@ -40,19 +41,6 @@ class SbsVideoNode(Node):
         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("https:" + release_url.replace("http:", "").replace("https:", ""))