diff --git a/src/anime/anime.rs b/src/anime/anime.rs index cc2bcd7..6f1c19e 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -261,6 +261,7 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( .unwrap(); app.episodes = get_episodes( &app.animes.0[selected.unwrap()].parse::().unwrap(), + &app.provider, ); app.messages.items.clear(); if app.token == "local" || app.anime_id == 0 { @@ -272,12 +273,16 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( app.messages.state.select(Some(app.progress as usize)); } if app.episodes.0.len() == 1 { - let link = get_episode_link(&app.episodes.1[0]); + let link = get_episode_link(&app.episodes.1[0], &app.provider); if !app.cast.0 { - open_video((link, format!("{} Episode 1", &app.title))); + open_video(( + link.0, + format!("{} Episode 1", &app.title), + link.1, + )); } else { open_cast( - (link, format!("{} Episode 1", &app.title)), + (link.1, format!("{} Episode 1", &app.title)), &app.cast.1, ) } @@ -317,12 +322,19 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( .collect::>()[0] .parse::() .unwrap(); - let link = get_episode_link(&app.episodes.1[app.ep as usize - 1]); + let link = get_episode_link( + &app.episodes.1[app.ep as usize - 1], + &app.provider, + ); if !app.cast.0 { - open_video((link, format!("{} Episode {}", &app.title, app.ep))); + open_video(( + link.0, + format!("{} Episode {}", &app.title, app.ep), + link.1, + )); } else { open_cast( - (link, format!("{} Episode {}", &app.title, app.ep)), + (link.0, format!("{} Episode {}", &app.title, app.ep)), &app.cast.1, ) } diff --git a/src/anime/player.rs b/src/anime/player.rs index 665d777..0a3b6ce 100644 --- a/src/anime/player.rs +++ b/src/anime/player.rs @@ -8,16 +8,28 @@ use rust_cast::{ }; use std::str::FromStr; -pub fn open_video(link: (String, String)) { - let title = link.1; - let title = title.replace("-", " "); - let arg: String = format!("--force-media-title={}", title); - let _ = std::process::Command::new("mpv") - .arg(link.0) - .arg(arg) - .output() - .expect("failed to open mpv"); - +pub fn open_video(link: (String, String, String)) { + if link.2 == "null" { + let title = link.1; + let title = title.replace("-", " "); + let arg: String = format!("--force-media-title={}", title); + let _ = std::process::Command::new("mpv") + .arg(link.0) + .arg(arg) + .output() + .expect("failed to open mpv"); + } else { + let title = link.1; + let title = title.replace("-", " "); + let arg1: String = format!("--force-media-title={}", title); + let arg2: String = format!("--sub-files={}", link.2); + let _ = std::process::Command::new("mpv") + .arg(link.0) + .arg(arg1) + .arg(arg2) + .output() + .expect("failed to open mpv"); + } // clear terminal } diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index ce83e2a..c81e4da 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -43,11 +43,11 @@ pub fn search_anime(query: String) -> (Vec, Vec, Vec) { (ids, titles, images) } -pub fn get_episodes(id: &i32) -> (Vec, Vec) { +pub fn get_episodes(id: &i32, provider: &str) -> (Vec, Vec) { let req = Request::builder() .uri(format!( - "https://api.consumet.org/meta/anilist/info/{}?provider=gogoanime", - id + "https://api.consumet.org/meta/anilist/info/{}?provider={}", + id, provider )) .redirect_policy(isahc::config::RedirectPolicy::Follow) .header( @@ -67,11 +67,11 @@ pub fn get_episodes(id: &i32) -> (Vec, Vec) { (titles, ids) } -pub fn get_episode_link(ep_id: &str) -> String { +pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) { let req = Request::builder() .uri(format!( - "https://api.consumet.org/meta/anilist/watch/{}?provider=gogoanime", - ep_id + "https://api.consumet.org/meta/anilist/watch/{}?provider={}", + ep_id, provider )) .redirect_policy(isahc::config::RedirectPolicy::Follow) .header( @@ -84,17 +84,33 @@ pub fn get_episode_link(ep_id: &str) -> String { let json: serde_json::Value = serde_json::from_str(&json).unwrap(); let url = ""; std::fs::write("test.json", json.to_string()).unwrap(); + let mut subtitle = String::new(); + let _error_vec = Vec::new(); + let sub_array = json["subtitles"].as_array().unwrap_or(&_error_vec); + for i in 0..sub_array.len() { + //set subtitle to lang = English + if json["subtitles"][i]["lang"].as_str().unwrap_or("null") == "English" { + subtitle = json["subtitles"][i]["url"] + .as_str() + .unwrap_or("null") + .to_string(); + // add \ before the first : in the url + subtitle = subtitle.replace(":", "\\:"); + } + } for i in 0..json["sources"].as_array().unwrap().len() { - //return json["sources"][i]["url"].as_str().unwrap().to_string(); where json["sources"][i]["quality"].as_str().unwrap().contains("1080") if json["sources"][i]["quality"] .as_str() .unwrap() .contains("1080") { - return json["sources"][i]["url"].as_str().unwrap().to_string(); + return ( + json["sources"][i]["url"].as_str().unwrap().to_string(), + subtitle, + ); } } - url.to_string() + (url.to_string(), subtitle) } pub fn get_image(url: &str, path: &str) { diff --git a/src/main.rs b/src/main.rs index d53215f..a010a16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,17 +29,17 @@ fn main() { 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(); + if arg == "zoro" { + provider = "zoro".to_string(); count += 1; } else if arg == "gogo" { - provider = "gogo".to_string(); + provider = "gogoanime".to_string(); count += 1; } else { - provider = "gogo".to_string(); + provider = "zoro".to_string(); } } else { - provider = "vrv".to_string(); + provider = "zoro".to_string(); } } if arg == "--cast" || arg == "-C" { @@ -122,13 +122,13 @@ fn print_help() { ); println!( "if no provider is entered it will default to {}", - "vrv".green() + "gogo".green() ); println!( "if the -r argument is not used it will default to {}", - "gogo".green() + "zoro".green() ); - println!("the providers are {} or {}", "gogo".green(), "vrv".green()); + println!("the providers are {} or {}", "gogo".green(), "zoro".green()); println!(""); println!("help:\t\t{}", format_args!("{}", "-h --help".red())); //kill the program