added new providers

This commit is contained in:
Zastian Pretorius
2022-11-04 14:37:07 +00:00
parent 1fc1b7e867
commit 3abedb7360
3 changed files with 76 additions and 25 deletions

View File

@@ -92,6 +92,7 @@ struct App {
progress: i32, progress: i32,
anime_id: i32, anime_id: i32,
token: String, token: String,
provider: String,
} }
impl<'a> App { impl<'a> App {
@@ -105,11 +106,12 @@ impl<'a> App {
progress: 0, progress: 0,
anime_id: 0, anime_id: 0,
token: String::new(), token: String::new(),
provider: String::new(),
} }
} }
} }
pub fn anime_ui(token: String) -> Result<(), Box<dyn Error>> { pub fn anime_ui(token: String, provider: String) -> Result<(), Box<dyn Error>> {
// setup terminal // setup terminal
enable_raw_mode()?; enable_raw_mode()?;
let mut stdout = io::stdout(); let mut stdout = io::stdout();
@@ -120,6 +122,7 @@ pub fn anime_ui(token: String) -> Result<(), Box<dyn Error>> {
// create app and run it // create app and run it
let mut app = App::default(); let mut app = App::default();
app.token = token; app.token = token;
app.provider = provider;
let res = run_app(&mut terminal, app); let res = run_app(&mut terminal, app);
// restore terminal // restore terminal
@@ -176,7 +179,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
app.messages.state.select(Some(app.progress as usize)); app.messages.state.select(Some(app.progress as usize));
} }
if anime_info.1 == 1 { 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)); open_video((link.0, link.1));
if app.token == "local" || app.anime_id == 0 { if app.token == "local" || app.anime_id == 0 {
write_an_progress(&app.title, &1); write_an_progress(&app.title, &1);
@@ -199,7 +202,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
.replace("Episode ", "") .replace("Episode ", "")
.parse::<u64>() .parse::<u64>()
.unwrap(); .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)); open_video((link.0, link.1));
if app.ep > app.progress as u64 { if app.ep > app.progress as u64 {
if app.token == "local" || app.anime_id == 0 { if app.token == "local" || app.anime_id == 0 {

View File

@@ -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 url = format!("https://animixplay.to/v1/{}", title);
let html = get_anime_html(&url); let html = get_anime_html(&url);
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap(); 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(), None => "".to_string(),
}; };
if id1 != "" { if id1 != "" {
let title = format!("{} Episode {}", title.replace('-', " "), ep); if provider == "vrv" {
let encoded_id1 = encode(&id1); let title = format!("{} Episode {}", title.replace('-', " "), ep);
let encoded_id2 = encode(&encoded_id1); let encoded_id1 = encode(&id1);
let mut last_byte = encoded_id1.as_bytes()[encoded_id1.len() - 2]; let encoded_id2 = encode(&encoded_id1);
last_byte += 1; let mut last_byte = encoded_id1.as_bytes()[encoded_id1.len() - 2];
let mut new_encoded_id1 = encoded_id1.as_bytes().to_vec(); last_byte += 1;
new_encoded_id1.pop(); 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); new_encoded_id1.pop();
let new_encoded_id1 = String::from_utf8(new_encoded_id1).unwrap(); new_encoded_id1.push(last_byte);
let ani_id = format!("cW9{}MVFhzM0dyVTh3ZTlP{}", new_encoded_id1, encoded_id2); let new_encoded_id1 = String::from_utf8(new_encoded_id1).unwrap();
let result = get_ep_location(format!("https://animixplay.to/api/{}", ani_id).as_str()); let ani_id = format!("cW9{}MVFhzM0dyVTh3ZTlP{}", new_encoded_id1, encoded_id2);
//split the result into at # and return the second part let result = get_ep_location(format!("https://animixplay.to/api/{}", ani_id).as_str());
let result: String = std::str::from_utf8( //split the result into at # and return the second part
decode(result.split('#').nth(1).unwrap()) 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() .unwrap()
.as_slice(), .to_string();
) return (url, title);
.unwrap() } else {
.to_string(); panic!("Invalid provider");
return (result, title); }
} else { } else {
let re = Regex::new(r#"(?m)r\.html#(.*)""#).unwrap(); let re = Regex::new(r#"(?m)r\.html#(.*)""#).unwrap();
let id2 = re let id2 = re

View File

@@ -21,6 +21,7 @@ fn main() {
let mut chapter: u32 = 0; let mut chapter: u32 = 0;
//let search = option string //let search = option string
let mut count = 0; let mut count = 0;
let mut provider: String = "gogo".to_string();
for arg in std::env::args() { for arg in std::env::args() {
if arg == "--help" || arg == "-h" { if arg == "--help" || arg == "-h" {
help = true; help = true;
@@ -28,6 +29,23 @@ fn main() {
if arg == "--anime" || arg == "-a" { if arg == "--anime" || arg == "-a" {
anime = true; 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" { if arg == "--ln" || arg == "-l" {
ln = true; ln = true;
} }
@@ -67,7 +85,7 @@ fn main() {
//anime_stream(search, episode, resume); //anime_stream(search, episode, resume);
let token = get_token(); let token = get_token();
_ = anime_ui(token); _ = anime_ui(token, provider);
} else { } else {
println!("Invalid argument"); println!("Invalid argument");
} }
@@ -88,6 +106,21 @@ fn print_help() {
println!("{}", "for exaple kami -c 200"); println!("{}", "for exaple kami -c 200");
//print blank line //print blank line
println!(""); 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())); println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
//kill the program //kill the program
std::process::exit(0); std::process::exit(0);