diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-02-23 13:58:02 -0800 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-02-23 17:17:06 -0500 |
commit | 31fe1dac55ef95be3291b55d2f652833a032f33d (patch) | |
tree | c94700647f0bafcf0b52998ee69ceaa68bab8f56 | |
parent | 4a8ba594d1b01cb61007dd223cfff35b910b4d97 (diff) | |
download | yt-local-31fe1dac55ef95be3291b55d2f652833a032f33d.tar.lz yt-local-31fe1dac55ef95be3291b55d2f652833a032f33d.tar.xz yt-local-31fe1dac55ef95be3291b55d2f652833a032f33d.zip |
Fix signature decryption due to new base.js minifier rules
YouTube now includes e.g. {"fe": ...} instead of just {fe: ...}
in the javascript object entries in the object holding the
operation definitions.
Fixes #2
Signed-off-by: Jesús <heckyel@hyperbola.info>
-rw-r--r-- | youtube/yt_data_extract/watch_extraction.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/youtube/yt_data_extract/watch_extraction.py b/youtube/yt_data_extract/watch_extraction.py index 2304cce..db53581 100644 --- a/youtube/yt_data_extract/watch_extraction.py +++ b/youtube/yt_data_extract/watch_extraction.py @@ -686,7 +686,9 @@ def requires_decryption(info): # adapted from youtube-dl and invidious: # https://github.com/omarroth/invidious/blob/master/src/invidious/helpers/signatures.cr decrypt_function_re = re.compile(r'function\(a\)\{(a=a\.split\(""\)[^\}{]+)return a\.join\(""\)\}') -op_with_arg_re = re.compile(r'[^\.]+\.([^\(]+)\(a,(\d+)\)') +# gives us e.g. rt, .xK, 5 from rt.xK(a,5) or rt, ["xK"], 5 from rt["xK"](a,5) +# (var, operation, argument) +var_op_arg_re = re.compile(r'(\w+)(\.\w+|\["[^"]+"\])\(a,(\d+)\)') def extract_decryption_function(info, base_js): '''Insert decryption function into info. Return error string if not successful. Decryption function is a list of list[2] of numbers. @@ -700,10 +702,11 @@ def extract_decryption_function(info, base_js): if not function_body: return 'Empty decryption function body' - var_name = get(function_body[0].split('.'), 0) - if var_name is None: + var_with_operation_match = var_op_arg_re.fullmatch(function_body[0]) + if var_with_operation_match is None: return 'Could not find var_name' + var_name = var_with_operation_match.group(1) var_body_match = re.search(r'var ' + re.escape(var_name) + r'=\{(.*?)\};', base_js, flags=re.DOTALL) if var_body_match is None: return 'Could not find var_body' @@ -732,13 +735,13 @@ def extract_decryption_function(info, base_js): decryption_function = [] for op_with_arg in function_body: - match = op_with_arg_re.fullmatch(op_with_arg) + match = var_op_arg_re.fullmatch(op_with_arg) if match is None: return 'Could not parse operation with arg' - op_name = match.group(1) + op_name = match.group(2).strip('[].') if op_name not in operation_definitions: - return 'Unknown op_name: ' + op_name - op_argument = match.group(2) + return 'Unknown op_name: ' + str(op_name) + op_argument = match.group(3) decryption_function.append([operation_definitions[op_name], int(op_argument)]) info['decryption_function'] = decryption_function |