mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 12:50:32 +00:00
Compare commits
5 Commits
newbee1905
...
consumet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dc4f4d6fe | ||
|
|
d22c9e6818 | ||
|
|
676edb1d98 | ||
|
|
21f81cb68d | ||
|
|
7b605f40b8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
test.json
|
||||||
|
|||||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -629,6 +629,7 @@ dependencies = [
|
|||||||
"crossterm 0.24.0",
|
"crossterm 0.24.0",
|
||||||
"dirs",
|
"dirs",
|
||||||
"isahc",
|
"isahc",
|
||||||
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
"rust_cast",
|
"rust_cast",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ crossterm = "0.24.0"
|
|||||||
unicode-width = "0.1.9"
|
unicode-width = "0.1.9"
|
||||||
rust_cast = "0.17.0"
|
rust_cast = "0.17.0"
|
||||||
viuer = { version = "0.6", features = ["sixel"] }
|
viuer = { version = "0.6", features = ["sixel"] }
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
|||||||
@@ -3,43 +3,39 @@ use isahc::{ReadResponseExt, Request, RequestExt};
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
use crate::helpers::{fixing_text::htmlise, scraper};
|
||||||
|
|
||||||
//use serde_json::json;
|
//use serde_json::json;
|
||||||
|
|
||||||
pub fn search_anime(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
pub fn search_anime(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.uri(format!(
|
.uri(format!(
|
||||||
"https://api.consumet.org/meta/anilist/{}",
|
"https://api.consumet.org/meta/anilist/{}",
|
||||||
query
|
htmlise(query)
|
||||||
.replace(" ", "%20")
|
|
||||||
.replace(":", "%3A")
|
|
||||||
.replace("!", "%21")
|
|
||||||
.replace("?", "%3F")
|
|
||||||
.replace("'", "%27")
|
|
||||||
))
|
))
|
||||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
"user-agent",
|
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
|
||||||
)
|
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let json = req.send().unwrap().text().unwrap();
|
let json = req.send().unwrap().text().unwrap();
|
||||||
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
let mut titles = Vec::new();
|
let mut titles = Vec::new();
|
||||||
let mut ids = Vec::new();
|
let mut ids = Vec::new();
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
for i in 0..json["results"].as_array().unwrap().len() {
|
|
||||||
|
for anime in json["results"].as_array().unwrap().iter() {
|
||||||
titles.push(
|
titles.push(
|
||||||
json["results"][i]["title"]["userPreferred"]
|
anime["title"]["userPreferred"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
ids.push(json["results"][i]["id"].as_str().unwrap().to_string());
|
ids.push(anime["id"].as_str().unwrap().to_string());
|
||||||
//convert ids to i32
|
images.push(anime["image"].as_str().unwrap().to_string());
|
||||||
images.push(json["results"][i]["image"].as_str().unwrap().to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(ids, titles, images)
|
(ids, titles, images)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,19 +46,18 @@ pub fn get_episodes(id: &i32, provider: &str) -> (Vec<String>, Vec<String>) {
|
|||||||
id, provider
|
id, provider
|
||||||
))
|
))
|
||||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
"user-agent",
|
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
|
||||||
)
|
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let json = req.send().unwrap().text().unwrap();
|
let json = req.send().unwrap().text().unwrap();
|
||||||
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
let mut titles = Vec::new();
|
let mut titles = Vec::new();
|
||||||
let mut ids = Vec::new();
|
let mut ids = Vec::new();
|
||||||
for i in 0..json["episodes"].as_array().unwrap().len() {
|
|
||||||
titles.push(json["episodes"][i]["title"].as_str().unwrap().to_string());
|
for episode in json["episodes"].as_array().unwrap().iter() {
|
||||||
ids.push(json["episodes"][i]["id"].as_str().unwrap().to_string());
|
titles.push(episode["title"].as_str().unwrap().to_string());
|
||||||
|
ids.push(episode["id"].as_str().unwrap().to_string());
|
||||||
}
|
}
|
||||||
(titles, ids)
|
(titles, ids)
|
||||||
}
|
}
|
||||||
@@ -74,33 +69,31 @@ pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) {
|
|||||||
ep_id, provider
|
ep_id, provider
|
||||||
))
|
))
|
||||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header("user-agent", *scraper::USER_AGENT)
|
||||||
"user-agent",
|
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
|
||||||
)
|
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let json = req.send().unwrap().text().unwrap();
|
let json = req.send().unwrap().text().unwrap();
|
||||||
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
std::fs::write("test.json", json.to_string()).unwrap();
|
std::fs::write("test.json", json.to_string()).unwrap();
|
||||||
|
|
||||||
let mut subtitle = String::new();
|
let mut subtitle = String::new();
|
||||||
let _error_vec = Vec::new();
|
let _error_vec = Vec::new();
|
||||||
|
|
||||||
let sub_array = json["subtitles"].as_array().unwrap_or(&_error_vec);
|
let sub_array = json["subtitles"].as_array().unwrap_or(&_error_vec);
|
||||||
for i in 0..sub_array.len() {
|
|
||||||
|
for sub in sub_array.iter() {
|
||||||
//set subtitle to lang = English
|
//set subtitle to lang = English
|
||||||
if json["subtitles"][i]["lang"].as_str().unwrap_or("null") == "English" {
|
if sub["lang"].as_str().unwrap_or("null") == "English" {
|
||||||
subtitle = json["subtitles"][i]["url"]
|
subtitle = sub["url"].as_str().unwrap_or("null").to_string();
|
||||||
.as_str()
|
|
||||||
.unwrap_or("null")
|
|
||||||
.to_string();
|
|
||||||
// add \ before the first : in the url
|
// add \ before the first : in the url
|
||||||
subtitle = subtitle.replace(":", "\\:");
|
subtitle = subtitle.replace(":", "\\:");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut highest_quality = 0;
|
let mut highest_quality = 0;
|
||||||
for i in 0..json["sources"].as_array().unwrap().len() {
|
for source in json["sources"].as_array().unwrap().iter() {
|
||||||
let quality = json["sources"][i]["quality"]
|
let quality = source["quality"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace("p", "")
|
.replace("p", "")
|
||||||
@@ -108,10 +101,10 @@ pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) {
|
|||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if quality > highest_quality {
|
if quality > highest_quality {
|
||||||
highest_quality = quality;
|
highest_quality = quality;
|
||||||
url = json["sources"][i]["url"].as_str().unwrap().to_string();
|
url = source["url"].as_str().unwrap().to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(url.to_string(), subtitle)
|
(url, subtitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_image(url: &str, path: &str) {
|
pub fn get_image(url: &str, path: &str) {
|
||||||
|
|||||||
@@ -59,3 +59,12 @@ pub fn fix_html_encoding(ln_text: &Vec<String>) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
ln_text_new
|
ln_text_new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn htmlise(query: String) -> String {
|
||||||
|
query
|
||||||
|
.replace(" ", "%20")
|
||||||
|
.replace(":", "%3A")
|
||||||
|
.replace("!", "%21")
|
||||||
|
.replace("?", "%3F")
|
||||||
|
.replace("'", "%27")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod fixing_text;
|
pub mod fixing_text;
|
||||||
|
pub mod scraper;
|
||||||
pub mod take_input;
|
pub mod take_input;
|
||||||
|
|||||||
4
src/helpers/scraper.rs
Normal file
4
src/helpers/scraper.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
lazy_static! {
|
||||||
|
pub static ref USER_AGENT: &'static str =
|
||||||
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0";
|
||||||
|
}
|
||||||
30
src/main.rs
30
src/main.rs
@@ -3,6 +3,9 @@ mod helpers;
|
|||||||
mod ln;
|
mod ln;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
|
||||||
use anime::anime::anime_ui;
|
use anime::anime::anime_ui;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
//use ln::ui::ln_ui;
|
//use ln::ui::ln_ui;
|
||||||
@@ -11,6 +14,7 @@ use ln::ln::ln_ui;
|
|||||||
use crate::anime::trackers::*;
|
use crate::anime::trackers::*;
|
||||||
use crate::get_token;
|
use crate::get_token;
|
||||||
use crate::helpers::take_input::{int_input, string_input};
|
use crate::helpers::take_input::{int_input, string_input};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut help = false;
|
let mut help = false;
|
||||||
let mut anime = false;
|
let mut anime = false;
|
||||||
@@ -106,25 +110,19 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
|
println!("anime:\t\t{}\n", format_args!("{}", "-a --anime".red()));
|
||||||
//print blank line
|
//print blank line
|
||||||
println!("");
|
|
||||||
println!(
|
println!(
|
||||||
"cast:\t\t{}",
|
"cast:\t\t{}\n",
|
||||||
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
|
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
|
||||||
);
|
);
|
||||||
println!("");
|
println!("light novel:\t{}\n", format_args!("{}", "-l --ln".red()));
|
||||||
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
println!("chapter:\t{}\n", format_args!("{}", "-c --chapter".red()));
|
||||||
//print blank line
|
|
||||||
println!("");
|
|
||||||
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
"after this^^^ argument you can enter a chapter number".green()
|
"after this^^^ argument you can enter a chapter number".green()
|
||||||
);
|
);
|
||||||
println!("{}", "for exaple kami -c 200");
|
println!("{}", "for exaple kami -c 200\n");
|
||||||
//print blank line
|
|
||||||
println!("");
|
|
||||||
println!("provider:\t{}", format_args!("{}", "-r --provider".red()));
|
println!("provider:\t{}", format_args!("{}", "-r --provider".red()));
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
@@ -138,8 +136,11 @@ fn print_help() {
|
|||||||
"if the -r argument is not used it will default to {}",
|
"if the -r argument is not used it will default to {}",
|
||||||
"zoro".green()
|
"zoro".green()
|
||||||
);
|
);
|
||||||
println!("the providers are {} or {}", "gogo".green(), "zoro".green());
|
println!(
|
||||||
println!("");
|
"the providers are {} or {}\n",
|
||||||
|
"gogo".green(),
|
||||||
|
"zoro".green()
|
||||||
|
);
|
||||||
println!("reader:\t\t{}", format_args!("{}", "-R --reader".red()));
|
println!("reader:\t\t{}", format_args!("{}", "-R --reader".red()));
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
@@ -153,8 +154,7 @@ fn print_help() {
|
|||||||
"if the -R argument is not used it will default to {}",
|
"if the -R argument is not used it will default to {}",
|
||||||
"bat".green()
|
"bat".green()
|
||||||
);
|
);
|
||||||
println!("the readers are {} or {}", "bat".green(), "glow".green());
|
println!("the readers are {} or {}\n", "bat".green(), "glow".green());
|
||||||
println!("");
|
|
||||||
println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
|
println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
|
||||||
//kill the program
|
//kill the program
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|||||||
@@ -103,6 +103,24 @@ impl<'a> KamiApp for App {
|
|||||||
terminal.draw(|f| self.ui(f))?;
|
terminal.draw(|f| self.ui(f))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
if let Event::Key(key) = event::read()? {
|
||||||
|
fn match_anime_list(this: &mut App, selected: Option<usize>) {
|
||||||
|
match selected {
|
||||||
|
Some(0) => match this.animes.2.len() {
|
||||||
|
0 => {
|
||||||
|
_ = 0;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
this.image = this.animes.2[selected.unwrap()].clone();
|
||||||
|
this.change_image();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(std::usize::MAX) => _ = 0,
|
||||||
|
_ => {
|
||||||
|
this.image = this.animes.2[selected.unwrap()].clone();
|
||||||
|
this.change_image();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
match self.input_mode {
|
match self.input_mode {
|
||||||
InputMode::Normal => match key.code {
|
InputMode::Normal => match key.code {
|
||||||
KeyCode::Char('i') => {
|
KeyCode::Char('i') => {
|
||||||
@@ -120,8 +138,7 @@ impl<'a> KamiApp for App {
|
|||||||
false => {
|
false => {
|
||||||
self.messages.next();
|
self.messages.next();
|
||||||
let selected = self.messages.state.selected();
|
let selected = self.messages.state.selected();
|
||||||
self.image = self.animes.2[selected.unwrap()].clone();
|
match_anime_list(self, selected);
|
||||||
self.change_image();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Char('j') => match ep_select {
|
KeyCode::Char('j') => match ep_select {
|
||||||
@@ -131,8 +148,7 @@ impl<'a> KamiApp for App {
|
|||||||
false => {
|
false => {
|
||||||
self.messages.next();
|
self.messages.next();
|
||||||
let selected = self.messages.state.selected();
|
let selected = self.messages.state.selected();
|
||||||
self.image = self.animes.2[selected.unwrap()].clone();
|
match_anime_list(self, selected)
|
||||||
self.change_image();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Up => match ep_select {
|
KeyCode::Up => match ep_select {
|
||||||
@@ -142,8 +158,7 @@ impl<'a> KamiApp for App {
|
|||||||
false => {
|
false => {
|
||||||
self.messages.previous();
|
self.messages.previous();
|
||||||
let selected = self.messages.state.selected();
|
let selected = self.messages.state.selected();
|
||||||
self.image = self.animes.2[selected.unwrap()].clone();
|
match_anime_list(self, selected)
|
||||||
self.change_image();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Char('k') => match ep_select {
|
KeyCode::Char('k') => match ep_select {
|
||||||
@@ -153,8 +168,7 @@ impl<'a> KamiApp for App {
|
|||||||
false => {
|
false => {
|
||||||
self.messages.previous();
|
self.messages.previous();
|
||||||
let selected = self.messages.state.selected();
|
let selected = self.messages.state.selected();
|
||||||
self.image = self.animes.2[selected.unwrap()].clone();
|
match_anime_list(self, selected)
|
||||||
self.change_image();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//if KeyCode::Enter => {
|
//if KeyCode::Enter => {
|
||||||
|
|||||||
Reference in New Issue
Block a user