mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
Did more refacroring and made a better loop for anime as well as error handeling in anime
This commit is contained in:
20
Cargo.lock
generated
20
Cargo.lock
generated
@@ -276,6 +276,16 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kami"
|
||||||
|
version = "0.2.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"colored",
|
||||||
|
"isahc",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -319,16 +329,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log_e"
|
|
||||||
version = "0.2.0"
|
|
||||||
dependencies = [
|
|
||||||
"base64",
|
|
||||||
"colored",
|
|
||||||
"isahc",
|
|
||||||
"regex",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matches"
|
name = "matches"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "log_e"
|
name = "kami"
|
||||||
#author = "mrfluffy-dev"
|
#author = "mrfluffy-dev"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod player;
|
pub mod player;
|
||||||
pub mod scraper;
|
pub mod scraper;
|
||||||
|
pub mod anime;
|
||||||
|
|||||||
60
src/anime/anime.rs
Normal file
60
src/anime/anime.rs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
use crate::{string_input,int_input,u16_input};
|
||||||
|
use crate::{anime_names,anime_ep_range,anime_link};
|
||||||
|
use crate::open_video;
|
||||||
|
use crate::main;
|
||||||
|
use colored::Colorize;
|
||||||
|
//use crate
|
||||||
|
pub fn anime_stream(){
|
||||||
|
let query = if std::env::args().len() > 2 {
|
||||||
|
std::env::args().nth(2).unwrap()
|
||||||
|
} else {
|
||||||
|
string_input("Enter query: ")
|
||||||
|
};
|
||||||
|
let anime_list = anime_names(&query);
|
||||||
|
let mut count = 0;
|
||||||
|
print!("\x1B[2J\x1B[1;1H");
|
||||||
|
anime_list.iter().for_each(|anime| {
|
||||||
|
if count % 2 == 0 {
|
||||||
|
println!(
|
||||||
|
"({})\t{}",
|
||||||
|
format_args!("{}", count.to_string().blue()),
|
||||||
|
format_args!("{}", anime.blue())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"({})\t{}",
|
||||||
|
format_args!("{}", count.to_string().yellow()),
|
||||||
|
format_args!("{}", anime.yellow())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
count += 1;
|
||||||
|
});
|
||||||
|
let mut anime_num: usize = usize::MAX;
|
||||||
|
while anime_num == usize::max_value() || anime_num >= anime_list.len() {
|
||||||
|
anime_num = int_input("Enter anime number: ");
|
||||||
|
if anime_num >= anime_list.len() {
|
||||||
|
println!("Invalid anime number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let title = &anime_list[anime_num];
|
||||||
|
let ep_range = anime_ep_range(title);
|
||||||
|
// if there is only one episode, then don't ask user to choose episode
|
||||||
|
if ep_range == 1 {
|
||||||
|
let link = anime_link(title, 1);
|
||||||
|
open_video(link);
|
||||||
|
main();
|
||||||
|
} else {
|
||||||
|
loop{
|
||||||
|
println!("select episode 1-{}: ", ep_range);
|
||||||
|
let mut ep_num: usize = usize::MAX;
|
||||||
|
while ep_num == usize::max_value() || ep_num >= ep_range as usize {
|
||||||
|
ep_num = int_input("Enter episode number: ");
|
||||||
|
if ep_num >= ep_range as usize {
|
||||||
|
println!("Invalid episode number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let link = anime_link(title, ep_num as u64);
|
||||||
|
open_video(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,7 +66,7 @@ pub fn anime_ep_range(anime_name: &str) -> u16 {
|
|||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn anime_link(title: &str, ep: u16) -> (String, String) {
|
pub fn anime_link(title: &str, ep: u64) -> (String, String) {
|
||||||
let url = format!("https://animixplay.to/v1/{}", title);
|
let url = format!("https://animixplay.to/v1/{}", title);
|
||||||
let html = get_anime_html(&url);
|
let html = get_anime_html(&url);
|
||||||
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap();
|
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap();
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ pub fn int_input(prompt: &str) -> usize {
|
|||||||
io::stdin()
|
io::stdin()
|
||||||
.read_line(&mut input)
|
.read_line(&mut input)
|
||||||
.expect("Error reading from STDIN");
|
.expect("Error reading from STDIN");
|
||||||
input.trim().parse::<usize>().unwrap()
|
//try to parse the input as usize else return max usize
|
||||||
|
match input.trim().parse::<usize>() {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(_) => {
|
||||||
|
usize::max_value()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn u16_input(prompt: &str) -> u16 {
|
pub fn u16_input(prompt: &str) -> u16 {
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ pub mod menu;
|
|||||||
pub mod open_text;
|
pub mod open_text;
|
||||||
pub mod scraper;
|
pub mod scraper;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
|
pub mod ln;
|
||||||
|
|||||||
23
src/ln/ln.rs
Normal file
23
src/ln/ln.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use crate::{search_ln,chapter_selector,get_full_text,open_bat};
|
||||||
|
pub fn ln(){
|
||||||
|
let ln_url = search_ln();
|
||||||
|
let mut selected_page = 1;
|
||||||
|
loop {
|
||||||
|
//make empty tuple called chapter_url with (String, u32, u32)
|
||||||
|
let chapter_url = chapter_selector(&ln_url, selected_page);
|
||||||
|
selected_page = chapter_url.1;
|
||||||
|
let full_text = get_full_text(&chapter_url.0);
|
||||||
|
//write full_text to file called temp.txt
|
||||||
|
let mut file = File::create("/tmp/log_e").expect("Unable to create file");
|
||||||
|
file.write_all(full_text.as_bytes())
|
||||||
|
.expect("Unable to write to file");
|
||||||
|
//close file
|
||||||
|
file.sync_all().expect("Unable to sync file");
|
||||||
|
//open temp.txt in cat for user to read
|
||||||
|
let _com = open_bat();
|
||||||
|
print!("\x1B[2J\x1B[1;1H");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
src/main.rs
63
src/main.rs
@@ -1,7 +1,6 @@
|
|||||||
use std::fs::File;
|
use crate::anime::anime::anime_stream;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use crate::anime::scraper::{anime_ep_range, anime_link, anime_names};
|
use crate::anime::scraper::{anime_ep_range, anime_link, anime_names};
|
||||||
|
use crate::ln::ln::ln;
|
||||||
use crate::ln::menu::chapter_selector;
|
use crate::ln::menu::chapter_selector;
|
||||||
use crate::ln::open_text::open_bat;
|
use crate::ln::open_text::open_bat;
|
||||||
use crate::ln::scraper::get_full_text;
|
use crate::ln::scraper::get_full_text;
|
||||||
@@ -31,63 +30,9 @@ fn main() {
|
|||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
if _arg == "l" {
|
if _arg == "l" {
|
||||||
let ln_url = search_ln();
|
ln();
|
||||||
let mut selected_page = 1;
|
|
||||||
loop {
|
|
||||||
//make empty tuple called chapter_url with (String, u32, u32)
|
|
||||||
let chapter_url = chapter_selector(&ln_url, selected_page);
|
|
||||||
selected_page = chapter_url.1;
|
|
||||||
let full_text = get_full_text(&chapter_url.0);
|
|
||||||
//write full_text to file called temp.txt
|
|
||||||
let mut file = File::create("/tmp/log_e").expect("Unable to create file");
|
|
||||||
file.write_all(full_text.as_bytes())
|
|
||||||
.expect("Unable to write to file");
|
|
||||||
//close file
|
|
||||||
file.sync_all().expect("Unable to sync file");
|
|
||||||
//open temp.txt in cat for user to read
|
|
||||||
let _com = open_bat();
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
}
|
|
||||||
} else if _arg == "a" {
|
} else if _arg == "a" {
|
||||||
let query = if std::env::args().len() > 2 {
|
anime_stream()
|
||||||
std::env::args().nth(2).unwrap()
|
|
||||||
} else {
|
|
||||||
string_input("Enter query: ")
|
|
||||||
};
|
|
||||||
let anime_list = anime_names(&query);
|
|
||||||
let mut count = 0;
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
anime_list.iter().for_each(|anime| {
|
|
||||||
if count % 2 == 0 {
|
|
||||||
println!(
|
|
||||||
"({})\t{}",
|
|
||||||
format_args!("{}", count.to_string().blue()),
|
|
||||||
format_args!("{}", anime.blue())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"({})\t{}",
|
|
||||||
format_args!("{}", count.to_string().yellow()),
|
|
||||||
format_args!("{}", anime.yellow())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
count += 1;
|
|
||||||
});
|
|
||||||
let anime_num = int_input("Enter anime number: ");
|
|
||||||
let title = &anime_list[anime_num];
|
|
||||||
let ep_range = anime_ep_range(title);
|
|
||||||
// if there is only one episode, then don't ask user to choose episode
|
|
||||||
if ep_range == 1 {
|
|
||||||
let link = anime_link(title, 1);
|
|
||||||
open_video(link);
|
|
||||||
main();
|
|
||||||
} else {
|
|
||||||
println!("select episode 1-{}: ", ep_range);
|
|
||||||
let ep_num = u16_input("Enter episode number: ");
|
|
||||||
let link = anime_link(title, ep_num);
|
|
||||||
open_video(link);
|
|
||||||
main();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
println!("Invalid argument");
|
println!("Invalid argument");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user