coolansx you are amazing(make stacking even better)

This commit is contained in:
Zastian Pretorius
2022-10-11 12:06:32 +01:00
parent 8ad12ebcca
commit 3ff0a47ff7
5 changed files with 22 additions and 60 deletions

View File

@@ -1,6 +1,5 @@
use crate::helpers::name_ranker::string_sumularity_ranker;
use crate::open_video;
use crate::{anime_ep_range, anime_info, anime_link, anime_names};
use crate::{anime_ep_range, anime_link, anime_names, get_mal_id};
use crate::{get_anime_id, get_user_anime_progress, update_anime_progress};
use crossterm::{
@@ -88,7 +87,6 @@ struct App {
progress: i32,
anime_id: i32,
token: String,
anime_mal_info: Vec<(String, String)>,
}
impl<'a> App {
@@ -102,7 +100,6 @@ impl<'a> App {
progress: 0,
anime_id: 0,
token: String::new(),
anime_mal_info: Vec::new(),
}
}
}
@@ -160,17 +157,9 @@ 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();
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();
app.title = app.messages.items[selected.unwrap()].clone();
let ep_range = anime_ep_range(&app.title);
let mel_id = app.anime_mal_info[simular.0].1.parse::<i32>().unwrap();
let mel_id = get_mal_id(&app.title);
app.anime_id = get_anime_id(mel_id);
app.messages.items.clear();
app.progress =
@@ -178,7 +167,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
app.messages.state.select(Some(app.progress as usize));
if ep_range == 1 {
let link = anime_link(&app.title, 1);
open_video(link);
open_video((link.0, link.1));
} else {
for ep in 1..ep_range + 1 {
app.messages.push(format!("Episode {}", ep));
@@ -196,7 +185,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
.parse::<u64>()
.unwrap();
let link = anime_link(&app.title, app.ep);
open_video(link);
open_video((link.0, link.1));
update_anime_progress(
app.anime_id,
app.ep as usize,

View File

@@ -45,28 +45,6 @@ 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/{}",
@@ -90,6 +68,22 @@ pub fn anime_ep_range(anime_name: &str) -> u16 {
.unwrap_or(0)
}
pub fn get_mal_id(title: &str) -> i32 {
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();
let mal_id = re
.captures_iter(&html)
.next()
.unwrap()
.get(1)
.unwrap()
.as_str()
.trim()
.to_string();
mal_id.parse::<i32>().unwrap_or(0)
}
pub fn anime_link(title: &str, ep: u64) -> (String, String) {
let url = format!("https://animixplay.to/v1/{}", title);
let html = get_anime_html(&url);

View File

@@ -1,3 +1,2 @@
pub mod fixing_text;
pub mod name_ranker;
pub mod take_input;

View File

@@ -1,20 +0,0 @@
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()) //
}

View File

@@ -9,7 +9,7 @@ use ln::ln::ln_ui;
use crate::anime::{
player::open_video,
scraper::{anime_ep_range, anime_info, anime_link, anime_names},
scraper::{anime_ep_range, anime_link, anime_names, get_mal_id},
trackers::*,
};
use crate::get_token;