ytdlp_ejs/
lib.rs

1//! EJS - JavaScript Challenge Solver Library
2
3pub mod builtin;
4pub mod director;
5pub mod provider;
6pub mod registry;
7pub mod test_data;
8
9// Re-export public API
10pub use builtin::preprocessor::preprocess_player;
11pub use director::{process_input };
12pub use provider::{
13    JsChallengeError, JsChallengeInput, JsChallengeOutput, JsChallengeRequest, JsChallengeResponse,
14    JsChallengeType,
15};
16pub use registry::RuntimeType;
17
18/// Run challenge solver with the specified runtime
19pub fn run(
20    player: String,
21    runtime: RuntimeType,
22    challenges: Vec<String>,
23) -> Result<JsChallengeOutput, JsChallengeError> {
24    let mut n_challenges = Vec::new();
25    let mut sig_challenges = Vec::new();
26
27    for request in &challenges {
28        let parts: Vec<&str> = request.splitn(2, ':').collect();
29        if parts.len() != 2 {
30            return Err(JsChallengeError::Parse(format!(
31                "Invalid request format: {}",
32                request
33            )));
34        }
35
36        match parts[0] {
37            "n" => n_challenges.push(parts[1].to_string()),
38            "sig" => sig_challenges.push(parts[1].to_string()),
39            t => return Err(JsChallengeError::Parse(format!("Unsupported type: {}", t))),
40        }
41    }
42
43    let input = JsChallengeInput::Player {
44        player,
45        requests: vec![
46            JsChallengeRequest {
47                challenge_type: JsChallengeType::N,
48                challenges: n_challenges,
49            },
50            JsChallengeRequest {
51                challenge_type: JsChallengeType::Sig,
52                challenges: sig_challenges,
53            },
54        ],
55        output_preprocessed: false,
56    };
57
58    Ok(process_input(input, runtime))
59}