Skip to content

Commit 3783319

Browse files
committed
yt_data_extract: check js_runtime earlier
Check for js_runtime earlier before constructing decryption js code. Also pretty print the decryption time info using .2f formatting.
1 parent 7d816fd commit 3783319

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

youtube/yt_data_extract/watch_extraction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def replace_n_signatures(info):
929929
parsed_url.fragment]
930930
)
931931
end = time.perf_counter()
932-
print(f"Decrypted nsig for {len(info['formats'])} formats in {end - start } s")
932+
print(f"Decrypted nsig for {len(info['formats'])} formats in {end - start:.2f} s")
933933
return False
934934

935935
def decrypt_signatures(info):
@@ -976,7 +976,7 @@ def decrypt_signatures(info):
976976
urllib.parse.urlencode(query_param_dict),
977977
parsed_url.fragment))
978978
end = time.perf_counter()
979-
print(f"Decrypted signatures for {len(info['formats'])} formats in {end - start} s")
979+
print(f"Decrypted signatures for {len(info['formats'])} formats in {end - start:.2f} s")
980980

981981
return False
982982

@@ -1010,6 +1010,8 @@ def get_js_runtime():
10101010
js_runtime = get_js_runtime()
10111011

10121012
def ejs_decrypt(player_version, nsig, sig=[]):
1013+
if not js_runtime:
1014+
raise NameError("No supported js_runtime is found!\nSupported runtimes: deno, bun, node.")
10131015
player_cache = os.path.join(settings.data_dir, f'iframe_api_base_{player_version}.js')
10141016
processed_cache = os.path.join(settings.data_dir, f'processed_{player_version}.js')
10151017
code_fd, code_tempfile = tempfile.mkstemp(prefix='yt-ejs-', suffix='.js', text=True)
@@ -1045,8 +1047,6 @@ def ejs_decrypt(player_version, nsig, sig=[]):
10451047
'''
10461048
with open(code_tempfile, 'w') as file:
10471049
file.write(jscode)
1048-
if not js_runtime:
1049-
raise NameError("No supported js_runtime is found!\nSupported runtimes: deno, bun, node.")
10501050
result = subprocess.run([js_runtime, code_tempfile], capture_output=True)
10511051
result.check_returncode()
10521052
result_json = json.loads(result.stdout.decode())

0 commit comments

Comments
 (0)