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;"
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"]
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"]