mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 12:50:32 +00:00
Compare commits
12 Commits
img
...
main-consu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf399d4a7f | ||
|
|
9f0df00b19 | ||
|
|
03166deb7e | ||
|
|
6fadcadba1 | ||
|
|
2dea2c86ec | ||
|
|
330eb6239a | ||
|
|
652548057b | ||
|
|
edbebf4b4e | ||
|
|
634643657e | ||
|
|
f435f290ac | ||
|
|
97fe7e30a7 | ||
|
|
2c3d883f1f |
@@ -1,8 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
get_an_history, get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
get_an_history, get_an_progress, get_user_anime_progress, update_anime_progress,
|
||||||
write_an_progress,
|
write_an_progress,
|
||||||
};
|
};
|
||||||
use crate::{get_anime_link, get_animes, get_image};
|
use crate::{get_episode_link, get_episodes, get_image, search_anime};
|
||||||
use crate::{open_cast, open_video};
|
use crate::{open_cast, open_video};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
@@ -22,8 +22,6 @@ use tui::{
|
|||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use viuer::{print_from_file, terminal_size, Config};
|
use viuer::{print_from_file, terminal_size, Config};
|
||||||
|
|
||||||
use super::scraper::get_anime_info;
|
|
||||||
|
|
||||||
enum InputMode {
|
enum InputMode {
|
||||||
Normal,
|
Normal,
|
||||||
Editing,
|
Editing,
|
||||||
@@ -90,8 +88,8 @@ struct App {
|
|||||||
input_mode: InputMode,
|
input_mode: InputMode,
|
||||||
/// History of recorded messages
|
/// History of recorded messages
|
||||||
messages: StatefulList<String>,
|
messages: StatefulList<String>,
|
||||||
|
episodes: (Vec<String>, Vec<String>),
|
||||||
title: String,
|
title: String,
|
||||||
link: String,
|
|
||||||
ep: u64,
|
ep: u64,
|
||||||
progress: i32,
|
progress: i32,
|
||||||
anime_id: i32,
|
anime_id: i32,
|
||||||
@@ -108,8 +106,8 @@ impl<'a> App {
|
|||||||
image: String::new(),
|
image: String::new(),
|
||||||
input_mode: InputMode::Normal,
|
input_mode: InputMode::Normal,
|
||||||
messages: StatefulList::with_items(Vec::new()),
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
|
episodes: (Vec::new(), Vec::new()),
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
link: String::new(),
|
|
||||||
ep: 0,
|
ep: 0,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
anime_id: 0,
|
anime_id: 0,
|
||||||
@@ -257,9 +255,14 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
app.progress = 0;
|
app.progress = 0;
|
||||||
let selected = app.messages.state.selected();
|
let selected = app.messages.state.selected();
|
||||||
app.title = app.messages.items[selected.unwrap()].clone();
|
app.title = app.messages.items[selected.unwrap()].clone();
|
||||||
app.link = app.animes.0[selected.unwrap()].clone();
|
app.anime_id = app.animes.0[selected.unwrap()]
|
||||||
let anime_info = get_anime_info(&app.animes.0[selected.unwrap()]);
|
.clone()
|
||||||
app.anime_id = get_anime_id(anime_info.0);
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
app.episodes = get_episodes(
|
||||||
|
&app.animes.0[selected.unwrap()].parse::<i32>().unwrap(),
|
||||||
|
&app.provider,
|
||||||
|
);
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
app.progress = get_an_progress(&app.title) as i32;
|
app.progress = get_an_progress(&app.title) as i32;
|
||||||
@@ -269,27 +272,41 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
get_user_anime_progress(app.anime_id, app.token.as_str());
|
get_user_anime_progress(app.anime_id, app.token.as_str());
|
||||||
app.messages.state.select(Some(app.progress as usize));
|
app.messages.state.select(Some(app.progress as usize));
|
||||||
}
|
}
|
||||||
if anime_info.1 == 1 {
|
if app.episodes.0.len() == 1 {
|
||||||
let link = get_anime_link(&app.link, 1);
|
let link = get_episode_link(&app.episodes.1[0], &app.provider);
|
||||||
if !app.cast.0 {
|
if !app.cast.0 {
|
||||||
open_video((link, format!("{} Episode 1", &app.title)));
|
open_video((
|
||||||
|
link.0,
|
||||||
|
format!("{} Episode 1", &app.title),
|
||||||
|
link.1,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
open_cast(
|
open_cast(
|
||||||
(link, format!("{} Episode 1", &app.title)),
|
(link.1, format!("{} Episode 1", &app.title)),
|
||||||
&app.cast.1,
|
&app.cast.1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let selected = app.messages.state.selected();
|
let selected = app.messages.state.selected();
|
||||||
let image_url = app.animes.2[selected.unwrap()].clone();
|
let image_url = app.animes.2[selected.unwrap()].clone();
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &1);
|
write_an_progress(
|
||||||
|
(&app.title, &app.anime_id.to_string(), &image_url),
|
||||||
|
&1,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
update_anime_progress(app.anime_id, 1, app.token.as_str());
|
update_anime_progress(app.anime_id, 1, app.token.as_str());
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &1);
|
write_an_progress(
|
||||||
|
(&app.title, &app.anime_id.to_string(), &image_url),
|
||||||
|
&1,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for ep in 1..anime_info.1 + 1 {
|
for ep in 1..app.episodes.1.len() + 1 {
|
||||||
app.messages.push(format!("Episode {}", ep));
|
app.messages.push(format!(
|
||||||
|
"Episode {}: {}",
|
||||||
|
ep,
|
||||||
|
app.episodes.0[ep - 1]
|
||||||
|
));
|
||||||
}
|
}
|
||||||
ep_select = true;
|
ep_select = true;
|
||||||
}
|
}
|
||||||
@@ -301,28 +318,43 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
.nth(selected.unwrap())
|
.nth(selected.unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace("Episode ", "")
|
.replace("Episode ", "")
|
||||||
|
.split(":")
|
||||||
|
.collect::<Vec<&str>>()[0]
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let link = get_anime_link(&app.link, app.ep);
|
let link = get_episode_link(
|
||||||
|
&app.episodes.1[app.ep as usize - 1],
|
||||||
|
&app.provider,
|
||||||
|
);
|
||||||
if !app.cast.0 {
|
if !app.cast.0 {
|
||||||
open_video((link, format!("{} Episode {}", &app.title, app.ep)));
|
open_video((
|
||||||
|
link.0,
|
||||||
|
format!("{} Episode {}", &app.title, app.ep),
|
||||||
|
link.1,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
open_cast(
|
open_cast(
|
||||||
(link, format!("{} Episode {}", &app.title, app.ep)),
|
(link.0, format!("{} Episode {}", &app.title, app.ep)),
|
||||||
&app.cast.1,
|
&app.cast.1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let image_url = &app.image;
|
let image_url = &app.image;
|
||||||
if app.ep > app.progress as u64 {
|
if app.ep > app.progress as u64 {
|
||||||
if app.token == "local" || app.anime_id == 0 {
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
write_an_progress(
|
||||||
|
(&app.title, &app.anime_id.to_string(), &image_url),
|
||||||
|
&app.ep,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
update_anime_progress(
|
update_anime_progress(
|
||||||
app.anime_id,
|
app.anime_id,
|
||||||
app.ep as usize,
|
app.ep as usize,
|
||||||
app.token.as_str(),
|
app.token.as_str(),
|
||||||
);
|
);
|
||||||
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
write_an_progress(
|
||||||
|
(&app.title, &app.anime_id.to_string(), &image_url),
|
||||||
|
&app.ep,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
app.progress = app.ep as i32;
|
app.progress = app.ep as i32;
|
||||||
}
|
}
|
||||||
@@ -333,7 +365,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
InputMode::Editing => match key.code {
|
InputMode::Editing => match key.code {
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
//push app.input into app.messages with '
|
//push app.input into app.messages with '
|
||||||
app.animes = get_animes(app.input.drain(..).collect());
|
app.animes = search_anime(app.input.drain(..).collect());
|
||||||
app.messages.items.clear();
|
app.messages.items.clear();
|
||||||
for anime in &app.animes.1 {
|
for anime in &app.animes.1 {
|
||||||
app.messages.push(anime.to_string());
|
app.messages.push(anime.to_string());
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ use rust_cast::{
|
|||||||
};
|
};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn open_video(link: (String, String)) {
|
pub fn open_video(link: (String, String, String)) {
|
||||||
|
if link.2 == "null" {
|
||||||
let title = link.1;
|
let title = link.1;
|
||||||
let title = title.replace("-", " ");
|
let title = title.replace("-", " ");
|
||||||
let arg: String = format!("--force-media-title={}", title);
|
let arg: String = format!("--force-media-title={}", title);
|
||||||
@@ -17,7 +18,18 @@ pub fn open_video(link: (String, String)) {
|
|||||||
.arg(arg)
|
.arg(arg)
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to open mpv");
|
.expect("failed to open mpv");
|
||||||
|
} else {
|
||||||
|
let title = link.1;
|
||||||
|
let title = title.replace("-", " ");
|
||||||
|
let arg1: String = format!("--force-media-title={}", title);
|
||||||
|
let arg2: String = format!("--sub-files={}", link.2);
|
||||||
|
let _ = std::process::Command::new("mpv")
|
||||||
|
.arg(link.0)
|
||||||
|
.arg(arg1)
|
||||||
|
.arg(arg2)
|
||||||
|
.output()
|
||||||
|
.expect("failed to open mpv");
|
||||||
|
}
|
||||||
// clear terminal
|
// clear terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
use isahc::config::Configurable;
|
use isahc::config::Configurable;
|
||||||
use isahc::{ReadResponseExt, Request, RequestExt};
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
use regex::Regex;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
//use serde_json::json;
|
//use serde_json::json;
|
||||||
|
|
||||||
pub fn get_anime_html(url: &str) -> String {
|
pub fn search_anime(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.uri(url)
|
.uri(format!(
|
||||||
|
"https://api.consumet.org/meta/anilist/{}",
|
||||||
|
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",
|
"user-agent",
|
||||||
@@ -16,74 +23,95 @@ pub fn get_anime_html(url: &str) -> String {
|
|||||||
)
|
)
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
req.send().unwrap().text().unwrap()
|
let json = req.send().unwrap().text().unwrap();
|
||||||
}
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
let mut titles = Vec::new();
|
||||||
pub fn get_post(id: &str) -> String {
|
let mut ids = Vec::new();
|
||||||
let resp = Request::builder()
|
let mut images = Vec::new();
|
||||||
.method("POST")
|
for i in 0..json["results"].as_array().unwrap().len() {
|
||||||
.uri("https://yugen.to/api/embed/")
|
titles.push(
|
||||||
.header("x-requested-with", "XMLHttpRequest")
|
json["results"][i]["title"]["userPreferred"]
|
||||||
.body(id)
|
.as_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.send()
|
.to_string(),
|
||||||
.unwrap()
|
|
||||||
.text();
|
|
||||||
let resp: String = resp.as_ref().unwrap().to_string();
|
|
||||||
resp
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_animes(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
|
||||||
let query = query.replace(" ", "+");
|
|
||||||
let html = get_anime_html(&format!("https://yugen.to/search/?q={}", query));
|
|
||||||
let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap();
|
|
||||||
let mut animes_links = Vec::new();
|
|
||||||
for cap in re.captures_iter(&html) {
|
|
||||||
animes_links.push(cap[1].to_string());
|
|
||||||
}
|
|
||||||
let re = Regex::new(r#"/" title="([^"]*)""#).unwrap();
|
|
||||||
let mut animes_names = Vec::new();
|
|
||||||
for cap in re.captures_iter(&html) {
|
|
||||||
animes_names.push(cap[1].to_string());
|
|
||||||
}
|
|
||||||
let re = Regex::new(r#"data-src="([^"]*)"#).unwrap();
|
|
||||||
let mut animes_images = Vec::new();
|
|
||||||
for cap in re.captures_iter(&html) {
|
|
||||||
animes_images.push(cap[1].to_string());
|
|
||||||
}
|
|
||||||
(animes_links, animes_names, animes_images)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_anime_info(url: &str) -> (i32, u16) {
|
|
||||||
let url = format!("https://yugen.to{}watch", url);
|
|
||||||
let html = get_anime_html(&url);
|
|
||||||
//print html and exit
|
|
||||||
let re = Regex::new(r#""mal_id":(\d*)"#).unwrap();
|
|
||||||
let mal_id = re.captures(&html).unwrap()[1].parse().unwrap();
|
|
||||||
let re =
|
|
||||||
Regex::new(r#"Episodes</div><span class="description" style="font-size: \d*px;">(\d*)"#)
|
|
||||||
.unwrap();
|
|
||||||
let episodes = re.captures(&html).unwrap()[1].parse().unwrap();
|
|
||||||
(mal_id, episodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_anime_link(url: &str, episode: u64) -> String {
|
|
||||||
let url = &format!(
|
|
||||||
"https://yugen.to/watch{}{}/",
|
|
||||||
url.replace("/anime", ""),
|
|
||||||
episode
|
|
||||||
);
|
);
|
||||||
let html = get_anime_html(url);
|
|
||||||
let re = Regex::new(r#"/e/([^/]*)"#).unwrap();
|
ids.push(json["results"][i]["id"].as_str().unwrap().to_string());
|
||||||
let capture = re.captures(&html).unwrap();
|
//convert ids to i32
|
||||||
let id = &capture[1];
|
images.push(json["results"][i]["image"].as_str().unwrap().to_string());
|
||||||
let id = format!("id={}%3D&ac=0", id);
|
}
|
||||||
let json = get_post(&id);
|
(ids, titles, images)
|
||||||
let re = Regex::new(r#"hls": \["(.*)","#).unwrap();
|
}
|
||||||
let capture = re.captures(&json).unwrap();
|
|
||||||
let link = &capture[1];
|
pub fn get_episodes(id: &i32, provider: &str) -> (Vec<String>, Vec<String>) {
|
||||||
//return the link
|
let req = Request::builder()
|
||||||
link.to_string()
|
.uri(format!(
|
||||||
|
"https://api.consumet.org/meta/anilist/info/{}?provider={}",
|
||||||
|
id, provider
|
||||||
|
))
|
||||||
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
|
.header(
|
||||||
|
"user-agent",
|
||||||
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
||||||
|
)
|
||||||
|
.body(())
|
||||||
|
.unwrap();
|
||||||
|
let json = req.send().unwrap().text().unwrap();
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
let mut titles = 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());
|
||||||
|
ids.push(json["episodes"][i]["id"].as_str().unwrap().to_string());
|
||||||
|
}
|
||||||
|
(titles, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) {
|
||||||
|
let req = Request::builder()
|
||||||
|
.uri(format!(
|
||||||
|
"https://api.consumet.org/meta/anilist/watch/{}?provider={}",
|
||||||
|
ep_id, provider
|
||||||
|
))
|
||||||
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
|
.header(
|
||||||
|
"user-agent",
|
||||||
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
||||||
|
)
|
||||||
|
.body(())
|
||||||
|
.unwrap();
|
||||||
|
let json = req.send().unwrap().text().unwrap();
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||||
|
let mut url = String::new();
|
||||||
|
std::fs::write("test.json", json.to_string()).unwrap();
|
||||||
|
let mut subtitle = String::new();
|
||||||
|
let _error_vec = Vec::new();
|
||||||
|
let sub_array = json["subtitles"].as_array().unwrap_or(&_error_vec);
|
||||||
|
for i in 0..sub_array.len() {
|
||||||
|
//set subtitle to lang = English
|
||||||
|
if json["subtitles"][i]["lang"].as_str().unwrap_or("null") == "English" {
|
||||||
|
subtitle = json["subtitles"][i]["url"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or("null")
|
||||||
|
.to_string();
|
||||||
|
// add \ before the first : in the url
|
||||||
|
subtitle = subtitle.replace(":", "\\:");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut highest_quality = 0;
|
||||||
|
for i in 0..json["sources"].as_array().unwrap().len() {
|
||||||
|
let quality = json["sources"][i]["quality"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace("p", "")
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap_or(0);
|
||||||
|
if quality > highest_quality {
|
||||||
|
highest_quality = quality;
|
||||||
|
url = json["sources"][i]["url"].as_str().unwrap().to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(url.to_string(), subtitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_image(url: &str, path: &str) {
|
pub fn get_image(url: &str, path: &str) {
|
||||||
|
|||||||
@@ -40,54 +40,6 @@ pub fn get_token() -> String {
|
|||||||
token
|
token
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_anime_id(mal_id: i32) -> i32 {
|
|
||||||
const QUERY: &str = "
|
|
||||||
query ($id: Int, $search: Int) {
|
|
||||||
Media (id: $id, idMal: $search, type: ANIME) {
|
|
||||||
id
|
|
||||||
title {
|
|
||||||
native
|
|
||||||
romaji
|
|
||||||
english
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
";
|
|
||||||
let json = json!({
|
|
||||||
"query": QUERY,
|
|
||||||
"variables": {
|
|
||||||
"search": mal_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let resp = Request::builder()
|
|
||||||
.method("POST")
|
|
||||||
.uri("https://graphql.anilist.co/")
|
|
||||||
.header("Content-Type", "application/json")
|
|
||||||
.header("Accept", "application/json")
|
|
||||||
.body(json.to_string())
|
|
||||||
.unwrap()
|
|
||||||
.send()
|
|
||||||
.unwrap()
|
|
||||||
.text();
|
|
||||||
let regex = regex::Regex::new(r#"id":(.*?),"#).unwrap();
|
|
||||||
let resp: String = resp.as_ref().unwrap().to_string();
|
|
||||||
//if error let id = 0
|
|
||||||
let id = match regex.captures(&resp) {
|
|
||||||
Some(captures) => captures[1].parse::<i32>().unwrap(),
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
// let id = regex
|
|
||||||
// .captures(&resp)
|
|
||||||
// .unwrap()
|
|
||||||
// .get(1)
|
|
||||||
// .unwrap()
|
|
||||||
// .as_str()
|
|
||||||
// .parse::<i32>()
|
|
||||||
// .unwrap();
|
|
||||||
id
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the user id from the token
|
//get the user id from the token
|
||||||
fn get_user_id(token: &str) -> i32 {
|
fn get_user_id(token: &str) -> i32 {
|
||||||
const QUERY: &str = "query {
|
const QUERY: &str = "query {
|
||||||
@@ -264,7 +216,6 @@ pub fn get_an_history() -> (Vec<String>, Vec<String>, Vec<String>) {
|
|||||||
titles.push(key.to_string());
|
titles.push(key.to_string());
|
||||||
links.push(value["link"].as_str().unwrap().to_string());
|
links.push(value["link"].as_str().unwrap().to_string());
|
||||||
images.push(value["image"].as_str().unwrap().to_string());
|
images.push(value["image"].as_str().unwrap().to_string());
|
||||||
println!("{}", value["updated"].as_u64().unwrap());
|
|
||||||
last_updated.push(value["updated"].as_u64().unwrap());
|
last_updated.push(value["updated"].as_u64().unwrap());
|
||||||
}
|
}
|
||||||
let mut indices: Vec<usize> = (0..last_updated.len()).collect();
|
let mut indices: Vec<usize> = (0..last_updated.len()).collect();
|
||||||
|
|||||||
14
src/ln/ln.rs
14
src/ln/ln.rs
@@ -1,4 +1,4 @@
|
|||||||
use crate::ln::open_text::*;
|
use crate::ln::open_text::{open_bat, open_glow};
|
||||||
use crate::ln::scraper::*;
|
use crate::ln::scraper::*;
|
||||||
use crate::ln::tracker::*;
|
use crate::ln::tracker::*;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
@@ -113,7 +113,7 @@ impl<'a> App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
pub fn ln_ui(chapter: u32, reader: String) -> Result<(), Box<dyn Error>> {
|
||||||
// setup terminal
|
// setup terminal
|
||||||
let _ = get_ln_json();
|
let _ = get_ln_json();
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
@@ -130,7 +130,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
|||||||
app.current_page_number = (chapter / 48.0).ceil() as u32;
|
app.current_page_number = (chapter / 48.0).ceil() as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = run_app(&mut terminal, app);
|
let res = run_app(&mut terminal, app, &*reader);
|
||||||
|
|
||||||
// restore terminal
|
// restore terminal
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
@@ -148,7 +148,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App, reader: &str) -> io::Result<()> {
|
||||||
let mut chapter_select = false;
|
let mut chapter_select = false;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@@ -244,7 +244,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
|
|||||||
file.sync_all().expect("Unable to sync file");
|
file.sync_all().expect("Unable to sync file");
|
||||||
};
|
};
|
||||||
terminal.clear()?;
|
terminal.clear()?;
|
||||||
let _ = open_bat();
|
let _ = match reader {
|
||||||
|
"bat" => open_bat(),
|
||||||
|
"glow" => open_glow(),
|
||||||
|
&_ => todo!(),
|
||||||
|
};
|
||||||
write_ln_progress(
|
write_ln_progress(
|
||||||
&app.title,
|
&app.title,
|
||||||
&app.current_page_number,
|
&app.current_page_number,
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ use std::process::{Command, ExitStatus, Stdio};
|
|||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
pub fn open_bat() -> Result<ExitStatus> {
|
pub fn open_bat() -> Result<ExitStatus> {
|
||||||
let termsize::Size {rows: _, cols} = termsize::get().unwrap();
|
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
|
||||||
let mut path = String::new();
|
let mut path = String::new();
|
||||||
if cfg!(target_os = "windows"){
|
if cfg!(target_os = "windows") {
|
||||||
use dirs::home_dir;
|
use dirs::home_dir;
|
||||||
let mut home = format!("{:?}",home_dir()).replace("\\\\","/");
|
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
||||||
home.drain(0..6);
|
home.drain(0..6);
|
||||||
home.drain(home.len()-2..home.len());
|
home.drain(home.len() - 2..home.len());
|
||||||
path = format!("{}/AppData/Roaming/log_e",home).to_string();
|
path = format!("{}/AppData/Roaming/log_e", home).to_string();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
path = "/tmp/log_e".to_string();
|
path = "/tmp/log_e".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,3 +36,36 @@ pub fn open_bat() -> Result<ExitStatus> {
|
|||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_assignments)]
|
||||||
|
pub fn open_glow() -> Result<ExitStatus> {
|
||||||
|
let termsize::Size { rows: _, cols } = termsize::get().unwrap();
|
||||||
|
let mut path = String::new();
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
use dirs::home_dir;
|
||||||
|
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
||||||
|
home.drain(0..6);
|
||||||
|
home.drain(home.len() - 2..home.len());
|
||||||
|
path = format!("{}/AppData/Roaming/log_e", home).to_string();
|
||||||
|
} else {
|
||||||
|
path = "/tmp/log_e".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let soft_wrap = match Command::new("fold")
|
||||||
|
.arg("-s")
|
||||||
|
.arg("-w")
|
||||||
|
.arg((cols - 9).to_string())
|
||||||
|
.arg(path)
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
|
Err(why) => panic!("couldn't spawn wc: {}", why),
|
||||||
|
Ok(soft_wrap) => soft_wrap,
|
||||||
|
};
|
||||||
|
|
||||||
|
Command::new("glow")
|
||||||
|
.arg("-p")
|
||||||
|
.stdin(soft_wrap.stdout.unwrap())
|
||||||
|
.spawn()?
|
||||||
|
.wait()
|
||||||
|
}
|
||||||
|
|||||||
79
src/main.rs
79
src/main.rs
@@ -18,48 +18,62 @@ fn main() {
|
|||||||
//let search = option string
|
//let search = option string
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut provider: String = "gogo".to_string();
|
let mut provider: String = "gogo".to_string();
|
||||||
|
let mut reader: String = "bat".to_string();
|
||||||
let mut cast = (false, "0".to_string());
|
let mut cast = (false, "0".to_string());
|
||||||
for arg in std::env::args() {
|
for arg in std::env::args() {
|
||||||
if arg == "--help" || arg == "-h" {
|
match &*arg {
|
||||||
help = true;
|
"--help" | "-h" => help = true,
|
||||||
}
|
"--anime" | "-a" => anime = true,
|
||||||
if arg == "--anime" || arg == "-a" {
|
"--provider" | "-r" => {
|
||||||
anime = true;
|
|
||||||
}
|
|
||||||
if arg == "--provider" || arg == "-r" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
//get the next argument and see if it is = to gogo of vrv
|
//get the next argument and see if it is = to gogo of vrv
|
||||||
if arg == "vrv" {
|
match arg.as_str() {
|
||||||
provider = "vrv".to_string();
|
"zoro" | "gogoanime" => {
|
||||||
|
provider = arg;
|
||||||
count += 1;
|
count += 1;
|
||||||
} else if arg == "gogo" {
|
}
|
||||||
provider = "gogo".to_string();
|
&_ => provider = "gogoanime".to_string(),
|
||||||
count += 1;
|
|
||||||
} else {
|
|
||||||
provider = "gogo".to_string();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
provider = "vrv".to_string();
|
provider = "zoro".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if arg == "--cast" || arg == "-C" {
|
"--reader" | "-R" => {
|
||||||
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
|
//get the next argument and see if it is = to gogo of vrv
|
||||||
|
match arg.as_str() {
|
||||||
|
"bat" | "glow" => {
|
||||||
|
reader = arg;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
&_ => reader = "bat".to_string(),
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
provider = "glow".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
provider = "gogo".to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
"--cast" | "-C" => {
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
cast = (true, String::from(arg))
|
cast = (true, String::from(arg))
|
||||||
} else {
|
} else {
|
||||||
println!("{}", "please provide a ip address".red())
|
println!("{}", "please provide a ip address".red())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"--ln" | "-l" => ln = true,
|
||||||
if arg == "--ln" || arg == "-l" {
|
"--chapter" | "-c" => {
|
||||||
ln = true;
|
|
||||||
}
|
|
||||||
if arg == "--chapter" || arg == "-c" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
chapter = arg.parse::<u32>().unwrap();
|
chapter = arg.parse::<u32>().unwrap();
|
||||||
} else {
|
} else {
|
||||||
chapter = 0;
|
chapter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
@@ -84,7 +98,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
if ln == true {
|
if ln == true {
|
||||||
//ln_read(&search, chapter);
|
//ln_read(&search, chapter);
|
||||||
_ = ln_ui(chapter);
|
_ = ln_ui(chapter, reader);
|
||||||
} else if anime == true {
|
} else if anime == true {
|
||||||
//anime_stream(search, episode, resume);
|
//anime_stream(search, episode, resume);
|
||||||
|
|
||||||
@@ -122,13 +136,28 @@ fn print_help() {
|
|||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"if no provider is entered it will default to {}",
|
"if no provider is entered it will default to {}",
|
||||||
"vrv".green()
|
"gogo".green()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"if the -r argument is not used it will default to {}",
|
"if the -r argument is not used it will default to {}",
|
||||||
"gogo".green()
|
"zoro".green()
|
||||||
);
|
);
|
||||||
println!("the providers are {} or {}", "gogo".green(), "vrv".green());
|
println!("the providers are {} or {}", "gogoanime".green(), "zoro".green());
|
||||||
|
println!("");
|
||||||
|
println!("reader:\t\t{}", format_args!("{}", "-R --reader".red()));
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
"after this^^^ argument you can enter a reader".green()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"if no reader is entered it will default to {}",
|
||||||
|
"bat".green()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"if the -R argument is not used it will default to {}",
|
||||||
|
"bat".green()
|
||||||
|
);
|
||||||
|
println!("the readers are {} or {}", "bat".green(), "glow".green());
|
||||||
println!("");
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user