mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
implemented way better anilist tracking
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::helpers::name_ranker::string_sumularity_ranker;
|
||||
use crate::open_video;
|
||||
use crate::{anime_ep_range, anime_link, anime_names};
|
||||
use crate::{anime_ep_range, anime_info, anime_link, anime_names};
|
||||
use crate::{get_anime_id, get_user_anime_progress, update_anime_progress};
|
||||
|
||||
use crossterm::{
|
||||
@@ -87,6 +88,7 @@ struct App {
|
||||
progress: i32,
|
||||
anime_id: i32,
|
||||
token: String,
|
||||
anime_mal_info: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
impl<'a> App {
|
||||
@@ -100,6 +102,7 @@ impl<'a> App {
|
||||
progress: 0,
|
||||
anime_id: 0,
|
||||
token: String::new(),
|
||||
anime_mal_info: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,33 +160,21 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
||||
KeyCode::Enter => {
|
||||
if ep_select == false {
|
||||
let selected = app.messages.state.selected();
|
||||
app.title = app
|
||||
.messages
|
||||
.iter()
|
||||
.nth(selected.unwrap())
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let gogo = app.messages.items[selected.unwrap()].clone();
|
||||
app.anime_mal_info = anime_info(gogo.clone());
|
||||
let mut animixplay = Vec::new();
|
||||
//for each app.anime_mal_info.0 add to animixplay
|
||||
for i in 0..app.anime_mal_info.len() {
|
||||
animixplay.push(app.anime_mal_info[i].0.as_str());
|
||||
}
|
||||
let simular = string_sumularity_ranker(animixplay, &gogo);
|
||||
app.title = simular.1.to_string();
|
||||
let ep_range = anime_ep_range(&app.title);
|
||||
let title = app.title.replace("tv-", "");
|
||||
let title = title.replace("dub", "");
|
||||
let title = title.replace("-uncensored", "");
|
||||
//if title contains "movie" then remove movie if it contains "movie-*" then remove movie-*
|
||||
let title = if title.contains("movie-") {
|
||||
//find the index of "movie"
|
||||
let index = title.find("movie-").unwrap();
|
||||
//remove "movie-*"
|
||||
title.replace(&title[index..index + 7], "")
|
||||
} else if title.contains("movie") {
|
||||
title.replace("movie", "")
|
||||
} else {
|
||||
title
|
||||
};
|
||||
|
||||
app.anime_id = get_anime_id(&title.replace("-", " "));
|
||||
let mel_id = app.anime_mal_info[simular.0].1.parse::<i32>().unwrap();
|
||||
app.anime_id = get_anime_id(mel_id);
|
||||
app.messages.items.clear();
|
||||
app.progress =
|
||||
get_user_anime_progress(app.anime_id, app.token.as_str());
|
||||
//set app.messages.state.selected to app.progress
|
||||
app.messages.state.select(Some(app.progress as usize));
|
||||
if ep_range == 1 {
|
||||
let link = anime_link(&app.title, 1);
|
||||
@@ -221,8 +212,9 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
||||
let anime_list = anime_names(app.input.drain(..).collect());
|
||||
app.messages.items.clear();
|
||||
for anime in anime_list {
|
||||
app.messages.push(anime);
|
||||
app.messages.push(anime.to_string());
|
||||
}
|
||||
|
||||
ep_select = false;
|
||||
app.input_mode = InputMode::Normal;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,33 @@ pub fn anime_names(query: String) -> Vec<String> {
|
||||
anime_list
|
||||
}
|
||||
|
||||
//get anime name and id using net\\\/anime\\\/([0-9]*)\\\/([^"]*)"
|
||||
pub fn anime_info(query: String) -> Vec<(String, String)> {
|
||||
let url = format!(
|
||||
"https://api.jikan.moe/v4/anime?q={}&limit=18&sfw=true",
|
||||
query
|
||||
);
|
||||
//relpace all spaces with %20
|
||||
let url = url.replace(' ', "%20");
|
||||
let html = get_anime_html(&url);
|
||||
let re = Regex::new(r#"(?m)net\\/anime\\/([0-9]*)\\/([^"]*)"#).unwrap();
|
||||
let mut anime_list: Vec<(String, String)> = Vec::new();
|
||||
for cap in re.captures_iter(&html) {
|
||||
anime_list.push((
|
||||
cap.get(2).unwrap().as_str().trim().to_string(),
|
||||
cap.get(1).unwrap().as_str().trim().to_string(),
|
||||
));
|
||||
}
|
||||
anime_list.dedup();
|
||||
|
||||
anime_list
|
||||
}
|
||||
|
||||
pub fn anime_ep_range(anime_name: &str) -> u16 {
|
||||
let url = format!("https://gogoanime.dk/category/{}", anime_name);
|
||||
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))
|
||||
|
||||
@@ -29,10 +29,10 @@ pub fn get_token() -> String {
|
||||
token
|
||||
}
|
||||
|
||||
pub fn get_anime_id(anime: &str) -> i32 {
|
||||
pub fn get_anime_id(mal_id: i32) -> i32 {
|
||||
const QUERY: &str = "
|
||||
query ($id: Int, $search: String) {
|
||||
Media (id: $id, search: $search, type: ANIME) {
|
||||
query ($id: Int, $search: Int) {
|
||||
Media (id: $id, idMal: $search, type: ANIME) {
|
||||
id
|
||||
title {
|
||||
native
|
||||
@@ -45,7 +45,7 @@ query ($id: Int, $search: String) {
|
||||
let json = json!({
|
||||
"query": QUERY,
|
||||
"variables": {
|
||||
"search": anime,
|
||||
"search": mal_id
|
||||
}
|
||||
});
|
||||
let resp = Request::builder()
|
||||
@@ -58,7 +58,6 @@ query ($id: Int, $search: String) {
|
||||
.send()
|
||||
.unwrap()
|
||||
.text();
|
||||
//println!("{}", resp);
|
||||
let regex = regex::Regex::new(r#"id":(.*?),"#).unwrap();
|
||||
let resp: String = resp.as_ref().unwrap().to_string();
|
||||
let id = regex
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod fixing_text;
|
||||
pub mod name_ranker;
|
||||
pub mod take_input;
|
||||
|
||||
20
src/helpers/name_ranker.rs
Normal file
20
src/helpers/name_ranker.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
pub fn string_sumularity_ranker(animixplay: Vec<&str>, gogo: &str) -> (usize, String) {
|
||||
let mut score = 0;
|
||||
let mut index = 0;
|
||||
for a in &animixplay {
|
||||
let mut temp_score = 0;
|
||||
// compare the each first letter of the strings and then the second and so on without unwrapping
|
||||
for (_i, (a, b)) in a.chars().zip(gogo.chars()).enumerate() {
|
||||
if a == b {
|
||||
temp_score += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if temp_score > score {
|
||||
score = temp_score;
|
||||
index = animixplay.iter().position(|&x| &x == a).unwrap();
|
||||
}
|
||||
}
|
||||
(index, gogo.to_string()) //
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use ln::ln::ln_ui;
|
||||
|
||||
use crate::anime::{
|
||||
player::open_video,
|
||||
scraper::{anime_ep_range, anime_link, anime_names},
|
||||
scraper::{anime_ep_range, anime_info, anime_link, anime_names},
|
||||
trackers::*,
|
||||
};
|
||||
use crate::get_token;
|
||||
|
||||
Reference in New Issue
Block a user