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::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 crate::{get_anime_id, get_user_anime_progress, update_anime_progress};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
@@ -87,6 +88,7 @@ struct App {
|
|||||||
progress: i32,
|
progress: i32,
|
||||||
anime_id: i32,
|
anime_id: i32,
|
||||||
token: String,
|
token: String,
|
||||||
|
anime_mal_info: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> App {
|
impl<'a> App {
|
||||||
@@ -100,6 +102,7 @@ impl<'a> App {
|
|||||||
progress: 0,
|
progress: 0,
|
||||||
anime_id: 0,
|
anime_id: 0,
|
||||||
token: String::new(),
|
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 => {
|
KeyCode::Enter => {
|
||||||
if ep_select == false {
|
if ep_select == false {
|
||||||
let selected = app.messages.state.selected();
|
let selected = app.messages.state.selected();
|
||||||
app.title = app
|
let gogo = app.messages.items[selected.unwrap()].clone();
|
||||||
.messages
|
app.anime_mal_info = anime_info(gogo.clone());
|
||||||
.iter()
|
let mut animixplay = Vec::new();
|
||||||
.nth(selected.unwrap())
|
//for each app.anime_mal_info.0 add to animixplay
|
||||||
.unwrap()
|
for i in 0..app.anime_mal_info.len() {
|
||||||
.to_string();
|
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 ep_range = anime_ep_range(&app.title);
|
||||||
let title = app.title.replace("tv-", "");
|
let mel_id = app.anime_mal_info[simular.0].1.parse::<i32>().unwrap();
|
||||||
let title = title.replace("dub", "");
|
app.anime_id = get_anime_id(mel_id);
|
||||||
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("-", " "));
|
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
app.progress =
|
app.progress =
|
||||||
get_user_anime_progress(app.anime_id, app.token.as_str());
|
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));
|
app.messages.state.select(Some(app.progress as usize));
|
||||||
if ep_range == 1 {
|
if ep_range == 1 {
|
||||||
let link = anime_link(&app.title, 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());
|
let anime_list = anime_names(app.input.drain(..).collect());
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
for anime in anime_list {
|
for anime in anime_list {
|
||||||
app.messages.push(anime);
|
app.messages.push(anime.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
ep_select = false;
|
ep_select = false;
|
||||||
app.input_mode = InputMode::Normal;
|
app.input_mode = InputMode::Normal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,33 @@ pub fn anime_names(query: String) -> Vec<String> {
|
|||||||
anime_list
|
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 {
|
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 re = Regex::new(r#"(?m)\s<a href="\#" class="active" ep_start = (.*?)</a>"#).unwrap();
|
||||||
let episodes = re
|
let episodes = re
|
||||||
.captures_iter(&get_anime_html(&url))
|
.captures_iter(&get_anime_html(&url))
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ pub fn get_token() -> String {
|
|||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_anime_id(anime: &str) -> i32 {
|
pub fn get_anime_id(mal_id: i32) -> i32 {
|
||||||
const QUERY: &str = "
|
const QUERY: &str = "
|
||||||
query ($id: Int, $search: String) {
|
query ($id: Int, $search: Int) {
|
||||||
Media (id: $id, search: $search, type: ANIME) {
|
Media (id: $id, idMal: $search, type: ANIME) {
|
||||||
id
|
id
|
||||||
title {
|
title {
|
||||||
native
|
native
|
||||||
@@ -45,7 +45,7 @@ query ($id: Int, $search: String) {
|
|||||||
let json = json!({
|
let json = json!({
|
||||||
"query": QUERY,
|
"query": QUERY,
|
||||||
"variables": {
|
"variables": {
|
||||||
"search": anime,
|
"search": mal_id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let resp = Request::builder()
|
let resp = Request::builder()
|
||||||
@@ -58,7 +58,6 @@ query ($id: Int, $search: String) {
|
|||||||
.send()
|
.send()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.text();
|
.text();
|
||||||
//println!("{}", resp);
|
|
||||||
let regex = regex::Regex::new(r#"id":(.*?),"#).unwrap();
|
let regex = regex::Regex::new(r#"id":(.*?),"#).unwrap();
|
||||||
let resp: String = resp.as_ref().unwrap().to_string();
|
let resp: String = resp.as_ref().unwrap().to_string();
|
||||||
let id = regex
|
let id = regex
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod fixing_text;
|
pub mod fixing_text;
|
||||||
|
pub mod name_ranker;
|
||||||
pub mod take_input;
|
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::{
|
use crate::anime::{
|
||||||
player::open_video,
|
player::open_video,
|
||||||
scraper::{anime_ep_range, anime_link, anime_names},
|
scraper::{anime_ep_range, anime_info, anime_link, anime_names},
|
||||||
trackers::*,
|
trackers::*,
|
||||||
};
|
};
|
||||||
use crate::get_token;
|
use crate::get_token;
|
||||||
|
|||||||
Reference in New Issue
Block a user