From deae9055ca9e3b210fc4c20e279873d2eaaaaab7 Mon Sep 17 00:00:00 2001 From: techmetx11 Date: Thu, 25 Jul 2024 14:26:20 +0100 Subject: [PATCH] Emergency fix --- src/consts.rs | 8 +++++++- src/player.rs | 47 +++++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/consts.rs b/src/consts.rs index b8f51b9..eb540ff 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -8,8 +8,14 @@ pub static TEST_YOUTUBE_VIDEO: &str = "https://www.youtube.com/watch?v=jNQXAC9IV pub static REGEX_PLAYER_ID: &Lazy = regex!("\\/s\\/player\\/([0-9a-f]{8})"); pub static NSIG_FUNCTION_ARRAY: &Lazy = regex!( - r#"(?x)(?:\.get\("n"\)\)&&\(b=|b=String\.fromCharCode\(110\),c=a\.get\(b\)\)&&\(c=)(?P[a-zA-Z0-9$]+)(?:\[(?P\d+)\])?\([a-zA-Z0-9]\)"# + r#"(?x)&&\(b="n+"\[[a-zA-Z0-9.+$]+\],c=a\.get\(b\)\)&&\(c=(?P[a-zA-Z0-9$]+)(?:\[(?P\d+)\])?\([a-zA-Z0-9]\)"# ); + +pub static NSIG_FUNCTION_ENDINGS: &[&str] = &[ + "=\\s*function([\\S\\s]*?\\}\\s*return \\w+?\\.join\\(\"\"\\)\\s*\\};)", + "=\\s*function([\\S\\s]*?\\}\\s*return [\\W\\w$]+?\\.call\\([\\w$]+?,\"\"\\)\\s*\\};)", +]; + pub static REGEX_SIGNATURE_TIMESTAMP: &Lazy = regex!("signatureTimestamp[=:](\\d+)"); pub static REGEX_SIGNATURE_FUNCTION: &Lazy = diff --git a/src/player.rs b/src/player.rs index 7d54565..4255352 100644 --- a/src/player.rs +++ b/src/player.rs @@ -4,8 +4,8 @@ use regex::Regex; use crate::{ consts::{ - NSIG_FUNCTION_ARRAY, NSIG_FUNCTION_NAME, REGEX_HELPER_OBJ_NAME, REGEX_PLAYER_ID, - REGEX_SIGNATURE_FUNCTION, REGEX_SIGNATURE_TIMESTAMP, TEST_YOUTUBE_VIDEO, + NSIG_FUNCTION_ARRAY, NSIG_FUNCTION_ENDINGS, NSIG_FUNCTION_NAME, REGEX_HELPER_OBJ_NAME, + REGEX_PLAYER_ID, REGEX_SIGNATURE_FUNCTION, REGEX_SIGNATURE_TIMESTAMP, TEST_YOUTUBE_VIDEO, }, jobs::GlobalState, }; @@ -93,23 +93,38 @@ pub async fn fetch_update(state: Arc) -> Result<(), FetchUpdateStat let nsig_function_name = array_values.get(nsig_array_value).unwrap(); - // Extract nsig function code - let mut nsig_function_code_regex_str: String = String::new(); - nsig_function_code_regex_str += &nsig_function_name.replace("$", "\\$"); - nsig_function_code_regex_str += - "=\\s*function([\\S\\s]*?\\}\\s*return [\\W\\w$]+?\\.call\\([\\w$]+?,\"\"\\)\\s*\\};)"; - - let nsig_function_code_regex = Regex::new(&nsig_function_code_regex_str).unwrap(); - let mut nsig_function_code = String::new(); nsig_function_code += "function "; nsig_function_code += NSIG_FUNCTION_NAME; - nsig_function_code += nsig_function_code_regex - .captures(&player_javascript) - .unwrap() - .get(1) - .unwrap() - .as_str(); + + let mut extracted = false; + // Extract nsig function code + for (index, ending) in NSIG_FUNCTION_ENDINGS.iter().enumerate() { + let mut nsig_function_code_regex_str: String = String::new(); + nsig_function_code_regex_str += &nsig_function_name.replace("$", "\\$"); + nsig_function_code_regex_str += ending; + + let nsig_function_code_regex = Regex::new(&nsig_function_code_regex_str).unwrap(); + nsig_function_code += match nsig_function_code_regex.captures(&player_javascript) { + None => { + println!("nsig function ending did not work: {}", ending); + if index == NSIG_FUNCTION_ENDINGS.len() { + println!("!!ERROR!! nsig function unable to be extracted"); + return Err(FetchUpdateStatus::NsigRegexCompileFailed); + } + + continue; + } + Some(i) => { + extracted = true; + i.get(1).unwrap().as_str() + } + }; + + if extracted { + break; + } + } // Extract signature function name let sig_function_name = REGEX_SIGNATURE_FUNCTION