diff --git a/src/anime/anime.rs b/src/anime/anime.rs index e680f7d..1958cf5 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -92,6 +92,7 @@ struct App { progress: i32, anime_id: i32, token: String, + provider: String, } impl<'a> App { @@ -105,11 +106,12 @@ impl<'a> App { progress: 0, anime_id: 0, token: String::new(), + provider: String::new(), } } } -pub fn anime_ui(token: String) -> Result<(), Box> { +pub fn anime_ui(token: String, provider: String) -> Result<(), Box> { // setup terminal enable_raw_mode()?; let mut stdout = io::stdout(); @@ -120,6 +122,7 @@ pub fn anime_ui(token: String) -> Result<(), Box> { // create app and run it let mut app = App::default(); app.token = token; + app.provider = provider; let res = run_app(&mut terminal, app); // restore terminal @@ -176,7 +179,7 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( app.messages.state.select(Some(app.progress as usize)); } if anime_info.1 == 1 { - let link = anime_link(&app.title, 1); + let link = anime_link(&app.title, 1, &app.provider); open_video((link.0, link.1)); if app.token == "local" || app.anime_id == 0 { write_an_progress(&app.title, &1); @@ -199,7 +202,7 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( .replace("Episode ", "") .parse::() .unwrap(); - let link = anime_link(&app.title, app.ep); + let link = anime_link(&app.title, app.ep, &app.provider); open_video((link.0, link.1)); if app.ep > app.progress as u64 { if app.token == "local" || app.anime_id == 0 { diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index 66805ca..541912b 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -77,7 +77,7 @@ pub fn get_anime_info(title: &str) -> (i32, u16) { ) } -pub fn anime_link(title: &str, ep: u64) -> (String, String) { +pub fn anime_link(title: &str, ep: u64, provider: &str) -> (String, String) { let url = format!("https://animixplay.to/v1/{}", title); let html = get_anime_html(&url); let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap(); @@ -86,27 +86,42 @@ pub fn anime_link(title: &str, ep: u64) -> (String, String) { None => "".to_string(), }; if id1 != "" { - let title = format!("{} Episode {}", title.replace('-', " "), ep); - let encoded_id1 = encode(&id1); - let encoded_id2 = encode(&encoded_id1); - let mut last_byte = encoded_id1.as_bytes()[encoded_id1.len() - 2]; - last_byte += 1; - let mut new_encoded_id1 = encoded_id1.as_bytes().to_vec(); - new_encoded_id1.pop(); - new_encoded_id1.pop(); - new_encoded_id1.push(last_byte); - let new_encoded_id1 = String::from_utf8(new_encoded_id1).unwrap(); - let ani_id = format!("cW9{}MVFhzM0dyVTh3ZTlP{}", new_encoded_id1, encoded_id2); - let result = get_ep_location(format!("https://animixplay.to/api/{}", ani_id).as_str()); - //split the result into at # and return the second part - let result: String = std::str::from_utf8( - decode(result.split('#').nth(1).unwrap()) + if provider == "vrv" { + let title = format!("{} Episode {}", title.replace('-', " "), ep); + let encoded_id1 = encode(&id1); + let encoded_id2 = encode(&encoded_id1); + let mut last_byte = encoded_id1.as_bytes()[encoded_id1.len() - 2]; + last_byte += 1; + let mut new_encoded_id1 = encoded_id1.as_bytes().to_vec(); + new_encoded_id1.pop(); + new_encoded_id1.pop(); + new_encoded_id1.push(last_byte); + let new_encoded_id1 = String::from_utf8(new_encoded_id1).unwrap(); + let ani_id = format!("cW9{}MVFhzM0dyVTh3ZTlP{}", new_encoded_id1, encoded_id2); + let result = get_ep_location(format!("https://animixplay.to/api/{}", ani_id).as_str()); + //split the result into at # and return the second part + let result: String = std::str::from_utf8( + decode(result.split('#').nth(1).unwrap()) + .unwrap() + .as_slice(), + ) + .unwrap() + .to_string(); + return (result, title); + } else if provider == "gogo" { + let title = format!("{} Episode {}", title.replace('-', " "), ep); + let encoded_id1 = encode(&id1); + let anime_id = encode(format!("{}LTXs3GrU8we9O{}", id1, encoded_id1)); + let html = format!("https://animixplay.to/api/live{}", anime_id); + let url = get_ep_location(&html); + let url = url.split('#').nth(1).unwrap(); + let url = std::str::from_utf8(&decode(url).unwrap()) .unwrap() - .as_slice(), - ) - .unwrap() - .to_string(); - return (result, title); + .to_string(); + return (url, title); + } else { + panic!("Invalid provider"); + } } else { let re = Regex::new(r#"(?m)r\.html#(.*)""#).unwrap(); let id2 = re diff --git a/src/main.rs b/src/main.rs index 129039d..7f925da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ fn main() { let mut chapter: u32 = 0; //let search = option string let mut count = 0; + let mut provider: String = "gogo".to_string(); for arg in std::env::args() { if arg == "--help" || arg == "-h" { help = true; @@ -28,6 +29,23 @@ fn main() { if arg == "--anime" || arg == "-a" { anime = true; } + if arg == "--provider" || arg == "-r" { + if let Some(arg) = std::env::args().nth(count + 1) { + //get the next argument and see if it is = to gogo of vrv + if arg == "vrv" { + provider = "vrv".to_string(); + count += 1; + } else if arg == "gogo" { + provider = "gogo".to_string(); + count += 1; + } else { + provider = "gogo".to_string(); + } + } else { + provider = "vrv".to_string(); + } + } + if arg == "--ln" || arg == "-l" { ln = true; } @@ -67,7 +85,7 @@ fn main() { //anime_stream(search, episode, resume); let token = get_token(); - _ = anime_ui(token); + _ = anime_ui(token, provider); } else { println!("Invalid argument"); } @@ -88,6 +106,21 @@ fn print_help() { println!("{}", "for exaple kami -c 200"); //print blank line println!(""); + println!("provider:\t{}", format_args!("{}", "-r --provider".red())); + println!( + "{}", + "after this^^^ argument you can enter a provider".green() + ); + println!( + "if no provider is entered it will default to {}", + "vrv".green() + ); + println!( + "if the -r argument is not used it will default to {}", + "gogo".green() + ); + println!("the providers are {} or {}", "gogo".green(), "vrv".green()); + println!(""); println!("help:\t\t{}", format_args!("{}", "-h --help".red())); //kill the program std::process::exit(0);