Emergency fix

This commit is contained in:
techmetx11 2024-07-25 14:26:20 +01:00
parent e506206971
commit deae9055ca
No known key found for this signature in database
GPG Key ID: E60B63635FF4E062
2 changed files with 38 additions and 17 deletions

View File

@ -8,8 +8,14 @@ pub static TEST_YOUTUBE_VIDEO: &str = "https://www.youtube.com/watch?v=jNQXAC9IV
pub static REGEX_PLAYER_ID: &Lazy<Regex> = regex!("\\/s\\/player\\/([0-9a-f]{8})");
pub static NSIG_FUNCTION_ARRAY: &Lazy<Regex> = regex!(
r#"(?x)(?:\.get\("n"\)\)&&\(b=|b=String\.fromCharCode\(110\),c=a\.get\(b\)\)&&\(c=)(?P<nfunc>[a-zA-Z0-9$]+)(?:\[(?P<idx>\d+)\])?\([a-zA-Z0-9]\)"#
r#"(?x)&&\(b="n+"\[[a-zA-Z0-9.+$]+\],c=a\.get\(b\)\)&&\(c=(?P<nfunc>[a-zA-Z0-9$]+)(?:\[(?P<idx>\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> = regex!("signatureTimestamp[=:](\\d+)");
pub static REGEX_SIGNATURE_FUNCTION: &Lazy<Regex> =

View File

@ -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<GlobalState>) -> 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