From c758791375331884f94800b59558aed3f5447346 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Tue, 3 Nov 2020 10:37:56 +1100 Subject: [PATCH] Fix for Google changes --- youtube.cgi | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/youtube.cgi b/youtube.cgi index 33bb29a..5c55feb 100755 --- a/youtube.cgi +++ b/youtube.cgi @@ -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"] -- 2.39.2