diff --git a/src/anime/anime.rs b/src/anime/anime.rs index be6bae4..f78c562 100644 --- a/src/anime/anime.rs +++ b/src/anime/anime.rs @@ -1,5 +1,5 @@ use crate::open_video; -use crate::{anime_ep_range, anime_link, anime_names, get_mal_id}; +use crate::{anime_link, anime_names}; use crate::{get_anime_id, get_user_anime_progress, update_anime_progress}; use crossterm::{ @@ -18,6 +18,8 @@ use tui::{ }; use unicode_width::UnicodeWidthStr; +use super::scraper::get_anime_info; + enum InputMode { Normal, Editing, @@ -158,19 +160,18 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( if ep_select == false { let selected = app.messages.state.selected(); app.title = app.messages.items[selected.unwrap()].clone(); - let ep_range = anime_ep_range(&app.title); - let mel_id = get_mal_id(&app.title); - app.anime_id = get_anime_id(mel_id); + let anime_info = get_anime_info(&app.title); + app.anime_id = get_anime_id(anime_info.0); app.messages.items.clear(); app.progress = get_user_anime_progress(app.anime_id, app.token.as_str()); app.messages.state.select(Some(app.progress as usize)); - if ep_range == 1 { + if anime_info.1 == 1 { let link = anime_link(&app.title, 1); open_video((link.0, link.1)); update_anime_progress(app.anime_id, 1, app.token.as_str()); } else { - for ep in 1..ep_range + 1 { + for ep in 1..anime_info.1 + 1 { app.messages.push(format!("Episode {}", ep)); } ep_select = true; diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index 4cb11a1..619997e 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -45,30 +45,7 @@ pub fn anime_names(query: String) -> Vec { anime_list } -pub fn anime_ep_range(anime_name: &str) -> u16 { - let url = format!( - "https://gogoanime.dk/category/{}", - anime_name.replace("__", "-").replace("_", "-") - ); - let re = Regex::new(r#"(?m)\s"#).unwrap(); - let episodes = re - .captures_iter(&get_anime_html(&url)) - .next() - .unwrap() - .get(1) - .unwrap() - .as_str() - .trim() - .to_string(); - episodes - .split('-') - .nth(1) - .unwrap_or("0") - .parse::() - .unwrap_or(0) -} - -pub fn get_mal_id(title: &str) -> i32 { +pub fn get_anime_info(title: &str) -> (i32, u16) { let url = format!("https://animixplay.to/v1/{}", title); let html = get_anime_html(&url); let re = Regex::new(r#"(?m)var malid = '([0-9]*)'"#).unwrap(); @@ -81,7 +58,21 @@ pub fn get_mal_id(title: &str) -> i32 { .as_str() .trim() .to_string(); - mal_id.parse::().unwrap_or(0) + + let re = Regex::new(r#"(?m)"eptotal":([\d]+)"#).unwrap(); + let episodes = re + .captures_iter(&html) + .next() + .unwrap() + .get(1) + .unwrap() + .as_str() + .trim() + .to_string(); + ( + mal_id.parse::().unwrap_or(0), + episodes.parse::().unwrap_or(0), + ) } pub fn anime_link(title: &str, ep: u64) -> (String, String) { diff --git a/src/main.rs b/src/main.rs index eeb756e..129039d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use ln::ln::ln_ui; use crate::anime::{ player::open_video, - scraper::{anime_ep_range, anime_link, anime_names, get_mal_id}, + scraper::{anime_link, anime_names}, trackers::*, }; use crate::get_token;