]> code.delx.au - youtube-cgi/commitdiff
Fix for Google changes
authorJames Bunton <jamesbunton@delx.net.au>
Mon, 2 Nov 2020 23:37:56 +0000 (10:37 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Mon, 2 Nov 2020 23:38:05 +0000 (10:38 +1100)
youtube.cgi

index 33bb29a105d46ae8499b15a23203709816062411..5c55feb3cdbb1abee93da8834685e7b76dd54193 100755 (executable)
@@ -130,15 +130,20 @@ def append_to_qs(url, params):
     return url
 
 def get_player_config(scripts):
-    player_config = None
+    config_strings = [
+        ("ytplayer.config = {", 1, "};", 1),
+        ("ytcfg.set({\"", 2, "});", 1),
+    ]
+    player_config = {}
     for script in scripts:
         for line in script.split("\n"):
-            s = "ytplayer.config = {"
-            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])
+            for s1, off1, s2, off2 in config_strings:
+                if s1 in line:
+                    p1 = line.find(s1) + len(s1) - off1
+                    p2 = line.find(s2, p1) + off2
+                    if p1 >= 0 and p2 > 0:
+                        player_config.update(json.loads(line[p1:p2]))
+    return player_config
 
 def extract_js(script):
     PREFIX = "var _yt_player={};(function(g){var window=this;"
@@ -241,8 +246,6 @@ def decode_cipher_url(js_url, cipher):
     return result_url
 
 def get_best_video(player_config):
-    js_url = player_config["assets"]["js"]
-
     player_args = player_config["args"]
     player_response = json.loads(player_args["player_response"])
     formats = player_response["streamingData"]["formats"]
@@ -266,6 +269,7 @@ def get_best_video(player_config):
             continue
 
         if "signatureCipher" in format_data:
+            js_url = player_config["PLAYER_JS_URL"]
             video_url = decode_cipher_url(js_url, format_data["signatureCipher"])
         else:
             video_url = format_data["url"]