mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
optimised episode range detection
This commit is contained in:
@@ -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<B: Backend>(terminal: &mut Terminal<B>, 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;
|
||||
|
||||
@@ -45,30 +45,7 @@ pub fn anime_names(query: String) -> Vec<String> {
|
||||
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<a href="\#" class="active" ep_start = (.*?)</a>"#).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::<u16>()
|
||||
.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::<i32>().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::<i32>().unwrap_or(0),
|
||||
episodes.parse::<u16>().unwrap_or(0),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn anime_link(title: &str, ep: u64) -> (String, String) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user