Skip to content

Commit

Permalink
02.08.2024
Browse files Browse the repository at this point in the history
* `extract_ncode` function added another step to extract n code if necessary
  • Loading branch information
Mithronn committed Aug 2, 2024
1 parent dce2dae commit 7606f78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/stream/streams/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,15 @@ impl Stream for LiveStream {

let headers = DEFAULT_HEADERS.clone();

let response = self
let mut response = self
.client
.get(first_segment.0.url().as_str())
.headers(headers)
.send()
.await;

if response.is_err() {
return Err(VideoError::ReqwestMiddleware(response.err().unwrap()));
}

let mut response = response.expect("IMPOSSIBLE");
.await
.map_err(VideoError::ReqwestMiddleware)?
.error_for_status()
.map_err(VideoError::Reqwest)?;

let mut buf: BytesMut = BytesMut::new();

Expand Down
22 changes: 22 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,28 @@ pub fn extract_functions(body: String) -> Vec<(String, String)> {
function_name = between(body.as_str(), left_name.as_str(), "]");
}

if function_name.is_empty() {
static FUNCTION_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"(?xs);\s*(?P<name>[a-zA-Z0-9_$]+)\s*=\s*function\([a-zA-Z0-9_$]+\)\s*\{",
)
.unwrap()
});

for caps in FUNCTION_REGEX.captures_iter(body.as_str()) {
let name = caps.name("name").unwrap().as_str();

let start_pos = caps.get(0).unwrap().end();
if let Some(end_pos) = body[start_pos..].find("};") {
let function_body = &body[start_pos..start_pos + end_pos];

if function_body.contains("enhanced_except_") {
function_name = name;
}
}
}
}

// println!("ncode function name: {}", function_name);

if !function_name.is_empty() {
Expand Down

0 comments on commit 7606f78

Please sign in to comment.