mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 12:50:32 +00:00
Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2b4243dd2 | ||
|
|
9f0df00b19 | ||
|
|
03166deb7e | ||
|
|
2dea2c86ec | ||
|
|
330eb6239a | ||
|
|
652548057b | ||
|
|
f435f290ac | ||
|
|
97fe7e30a7 | ||
|
|
e7438cb664 | ||
|
|
2c3d883f1f | ||
|
|
6b58d42af7 | ||
|
|
7fc96dce60 | ||
|
|
d716fa1d49 | ||
|
|
4d0112ed86 | ||
|
|
26a8cb5e77 | ||
|
|
929cca2ace | ||
|
|
cc4f530764 | ||
|
|
b5bac31d64 | ||
|
|
1092bc4f75 | ||
|
|
f39deb5321 | ||
|
|
e22047b142 | ||
|
|
ea91edf8bd | ||
|
|
e2b7f53da1 | ||
|
|
061d2dfb7c | ||
|
|
3abedb7360 | ||
|
|
1fc1b7e867 | ||
|
|
a5f0ef0e40 | ||
|
|
6d09eb7e6b | ||
|
|
ca8c8c12e8 | ||
|
|
52dab31fe3 | ||
|
|
ed0e3dd50f | ||
|
|
abe79ba96f | ||
|
|
8363c57f73 | ||
|
|
857a5daf5a | ||
|
|
e9de97e4da | ||
|
|
1e02417c15 | ||
|
|
d436e69a64 | ||
|
|
115d7e790f | ||
|
|
cc0945e29a | ||
|
|
3ff0a47ff7 | ||
|
|
8ad12ebcca | ||
|
|
c63bb81f40 | ||
|
|
759a8e48b3 | ||
|
|
e025163448 | ||
|
|
ae10585507 | ||
|
|
2e9874b486 | ||
|
|
67eed7353a | ||
|
|
2193956e8b | ||
|
|
ebfb9b8ea6 | ||
|
|
8afe0fad98 | ||
|
|
f5b37da2d1 | ||
|
|
a7ddb5f09d | ||
|
|
2256fd4000 | ||
|
|
20ab508dad | ||
|
|
b67369d568 | ||
|
|
95a6da290c | ||
|
|
8aaeaa756d | ||
|
|
0d2ff78743 | ||
|
|
e79cdb07f5 | ||
|
|
570a8dfc4b | ||
|
|
3361f9ad93 | ||
|
|
3fb4ad1e93 | ||
|
|
2b998923d2 | ||
|
|
180b1dfb32 | ||
|
|
c5fb7b056a | ||
|
|
333b638d06 | ||
|
|
77415b22b4 | ||
|
|
84aa95aa6e | ||
|
|
62de278e8d | ||
|
|
f57e3f2df6 |
919
Cargo.lock
generated
919
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
name = "kami"
|
name = "kami"
|
||||||
author = "mrfluffy-dev"
|
author = "mrfluffy-dev"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
version = "0.5.0"
|
version = "0.6.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@@ -14,3 +14,9 @@ isahc = "1.7.2"
|
|||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
termsize = "0.1.6"
|
termsize = "0.1.6"
|
||||||
dirs = "4.0"
|
dirs = "4.0"
|
||||||
|
serde_json = "1.0.83"
|
||||||
|
tui = "0.18.0"
|
||||||
|
crossterm = "0.24.0"
|
||||||
|
unicode-width = "0.1.9"
|
||||||
|
rust_cast = "0.17.0"
|
||||||
|
viuer = { version = "0.6", features = ["sixel"] }
|
||||||
|
|||||||
21
README.org
21
README.org
@@ -1,15 +1,19 @@
|
|||||||
#+title: Readme
|
#+title: Readme
|
||||||
#+OPTIONS: toc:2
|
#+OPTIONS: toc:2
|
||||||
* Table of content
|
* Table of content
|
||||||
1. [[#Why-use-kami][Why use kami]]
|
1. [[#IMPORTANT][IMPORTANT]]
|
||||||
2. [[#Dependencies][Dependencies]]
|
2. [[#Why-use-kami][Why use kami]]
|
||||||
3. [[#Install][Install]]
|
3. [[#Dependencies][Dependencies]]
|
||||||
|
4. [[#Install][Install]]
|
||||||
- [[#LinuxMac][Linux/mac]]
|
- [[#LinuxMac][Linux/mac]]
|
||||||
- [[#Windows][Windows]]
|
- [[#Windows][Windows]]
|
||||||
4. [[#Honorable-mentions][Honorable mentions]]
|
5. [[#Honorable-mentions][Honorable mentions]]
|
||||||
|
* IMPORTANT
|
||||||
|
remove all contents of ~$HOME/.config/kami/an_progress.json~ new version is not compatibal with old progress file.
|
||||||
* Why use kami
|
* Why use kami
|
||||||
well its a fast and easy way to watch anime and read light novels right in your terminal no need to open a browser.
|
Well its a fast and easy way to watch anime and read light novels right in your terminal no need to open a browser.
|
||||||
Also rust is fast as fuck boiiiii.
|
Also rust is fast as fuck boiiiii.
|
||||||
|
It can keep your anime tracking up to date with anilist.
|
||||||
* Dependencies
|
* Dependencies
|
||||||
1. [[https://github.com/sharkdp/bat][bat]]
|
1. [[https://github.com/sharkdp/bat][bat]]
|
||||||
2. [[https://mpv.io/][mpv]]
|
2. [[https://mpv.io/][mpv]]
|
||||||
@@ -76,11 +80,12 @@ git clone https://github.com/mrfluffy-dev/kami.git && cd kami
|
|||||||
#+begin_src shell
|
#+begin_src shell
|
||||||
cargo build --release
|
cargo build --release
|
||||||
#+end_src
|
#+end_src
|
||||||
7. copy kami to path
|
7. copy kami to path (for this to work, you need to use git bash and you need to run git bash in administrator mode0
|
||||||
#+begin_src
|
#+begin_src
|
||||||
cp target/release/kami.exe /usr/bin/kami
|
cp target/release/kami.exe /usr/bin/kami
|
||||||
#+end_src
|
#+end_src
|
||||||
8. open kami by using ~kami~
|
8. open kami by using ~kami~
|
||||||
* Honorable mentions
|
* Honorable mentions
|
||||||
- [[https://github.com/pystardust/ani-cli][ani-cli]] just a bunch of fucking nice people.
|
- [[https://github.com/pystardust/ani-cli][ani-cli]] Just a bunch of fucking nice people.
|
||||||
- [[https://docs.rs/][rust docs]] honestly its just so useful.
|
- [[https://docs.rs/][rust docs]] Honestly its just so useful.
|
||||||
|
- [[https://github.com/DemonKingSwarn/flix-cli][flix-cli]] For forcing me to make a release.
|
||||||
|
|||||||
@@ -1,93 +1,465 @@
|
|||||||
use crate::main;
|
use crate::{
|
||||||
use crate::open_video;
|
get_an_history, get_an_progress, get_anime_id, get_user_anime_progress, update_anime_progress,
|
||||||
use crate::{anime_ep_range, anime_link, anime_names};
|
write_an_progress,
|
||||||
use crate::{int_input, string_input};
|
};
|
||||||
use colored::Colorize;
|
use crate::{get_anime_link, get_animes, get_image};
|
||||||
//use crate
|
use crate::{open_cast, open_video};
|
||||||
pub fn anime_stream(search: String, episode: u32) {
|
|
||||||
let query = if search != "" {
|
|
||||||
search
|
|
||||||
} else {
|
|
||||||
string_input("Search anime: ")
|
|
||||||
};
|
|
||||||
|
|
||||||
let anime_list = anime_names(&query);
|
use crossterm::{
|
||||||
let mut count = 0;
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
execute,
|
||||||
anime_list.iter().for_each(|anime| {
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
if count % 2 == 0 {
|
};
|
||||||
println!(
|
use std::{error::Error, io};
|
||||||
"({})\t{}",
|
use tui::{
|
||||||
format_args!("{}", count.to_string().blue()),
|
backend::{Backend, CrosstermBackend},
|
||||||
format_args!("{}", anime.blue())
|
layout::{Constraint, Direction, Layout},
|
||||||
);
|
style::{Color, Modifier, Style},
|
||||||
} else {
|
text::{Span, Spans, Text},
|
||||||
println!(
|
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||||
"({})\t{}",
|
Frame, Terminal,
|
||||||
format_args!("{}", count.to_string().yellow()),
|
};
|
||||||
format_args!("{}", anime.yellow())
|
use unicode_width::UnicodeWidthStr;
|
||||||
);
|
use viuer::{print_from_file, terminal_size, Config};
|
||||||
}
|
|
||||||
count += 1;
|
use super::scraper::get_anime_info;
|
||||||
});
|
|
||||||
let mut anime_num: usize = usize::MAX;
|
enum InputMode {
|
||||||
while anime_num == usize::max_value() || anime_num > anime_list.len() {
|
Normal,
|
||||||
anime_num = int_input("Enter anime number: ");
|
Editing,
|
||||||
if anime_num > anime_list.len() {
|
}
|
||||||
println!("Invalid anime number");
|
|
||||||
|
struct StatefulList<T> {
|
||||||
|
state: ListState,
|
||||||
|
items: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StatefulList<T> {
|
||||||
|
fn with_items(items: Vec<T>) -> StatefulList<T> {
|
||||||
|
StatefulList {
|
||||||
|
state: ListState::default(),
|
||||||
|
items,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let title = &anime_list[anime_num];
|
|
||||||
let ep_range = anime_ep_range(title);
|
fn next(&mut self) {
|
||||||
// if there is only one episode, then don't ask user to choose episode
|
let i = match self.state.selected() {
|
||||||
if ep_range == 1 {
|
Some(i) => {
|
||||||
let link = anime_link(title, 1);
|
if i >= self.items.len() - 1 {
|
||||||
open_video(link);
|
0
|
||||||
main();
|
} else {
|
||||||
} else {
|
i + 1
|
||||||
let mut ep_num: usize = usize::MAX;
|
|
||||||
if episode > ep_range.into() {
|
|
||||||
println!("Invalid episode number");
|
|
||||||
main();
|
|
||||||
} else if episode != 0 {
|
|
||||||
ep_num = episode as usize;
|
|
||||||
} else {
|
|
||||||
println!("select episode 1-{}: ", ep_range);
|
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.state.select(Some(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn previous(&mut self) {
|
||||||
|
let i = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == 0 {
|
||||||
|
self.items.len() - 1
|
||||||
|
} else {
|
||||||
|
i - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.state.select(Some(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unselect(&mut self) {
|
||||||
|
self.state.select(None);
|
||||||
|
}
|
||||||
|
fn push(&mut self, item: T) {
|
||||||
|
self.items.push(item);
|
||||||
|
}
|
||||||
|
fn iter(&self) -> impl Iterator<Item = &T> {
|
||||||
|
self.items.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
/// Current value of the input box
|
||||||
|
input: String,
|
||||||
|
animes: (Vec<String>, Vec<String>, Vec<String>),
|
||||||
|
image: String,
|
||||||
|
/// Current input mode
|
||||||
|
input_mode: InputMode,
|
||||||
|
/// History of recorded messages
|
||||||
|
messages: StatefulList<String>,
|
||||||
|
title: String,
|
||||||
|
link: String,
|
||||||
|
ep: u64,
|
||||||
|
progress: i32,
|
||||||
|
anime_id: i32,
|
||||||
|
token: String,
|
||||||
|
provider: String,
|
||||||
|
cast: (bool, String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> App {
|
||||||
|
fn default() -> App {
|
||||||
|
App {
|
||||||
|
input: String::new(),
|
||||||
|
animes: get_an_history(),
|
||||||
|
image: String::new(),
|
||||||
|
input_mode: InputMode::Normal,
|
||||||
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
|
title: String::new(),
|
||||||
|
link: String::new(),
|
||||||
|
ep: 0,
|
||||||
|
progress: 0,
|
||||||
|
anime_id: 0,
|
||||||
|
token: String::new(),
|
||||||
|
provider: String::new(),
|
||||||
|
cast: (false, "0".to_string()),
|
||||||
}
|
}
|
||||||
loop {
|
}
|
||||||
let link = anime_link(title, ep_num as u64);
|
}
|
||||||
open_video(link);
|
|
||||||
println!("{}", "n: next episode".green());
|
pub fn anime_ui(
|
||||||
println!("{}", "p: previous episode".yellow());
|
token: String,
|
||||||
println!("{}", "s: search another anime".green());
|
provider: String,
|
||||||
println!("{}", "q: quit".red());
|
cast: (bool, String),
|
||||||
let input = string_input("Enter command: ");
|
) -> Result<(), Box<dyn Error>> {
|
||||||
if input == "n" {
|
// setup terminal
|
||||||
if ep_num == ep_range as usize {
|
enable_raw_mode()?;
|
||||||
println!("No more episodes");
|
let mut stdout = io::stdout();
|
||||||
} else {
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||||
ep_num += 1;
|
let backend = CrosstermBackend::new(stdout);
|
||||||
}
|
let mut terminal = Terminal::new(backend)?;
|
||||||
} else if input == "p" {
|
|
||||||
if ep_num == 1 {
|
// create app and run it
|
||||||
println!("No previous episodes");
|
let mut app = App::default();
|
||||||
} else {
|
app.token = token;
|
||||||
ep_num -= 1;
|
app.provider = provider;
|
||||||
}
|
app.cast = cast;
|
||||||
} else if input == "s" {
|
let res = run_app(&mut terminal, app);
|
||||||
//remove all the arguments
|
|
||||||
anime_stream("".to_string(), 0);
|
// restore terminal
|
||||||
} else if input == "q" {
|
disable_raw_mode()?;
|
||||||
std::process::exit(0);
|
execute!(
|
||||||
} else {
|
terminal.backend_mut(),
|
||||||
println!("Invalid command");
|
LeaveAlternateScreen,
|
||||||
|
DisableMouseCapture
|
||||||
|
)?;
|
||||||
|
terminal.show_cursor()?;
|
||||||
|
|
||||||
|
if let Err(err) = res {
|
||||||
|
println!("{:?}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
|
||||||
|
let mut ep_select = false;
|
||||||
|
fn change_image(app: &App) {
|
||||||
|
//save as f32
|
||||||
|
let (width, height) = terminal_size().to_owned();
|
||||||
|
let width = width as f32;
|
||||||
|
let height = height as f32;
|
||||||
|
let sixel_support = viuer::is_sixel_supported();
|
||||||
|
let config = match sixel_support {
|
||||||
|
true => Config {
|
||||||
|
x: ((width / 2.0) + 1.0).round() as u16,
|
||||||
|
y: 2,
|
||||||
|
width: Some((width / 1.3).round() as u32),
|
||||||
|
height: Some((height * 1.5) as u32),
|
||||||
|
restore_cursor: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
false => Config {
|
||||||
|
x: ((width / 2.0) + 1.0).round() as u16,
|
||||||
|
y: 2,
|
||||||
|
width: Some(((width / 2.0) - 4.0).round() as u32),
|
||||||
|
height: Some((height / 1.3).round() as u32),
|
||||||
|
restore_cursor: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
let image_path = config_path.join("tmp.jpg");
|
||||||
|
get_image(&app.image, &image_path.to_str().unwrap());
|
||||||
|
print_from_file(image_path, &config).expect("Image printing failed.");
|
||||||
|
}
|
||||||
|
app.messages.items.clear();
|
||||||
|
for anime in &app.animes.1 {
|
||||||
|
app.messages.push(anime.to_string());
|
||||||
|
}
|
||||||
|
app.input_mode = InputMode::Normal;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
terminal.draw(|f| ui(f, &mut app))?;
|
||||||
|
|
||||||
|
if let Event::Key(key) = event::read()? {
|
||||||
|
match app.input_mode {
|
||||||
|
InputMode::Normal => match key.code {
|
||||||
|
KeyCode::Char('i') => {
|
||||||
|
app.input_mode = InputMode::Editing;
|
||||||
|
}
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
KeyCode::Left => app.messages.unselect(),
|
||||||
|
KeyCode::Char('h') => app.messages.unselect(),
|
||||||
|
KeyCode::Down => match ep_select {
|
||||||
|
true => {
|
||||||
|
app.messages.next();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
app.messages.next();
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.image = app.animes.2[selected.unwrap()].clone();
|
||||||
|
change_image(&app);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Char('j') => match ep_select {
|
||||||
|
true => {
|
||||||
|
app.messages.next();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
app.messages.next();
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.image = app.animes.2[selected.unwrap()].clone();
|
||||||
|
change_image(&app);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Up => match ep_select {
|
||||||
|
true => {
|
||||||
|
app.messages.previous();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
app.messages.previous();
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.image = app.animes.2[selected.unwrap()].clone();
|
||||||
|
change_image(&app);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Char('k') => match ep_select {
|
||||||
|
true => {
|
||||||
|
app.messages.previous();
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
app.messages.previous();
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.image = app.animes.2[selected.unwrap()].clone();
|
||||||
|
change_image(&app);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//if KeyCode::Enter => {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
if ep_select == false {
|
||||||
|
app.progress = 0;
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.title = app.messages.items[selected.unwrap()].clone();
|
||||||
|
app.link = app.animes.0[selected.unwrap()].clone();
|
||||||
|
let anime_info = get_anime_info(&app.animes.0[selected.unwrap()]);
|
||||||
|
app.anime_id = get_anime_id(anime_info.0);
|
||||||
|
app.messages.items.clear();
|
||||||
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
|
app.progress = get_an_progress(&app.title) as i32;
|
||||||
|
app.messages.state.select(Some(app.progress as usize));
|
||||||
|
} else {
|
||||||
|
app.progress =
|
||||||
|
get_user_anime_progress(app.anime_id, app.token.as_str());
|
||||||
|
app.messages.state.select(Some(app.progress as usize));
|
||||||
|
}
|
||||||
|
if anime_info.1 == 1 {
|
||||||
|
let link = get_anime_link(&app.link, 1);
|
||||||
|
if !app.cast.0 {
|
||||||
|
open_video((link, format!("{} Episode 1", &app.title)));
|
||||||
|
} else {
|
||||||
|
open_cast(
|
||||||
|
(link, format!("{} Episode 1", &app.title)),
|
||||||
|
&app.cast.1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
let image_url = app.animes.2[selected.unwrap()].clone();
|
||||||
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
|
write_an_progress((&app.title, &app.link, &image_url), &1);
|
||||||
|
} else {
|
||||||
|
update_anime_progress(app.anime_id, 1, app.token.as_str());
|
||||||
|
write_an_progress((&app.title, &app.link, &image_url), &1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ep in 1..anime_info.1 + 1 {
|
||||||
|
app.messages.push(format!("Episode {}", ep));
|
||||||
|
}
|
||||||
|
ep_select = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.ep = app
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.nth(selected.unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.replace("Episode ", "")
|
||||||
|
.parse::<u64>()
|
||||||
|
.unwrap();
|
||||||
|
let link = get_anime_link(&app.link, app.ep);
|
||||||
|
if !app.cast.0 {
|
||||||
|
open_video((link, format!("{} Episode {}", &app.title, app.ep)));
|
||||||
|
} else {
|
||||||
|
open_cast(
|
||||||
|
(link, format!("{} Episode {}", &app.title, app.ep)),
|
||||||
|
&app.cast.1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let image_url = &app.image;
|
||||||
|
if app.ep > app.progress as u64 {
|
||||||
|
if app.token == "local" || app.anime_id == 0 {
|
||||||
|
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
||||||
|
} else {
|
||||||
|
update_anime_progress(
|
||||||
|
app.anime_id,
|
||||||
|
app.ep as usize,
|
||||||
|
app.token.as_str(),
|
||||||
|
);
|
||||||
|
write_an_progress((&app.title, &app.link, &image_url), &app.ep);
|
||||||
|
}
|
||||||
|
app.progress = app.ep as i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
InputMode::Editing => match key.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
//push app.input into app.messages with '
|
||||||
|
app.animes = get_animes(app.input.drain(..).collect());
|
||||||
|
app.messages.items.clear();
|
||||||
|
for anime in &app.animes.1 {
|
||||||
|
app.messages.push(anime.to_string());
|
||||||
|
}
|
||||||
|
ep_select = false;
|
||||||
|
app.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
KeyCode::Char(c) => {
|
||||||
|
app.input.push(c);
|
||||||
|
}
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
app.input.pop();
|
||||||
|
}
|
||||||
|
KeyCode::Esc => {
|
||||||
|
app.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.margin(1)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(3),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(f.size());
|
||||||
|
|
||||||
|
let block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("kami")
|
||||||
|
.border_type(BorderType::Rounded);
|
||||||
|
f.render_widget(block, f.size());
|
||||||
|
|
||||||
|
let top_chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
|
.split(chunks[0]);
|
||||||
|
|
||||||
|
let (msg, style) = match app.input_mode {
|
||||||
|
InputMode::Normal => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to exit, "),
|
||||||
|
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to search."),
|
||||||
|
],
|
||||||
|
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
||||||
|
),
|
||||||
|
InputMode::Editing => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to stop editing, "),
|
||||||
|
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to select."),
|
||||||
|
],
|
||||||
|
Style::default(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let messages: Vec<ListItem> = app
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, m)| {
|
||||||
|
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
||||||
|
ListItem::new(content)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let messages = List::new(messages)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("list")
|
||||||
|
.border_type(BorderType::Rounded),
|
||||||
|
)
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
|
.highlight_style(
|
||||||
|
Style::default()
|
||||||
|
.bg(Color::Rgb(183, 142, 241))
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
|
.highlight_symbol(">>");
|
||||||
|
f.render_stateful_widget(messages, top_chunks[0], &mut app.messages.state);
|
||||||
|
let block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("info")
|
||||||
|
.border_type(BorderType::Rounded);
|
||||||
|
f.render_widget(block, top_chunks[1]);
|
||||||
|
|
||||||
|
let mut text = Text::from(Spans::from(msg));
|
||||||
|
text.patch_style(style);
|
||||||
|
let help_message = Paragraph::new(text);
|
||||||
|
f.render_widget(help_message, chunks[1]);
|
||||||
|
|
||||||
|
let input = Paragraph::new(app.input.as_ref())
|
||||||
|
.style(match app.input_mode {
|
||||||
|
InputMode::Normal => Style::default(),
|
||||||
|
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
||||||
|
})
|
||||||
|
.block(Block::default().borders(Borders::all()).title("Input"));
|
||||||
|
f.render_widget(input, chunks[2]);
|
||||||
|
match app.input_mode {
|
||||||
|
InputMode::Normal =>
|
||||||
|
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
||||||
|
{}
|
||||||
|
|
||||||
|
InputMode::Editing => {
|
||||||
|
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
||||||
|
f.set_cursor(
|
||||||
|
// Put cursor past the end of the input text
|
||||||
|
chunks[2].x + app.input.width() as u16 + 1,
|
||||||
|
// Move one line down, from the border to the input line
|
||||||
|
chunks[2].y + 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod anime;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
pub mod scraper;
|
pub mod scraper;
|
||||||
pub mod anime;
|
pub mod trackers;
|
||||||
|
|||||||
@@ -1,3 +1,13 @@
|
|||||||
|
extern crate rust_cast;
|
||||||
|
use rust_cast::{
|
||||||
|
channels::{
|
||||||
|
media::{Media, StreamType},
|
||||||
|
receiver::CastDeviceApp,
|
||||||
|
},
|
||||||
|
CastDevice,
|
||||||
|
};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn open_video(link: (String, String)) {
|
pub fn open_video(link: (String, String)) {
|
||||||
let title = link.1;
|
let title = link.1;
|
||||||
let title = title.replace("-", " ");
|
let title = title.replace("-", " ");
|
||||||
@@ -9,5 +19,64 @@ pub fn open_video(link: (String, String)) {
|
|||||||
.expect("failed to open mpv");
|
.expect("failed to open mpv");
|
||||||
|
|
||||||
// clear terminal
|
// clear terminal
|
||||||
print!("\x1b[2J\x1b[1;1H");
|
}
|
||||||
|
|
||||||
|
const DEFAULT_DESTINATION_ID: &str = "receiver-0";
|
||||||
|
fn play_media(
|
||||||
|
device: &CastDevice,
|
||||||
|
app_to_run: &CastDeviceApp,
|
||||||
|
media: String,
|
||||||
|
media_type: String,
|
||||||
|
media_stream_type: StreamType,
|
||||||
|
) {
|
||||||
|
let app = device.receiver.launch_app(app_to_run).unwrap();
|
||||||
|
|
||||||
|
device
|
||||||
|
.connection
|
||||||
|
.connect(app.transport_id.as_str())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let _status = device
|
||||||
|
.media
|
||||||
|
.load(
|
||||||
|
app.transport_id.as_str(),
|
||||||
|
app.session_id.as_str(),
|
||||||
|
&Media {
|
||||||
|
content_id: media,
|
||||||
|
content_type: media_type,
|
||||||
|
stream_type: media_stream_type,
|
||||||
|
duration: None,
|
||||||
|
metadata: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_cast(link: (String, String), ip: &str) {
|
||||||
|
let cast_device = match CastDevice::connect_without_host_verification(ip, 8009) {
|
||||||
|
Ok(cast_device) => cast_device,
|
||||||
|
Err(err) => panic!("Could not establish connection with Cast Device: {:?}", err),
|
||||||
|
};
|
||||||
|
|
||||||
|
cast_device
|
||||||
|
.connection
|
||||||
|
.connect(DEFAULT_DESTINATION_ID.to_string())
|
||||||
|
.unwrap();
|
||||||
|
cast_device.heartbeat.ping().unwrap();
|
||||||
|
|
||||||
|
// Play media and keep connection.
|
||||||
|
|
||||||
|
let media_stream_type = match "none" {
|
||||||
|
value @ "buffered" | value @ "live" | value @ "none" => {
|
||||||
|
StreamType::from_str(value).unwrap()
|
||||||
|
}
|
||||||
|
_ => panic!("Unsupported stream type!"),
|
||||||
|
};
|
||||||
|
play_media(
|
||||||
|
&cast_device,
|
||||||
|
&CastDeviceApp::from_str("default").unwrap(),
|
||||||
|
link.0.to_string(),
|
||||||
|
"".to_string(),
|
||||||
|
media_stream_type,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +1,96 @@
|
|||||||
use base64::{decode, encode};
|
use isahc::config::Configurable;
|
||||||
use isahc::{ReadResponseExt, Request, RequestExt};
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
//use serde_json::json;
|
||||||
|
|
||||||
pub fn get_anime_html(url: &str) -> String {
|
pub fn get_anime_html(url: &str) -> String {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.uri(url)
|
.uri(url)
|
||||||
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header(
|
||||||
"user-agent",
|
"user-agent",
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
||||||
)
|
)
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
req.send().unwrap().text().unwrap()
|
req.send().unwrap().text().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ep_location(url: &str) -> String {
|
pub fn get_post(id: &str) -> String {
|
||||||
let request = Request::builder()
|
let resp = Request::builder()
|
||||||
.method("HEAD")
|
.method("POST")
|
||||||
.uri(url)
|
.uri("https://yugenanime.ro/api/embed/")
|
||||||
.header(
|
.header("x-requested-with", "XMLHttpRequest")
|
||||||
"user-agent",
|
.body(id)
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
.unwrap()
|
||||||
)
|
.send()
|
||||||
.body(())
|
.unwrap()
|
||||||
.unwrap();
|
.text();
|
||||||
let response = request.send().unwrap();
|
let resp: String = resp.as_ref().unwrap().to_string();
|
||||||
let headers = response.headers();
|
resp
|
||||||
let location = headers.get("location").unwrap();
|
|
||||||
location.to_str().unwrap().to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn anime_names(query: &str) -> Vec<String> {
|
pub fn get_animes(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
|
||||||
let url = format!("https://gogoanime.lu//search.html?keyword={}", query);
|
let query = query.replace(" ", "+");
|
||||||
//relpace all spaces with %20
|
let html = get_anime_html(&format!("https://yugenanime.ro/discover/?q={}", query));
|
||||||
let url = url.replace(' ', "%20");
|
let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap();
|
||||||
let html = get_anime_html(&url);
|
let mut animes_links = Vec::new();
|
||||||
let re = Regex::new(r#"(?m)/category/([^"]*)"#).unwrap();
|
|
||||||
let mut anime_list: Vec<String> = Vec::new();
|
|
||||||
for cap in re.captures_iter(&html) {
|
for cap in re.captures_iter(&html) {
|
||||||
anime_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
animes_links.push(cap[1].to_string());
|
||||||
}
|
}
|
||||||
anime_list.dedup();
|
let re = Regex::new(r#"/" title="([^"]*)""#).unwrap();
|
||||||
|
let mut animes_names = Vec::new();
|
||||||
anime_list
|
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 anime_ep_range(anime_name: &str) -> u16 {
|
pub fn get_anime_info(url: &str) -> (i32, u16) {
|
||||||
let url = format!("https://gogoanime.lu/category/{}", anime_name);
|
let url = format!("https://yugenanime.ro{}watch", url);
|
||||||
let re = Regex::new(r#"(?m)\s<a href="\#" class="active" ep_start = (.*?)</a>"#).unwrap();
|
|
||||||
let episodes = re
|
|
||||||
.captures_iter(&get_anime_html(&url))
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.trim()
|
|
||||||
.to_string();
|
|
||||||
episodes
|
|
||||||
.split('-')
|
|
||||||
.nth(1)
|
|
||||||
.unwrap_or("0")
|
|
||||||
.parse::<u16>()
|
|
||||||
.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);
|
let html = get_anime_html(&url);
|
||||||
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap();
|
//print html and exit
|
||||||
let id1 = re
|
let re = Regex::new(r#""mal_id":(\d*)"#).unwrap();
|
||||||
.captures_iter(&html)
|
let mal_id = re.captures(&html).unwrap()[1].parse().unwrap();
|
||||||
.nth(ep as usize - 1)
|
let re =
|
||||||
.unwrap()
|
Regex::new(r#"Episodes</div><span class="description" style="font-size: \d*px;">(\d*)"#)
|
||||||
.get(1)
|
.unwrap();
|
||||||
.unwrap()
|
let episodes = re.captures(&html).unwrap()[1].parse().unwrap();
|
||||||
.as_str()
|
(mal_id, episodes)
|
||||||
.trim()
|
}
|
||||||
.to_string();
|
|
||||||
let title = format!("{} Episode {}", title.replace('-', " "), ep);
|
pub fn get_anime_link(url: &str, episode: u64) -> String {
|
||||||
let encoded_id1 = encode(&id1);
|
let url = &format!(
|
||||||
let anime_id = encode(format!("{}LTXs3GrU8we9O{}", id1, encoded_id1));
|
"https://yugenanime.ro/watch{}{}/",
|
||||||
let html = format!("https://animixplay.to/api/live{}", anime_id);
|
url.replace("/anime", ""),
|
||||||
let url = get_ep_location(&html);
|
episode
|
||||||
let url = url.split('#').nth(1).unwrap();
|
);
|
||||||
let url = std::str::from_utf8(&decode(url).unwrap())
|
let html = get_anime_html(url);
|
||||||
.unwrap()
|
let re = Regex::new(r#"/e/([^/]*)"#).unwrap();
|
||||||
.to_string();
|
let capture = re.captures(&html).unwrap();
|
||||||
(url, title)
|
let id = &capture[1];
|
||||||
|
let id = format!("id={}%3D&ac=0", id);
|
||||||
|
let json = get_post(&id);
|
||||||
|
let re = Regex::new(r#"hls": \["(.*)","#).unwrap();
|
||||||
|
let capture = re.captures(&json).unwrap();
|
||||||
|
let link = &capture[1];
|
||||||
|
//return the link
|
||||||
|
link.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_image(url: &str, path: &str) {
|
||||||
|
let url = url;
|
||||||
|
let mut response = isahc::get(url).unwrap();
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
response.copy_to(&mut buffer).unwrap();
|
||||||
|
let mut file = File::create(path).unwrap();
|
||||||
|
file.write_all(&buffer).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
281
src/anime/trackers.rs
Normal file
281
src/anime/trackers.rs
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
use crate::string_input;
|
||||||
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
|
use serde_json::json;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
pub fn get_token() -> String {
|
||||||
|
//if not on windows create folder ~/.config/kami
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
if !config_path.exists() {
|
||||||
|
fs::create_dir_all(&config_path).unwrap();
|
||||||
|
}
|
||||||
|
let token_path = config_path.join("token.txt");
|
||||||
|
if !token_path.exists() {
|
||||||
|
//create empty file
|
||||||
|
fs::File::create(&token_path).unwrap();
|
||||||
|
}
|
||||||
|
//read token from file
|
||||||
|
let token = fs::read_to_string(&token_path).unwrap();
|
||||||
|
if token.is_empty() {
|
||||||
|
//ask user if they want to add a token or track locally
|
||||||
|
let input = string_input(
|
||||||
|
"would you want to link anilist(sellecting no will track anime localy)? (y/n)",
|
||||||
|
);
|
||||||
|
if input == "y" {
|
||||||
|
println!("please go to the below link and copy and past the token below");
|
||||||
|
println!(
|
||||||
|
"https://anilist.co/api/v2/oauth/authorize?client_id=9121&response_type=token"
|
||||||
|
);
|
||||||
|
let token = string_input("token: ");
|
||||||
|
fs::write(&token_path, token).unwrap();
|
||||||
|
} else if input == "n" {
|
||||||
|
let token = "local";
|
||||||
|
fs::write(&token_path, token).unwrap();
|
||||||
|
} else {
|
||||||
|
println!("invalid input");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let token = fs::read_to_string(&token_path).unwrap();
|
||||||
|
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
|
||||||
|
fn get_user_id(token: &str) -> i32 {
|
||||||
|
const QUERY: &str = "query {
|
||||||
|
Viewer {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
let json = json!({ "query": QUERY });
|
||||||
|
let resp = Request::builder()
|
||||||
|
.method("POST")
|
||||||
|
.uri("https://graphql.anilist.co/")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.body(json.to_string())
|
||||||
|
.unwrap()
|
||||||
|
.send()
|
||||||
|
.unwrap()
|
||||||
|
.text();
|
||||||
|
//println!("{}", resp);
|
||||||
|
let regex = regex::Regex::new(r#"id":(.*?)}"#).unwrap();
|
||||||
|
let resp: String = resp.as_ref().unwrap().to_string();
|
||||||
|
let id = regex
|
||||||
|
.captures(&resp)
|
||||||
|
.unwrap()
|
||||||
|
.get(1)
|
||||||
|
.unwrap()
|
||||||
|
.as_str()
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_user_anime_progress(anime_id: i32, token: &str) -> i32 {
|
||||||
|
let user_id = get_user_id(&token);
|
||||||
|
const QUERY: &str = "query ($user_id: Int, $media_id: Int) {
|
||||||
|
MediaList (userId: $user_id, mediaId: $media_id, type: ANIME) {
|
||||||
|
progress
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
let json = json!({
|
||||||
|
"query": QUERY,
|
||||||
|
"variables": {
|
||||||
|
"user_id": user_id,
|
||||||
|
"media_id": anime_id,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let resp = Request::builder()
|
||||||
|
.method("POST")
|
||||||
|
.uri("https://graphql.anilist.co/")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.body(json.to_string())
|
||||||
|
.unwrap()
|
||||||
|
.send()
|
||||||
|
.unwrap()
|
||||||
|
.text();
|
||||||
|
let regex = regex::Regex::new(r#"progress":(.*?)}"#).unwrap();
|
||||||
|
let resp: String = resp.as_ref().unwrap().to_string();
|
||||||
|
if resp.contains("errors") {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
let progress = regex
|
||||||
|
.captures(&resp)
|
||||||
|
.unwrap()
|
||||||
|
.get(1)
|
||||||
|
.unwrap()
|
||||||
|
.as_str()
|
||||||
|
.parse::<i32>()
|
||||||
|
.unwrap();
|
||||||
|
progress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_anime_progress(anime_id: i32, progress: usize, token: &str) {
|
||||||
|
const UPDATE: &str = "
|
||||||
|
mutation ($mediaId: Int, $status: MediaListStatus, $progress: Int) {
|
||||||
|
SaveMediaListEntry (mediaId: $mediaId, status: $status, progress: $progress) {
|
||||||
|
id
|
||||||
|
status
|
||||||
|
progress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
let json = json!({
|
||||||
|
"query": UPDATE,
|
||||||
|
"variables": {
|
||||||
|
"mediaId": anime_id,
|
||||||
|
"status": "CURRENT",
|
||||||
|
"progress": progress
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let _resp = Request::builder()
|
||||||
|
.method("POST")
|
||||||
|
.uri("https://graphql.anilist.co/")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.body(json.to_string())
|
||||||
|
.unwrap()
|
||||||
|
.send()
|
||||||
|
.unwrap()
|
||||||
|
.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
// local tracking
|
||||||
|
pub fn get_an_json() -> serde_json::Value {
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
if !config_path.exists() {
|
||||||
|
fs::create_dir_all(&config_path).unwrap();
|
||||||
|
}
|
||||||
|
let json_path = config_path.join("an_progress.json");
|
||||||
|
if !json_path.exists() {
|
||||||
|
fs::File::create(&json_path).unwrap();
|
||||||
|
}
|
||||||
|
let json = fs::read_to_string(&json_path).unwrap();
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap_or(serde_json::Value::Null);
|
||||||
|
json
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_an_progress(anime: (&str, &str, &str), progress: &u64) {
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
let json_path = config_path.join("an_progress.json");
|
||||||
|
let json = fs::read_to_string(&json_path).unwrap();
|
||||||
|
let mut json: serde_json::Value =
|
||||||
|
serde_json::from_str(&json).unwrap_or(serde_json::Value::Null);
|
||||||
|
let mut title_json = serde_json::Map::new();
|
||||||
|
title_json.insert(
|
||||||
|
"progress".to_string(),
|
||||||
|
serde_json::Value::from(progress.clone()),
|
||||||
|
);
|
||||||
|
title_json.insert("link".to_string(), serde_json::Value::from(anime.1));
|
||||||
|
title_json.insert("image".to_string(), serde_json::Value::from(anime.2));
|
||||||
|
title_json.insert(
|
||||||
|
"updated".to_string(),
|
||||||
|
serde_json::Value::from(
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
//insert title_json into json
|
||||||
|
if json[anime.0].is_null() {
|
||||||
|
json[anime.0] = serde_json::Value::from(title_json);
|
||||||
|
} else {
|
||||||
|
json[anime.0]["progress"] = serde_json::Value::from(progress.clone());
|
||||||
|
json[anime.0]["link"] = serde_json::Value::from(anime.1);
|
||||||
|
json[anime.0]["image"] = serde_json::Value::from(anime.2);
|
||||||
|
json[anime.0]["updated"] = serde_json::Value::from(
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let json = serde_json::to_string_pretty(&json).unwrap();
|
||||||
|
fs::write(&json_path, json).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_an_history() -> (Vec<String>, Vec<String>, Vec<String>) {
|
||||||
|
//get the titles, links, and images from the json
|
||||||
|
let json = get_an_json();
|
||||||
|
let mut titles = vec![];
|
||||||
|
let mut links = vec![];
|
||||||
|
let mut images = vec![];
|
||||||
|
let mut last_updated = vec![];
|
||||||
|
//if the json is empty, return empty vectors
|
||||||
|
if json.is_null() {
|
||||||
|
return (titles, links, images);
|
||||||
|
}
|
||||||
|
for (key, value) in json.as_object().unwrap() {
|
||||||
|
titles.push(key.to_string());
|
||||||
|
links.push(value["link"].as_str().unwrap().to_string());
|
||||||
|
images.push(value["image"].as_str().unwrap().to_string());
|
||||||
|
last_updated.push(value["updated"].as_u64().unwrap());
|
||||||
|
}
|
||||||
|
let mut indices: Vec<usize> = (0..last_updated.len()).collect();
|
||||||
|
indices.sort_by(|&a, &b| last_updated[b].cmp(&last_updated[a]));
|
||||||
|
titles = indices.iter().map(|&i| titles[i].clone()).collect();
|
||||||
|
links = indices.iter().map(|&i| links[i].clone()).collect();
|
||||||
|
images = indices.iter().map(|&i| images[i].clone()).collect();
|
||||||
|
(links, titles, images)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_an_progress(title: &str) -> i32 {
|
||||||
|
let json = get_an_json();
|
||||||
|
let selected = json[title]["progress"].as_u64().unwrap_or(0);
|
||||||
|
selected as i32
|
||||||
|
}
|
||||||
417
src/ln/ln.rs
417
src/ln/ln.rs
@@ -1,37 +1,392 @@
|
|||||||
use crate::{chapter_selector, get_full_text, open_bat, search_ln};
|
use crate::ln::open_text::{open_bat, open_glow};
|
||||||
|
use crate::ln::scraper::*;
|
||||||
|
use crate::ln::tracker::*;
|
||||||
|
use crossterm::{
|
||||||
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
|
||||||
|
execute,
|
||||||
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
|
};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
pub fn ln_read(search: &str, chapter: u32) {
|
use std::{error::Error, io};
|
||||||
//convert search in to Option<&str>
|
use tui::{
|
||||||
let ln_url = search_ln(&search);
|
backend::{Backend, CrosstermBackend},
|
||||||
let chapter = chapter as f64;
|
layout::{Constraint, Direction, Layout},
|
||||||
let mut selected_page = 1;
|
style::{Color, Modifier, Style},
|
||||||
if chapter != 0.0 {
|
text::{Span, Spans, Text},
|
||||||
selected_page = (chapter / 48.0).ceil() as u32;
|
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||||
|
Frame, Terminal,
|
||||||
|
};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
enum InputMode {
|
||||||
|
Normal,
|
||||||
|
Editing,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct StatefulList<T> {
|
||||||
|
state: ListState,
|
||||||
|
items: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StatefulList<T> {
|
||||||
|
fn with_items(items: Vec<T>) -> StatefulList<T> {
|
||||||
|
StatefulList {
|
||||||
|
state: ListState::default(),
|
||||||
|
items,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loop {
|
|
||||||
//make empty tuple called chapter_url with (String, u32, u32)
|
fn next(&mut self) {
|
||||||
let chapter_url = chapter_selector(&ln_url, selected_page);
|
let i = match self.state.selected() {
|
||||||
selected_page = chapter_url.1;
|
Some(i) => {
|
||||||
let full_text = get_full_text(&chapter_url.0);
|
if i >= self.items.len() - 1 {
|
||||||
if cfg!(target_os = "windows") {
|
0
|
||||||
use dirs::home_dir;
|
} else {
|
||||||
let mut home = format!("{:?}", home_dir()).replace("\\\\", "/");
|
i + 1
|
||||||
home.drain(0..6);
|
}
|
||||||
home.drain(home.len() - 2..home.len());
|
}
|
||||||
let mut file = File::create(format!("{}/AppData/Roaming/log_e", home))
|
None => 0,
|
||||||
.expect("Unable to create file");
|
|
||||||
file.write_all(full_text.as_bytes())
|
|
||||||
.expect("Unable to write to file");
|
|
||||||
file.sync_all().expect("Unable to sync file");
|
|
||||||
} else {
|
|
||||||
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");
|
|
||||||
file.sync_all().expect("Unable to sync file");
|
|
||||||
};
|
};
|
||||||
//open temp.txt in cat for user to read
|
self.state.select(Some(i));
|
||||||
let _com = open_bat();
|
}
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
|
fn previous(&mut self) {
|
||||||
|
let i = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == 0 {
|
||||||
|
self.items.len() - 1
|
||||||
|
} else {
|
||||||
|
i - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
self.state.select(Some(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unselect(&mut self) {
|
||||||
|
self.state.select(None);
|
||||||
|
}
|
||||||
|
fn push(&mut self, item: T) {
|
||||||
|
self.items.push(item);
|
||||||
|
}
|
||||||
|
fn iter(&self) -> impl Iterator<Item = &T> {
|
||||||
|
self.items.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
/// Current value of the input box
|
||||||
|
input: String,
|
||||||
|
/// Current input mode
|
||||||
|
input_mode: InputMode,
|
||||||
|
/// History of recorded messages
|
||||||
|
messages: StatefulList<String>,
|
||||||
|
ln_titles: Vec<String>,
|
||||||
|
ln_links: Vec<String>,
|
||||||
|
title: String,
|
||||||
|
ln_id: String,
|
||||||
|
ln_chapters: Vec<String>,
|
||||||
|
ln_chapters_links: Vec<String>,
|
||||||
|
last_page: String,
|
||||||
|
current_page: String,
|
||||||
|
current_page_number: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> App {
|
||||||
|
fn default() -> App {
|
||||||
|
App {
|
||||||
|
input: String::new(),
|
||||||
|
input_mode: InputMode::Normal,
|
||||||
|
messages: StatefulList::with_items(Vec::new()),
|
||||||
|
ln_titles: Vec::new(),
|
||||||
|
ln_links: Vec::new(),
|
||||||
|
title: String::new(),
|
||||||
|
ln_id: String::new(),
|
||||||
|
ln_chapters: Vec::new(),
|
||||||
|
ln_chapters_links: Vec::new(),
|
||||||
|
last_page: String::new(),
|
||||||
|
current_page: String::new(),
|
||||||
|
current_page_number: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ln_ui(chapter: u32, reader: String) -> Result<(), Box<dyn Error>> {
|
||||||
|
// setup terminal
|
||||||
|
let _ = get_ln_json();
|
||||||
|
enable_raw_mode()?;
|
||||||
|
let mut stdout = io::stdout();
|
||||||
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||||
|
let backend = CrosstermBackend::new(stdout);
|
||||||
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
|
// create app and run it
|
||||||
|
let mut app = App::default();
|
||||||
|
let chapter = chapter as f64;
|
||||||
|
app.current_page_number = 1;
|
||||||
|
if chapter != 0.0 {
|
||||||
|
app.current_page_number = (chapter / 48.0).ceil() as u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = run_app(&mut terminal, app, &*reader);
|
||||||
|
|
||||||
|
// restore terminal
|
||||||
|
disable_raw_mode()?;
|
||||||
|
execute!(
|
||||||
|
terminal.backend_mut(),
|
||||||
|
LeaveAlternateScreen,
|
||||||
|
DisableMouseCapture
|
||||||
|
)?;
|
||||||
|
terminal.show_cursor()?;
|
||||||
|
|
||||||
|
if let Err(err) = res {
|
||||||
|
println!("{:?}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App, reader: &str) -> io::Result<()> {
|
||||||
|
let mut chapter_select = false;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
terminal.draw(|f| ui(f, &mut app))?;
|
||||||
|
if let Event::Key(key) = event::read()? {
|
||||||
|
match app.input_mode {
|
||||||
|
InputMode::Normal => match key.code {
|
||||||
|
KeyCode::Char('i') => {
|
||||||
|
app.input_mode = InputMode::Editing;
|
||||||
|
}
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
terminal.clear()?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
KeyCode::Left => app.messages.unselect(),
|
||||||
|
KeyCode::Char('h') => {
|
||||||
|
if app.current_page_number > 0 {
|
||||||
|
app.current_page_number -= 1;
|
||||||
|
}
|
||||||
|
app.current_page = get_ln_next_page(&app.ln_id, &app.current_page_number);
|
||||||
|
app.ln_chapters = get_ln_chapters(&app.current_page);
|
||||||
|
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
||||||
|
app.messages.items.clear();
|
||||||
|
for chapter in app.ln_chapters.iter() {
|
||||||
|
app.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyCode::Down => app.messages.next(),
|
||||||
|
KeyCode::Char('j') => app.messages.next(),
|
||||||
|
KeyCode::Up => app.messages.previous(),
|
||||||
|
KeyCode::Char('k') => app.messages.previous(),
|
||||||
|
KeyCode::Char('l') => {
|
||||||
|
if app.current_page_number < app.last_page.parse::<u32>().unwrap() {
|
||||||
|
app.current_page_number += 1;
|
||||||
|
}
|
||||||
|
app.current_page = get_ln_next_page(&app.ln_id, &app.current_page_number);
|
||||||
|
app.ln_chapters = get_ln_chapters(&app.current_page);
|
||||||
|
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
||||||
|
app.messages.items.clear();
|
||||||
|
for chapter in app.ln_chapters.iter() {
|
||||||
|
app.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if KeyCode::Enter => {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
if chapter_select == false {
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
app.title = app
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.nth(selected.unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
if app.current_page_number == 1 {
|
||||||
|
let progress = get_ln_progress(&app.title);
|
||||||
|
app.current_page_number = progress.0;
|
||||||
|
app.messages.state.select(Some(progress.1));
|
||||||
|
}
|
||||||
|
let link = app.ln_links[selected.unwrap()].to_string();
|
||||||
|
let html = get_html(&link);
|
||||||
|
app.ln_id = get_ln_id(&html).to_string();
|
||||||
|
app.last_page = get_ln_last_page(&html);
|
||||||
|
app.current_page =
|
||||||
|
get_ln_next_page(&app.ln_id.to_string(), &app.current_page_number);
|
||||||
|
app.ln_chapters = get_ln_chapters(&app.current_page);
|
||||||
|
app.ln_chapters_links = get_ln_chapters_urls(&app.current_page);
|
||||||
|
app.messages.items.clear();
|
||||||
|
for chapter in app.ln_chapters.iter() {
|
||||||
|
app.messages.push(chapter.to_string());
|
||||||
|
}
|
||||||
|
chapter_select = true;
|
||||||
|
} else {
|
||||||
|
let selected = app.messages.state.selected();
|
||||||
|
let chapter_url = app.ln_chapters_links[selected.unwrap()].to_string();
|
||||||
|
let full_text = get_full_text(&chapter_url);
|
||||||
|
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());
|
||||||
|
let mut file =
|
||||||
|
File::create(format!("{}/AppData/Roaming/log_e", home))
|
||||||
|
.expect("Unable to create file");
|
||||||
|
file.write_all(full_text.as_bytes())
|
||||||
|
.expect("Unable to write to file");
|
||||||
|
file.sync_all().expect("Unable to sync file");
|
||||||
|
} else {
|
||||||
|
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");
|
||||||
|
file.sync_all().expect("Unable to sync file");
|
||||||
|
};
|
||||||
|
terminal.clear()?;
|
||||||
|
let _ = match reader {
|
||||||
|
"bat" => open_bat(),
|
||||||
|
"glow" => open_glow(),
|
||||||
|
&_ => todo!(),
|
||||||
|
};
|
||||||
|
write_ln_progress(
|
||||||
|
&app.title,
|
||||||
|
&app.current_page_number,
|
||||||
|
&app.messages.state.selected().unwrap(),
|
||||||
|
);
|
||||||
|
terminal.clear()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
InputMode::Editing => match key.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
//push app.input into app.messages with '1
|
||||||
|
let search: String = app.input.drain(..).collect();
|
||||||
|
let search = search.replace(" ", "+");
|
||||||
|
let url = "https://readlightnovels.net/?s=".to_string();
|
||||||
|
let url = format!("{}{}", url, search.trim()).trim().to_string();
|
||||||
|
let html = get_html(&url);
|
||||||
|
let ln_list = get_ln_list(html.as_str());
|
||||||
|
app.ln_titles = get_ln_titles(&ln_list);
|
||||||
|
app.ln_links = get_ln_urls(&ln_list);
|
||||||
|
app.messages.items.clear();
|
||||||
|
//remove index 0 of app.ln_titles and app.ln_links
|
||||||
|
app.ln_titles.remove(0);
|
||||||
|
app.ln_links.remove(0);
|
||||||
|
for ln in &app.ln_titles {
|
||||||
|
app.messages.push(ln.to_string());
|
||||||
|
}
|
||||||
|
chapter_select = false;
|
||||||
|
app.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
KeyCode::Char(c) => {
|
||||||
|
app.input.push(c);
|
||||||
|
}
|
||||||
|
KeyCode::Backspace => {
|
||||||
|
app.input.pop();
|
||||||
|
}
|
||||||
|
KeyCode::Esc => {
|
||||||
|
app.input_mode = InputMode::Normal;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.margin(1)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Min(1),
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(3),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(f.size());
|
||||||
|
let block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("kami")
|
||||||
|
.border_type(BorderType::Rounded);
|
||||||
|
f.render_widget(block, f.size());
|
||||||
|
|
||||||
|
let (msg, style) = match app.input_mode {
|
||||||
|
InputMode::Normal => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("q", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to exit, "),
|
||||||
|
Span::styled("i", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to search, "),
|
||||||
|
Span::styled("h", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to go to the previous page, "),
|
||||||
|
Span::styled("l", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to go to the next page."),
|
||||||
|
],
|
||||||
|
Style::default().add_modifier(Modifier::RAPID_BLINK),
|
||||||
|
),
|
||||||
|
InputMode::Editing => (
|
||||||
|
vec![
|
||||||
|
Span::raw("Press "),
|
||||||
|
Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to stop editing, "),
|
||||||
|
Span::styled("Enter", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
Span::raw(" to select."),
|
||||||
|
],
|
||||||
|
Style::default(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
let messages: Vec<ListItem> = app
|
||||||
|
.messages
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, m)| {
|
||||||
|
let content = vec![Spans::from(Span::raw(format!("{}: {}", i, m)))];
|
||||||
|
ListItem::new(content)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let messages = List::new(messages)
|
||||||
|
.block(Block::default().borders(Borders::ALL).title("list"))
|
||||||
|
.style(Style::default().fg(Color::White))
|
||||||
|
.highlight_style(
|
||||||
|
Style::default()
|
||||||
|
.bg(Color::Rgb(183, 142, 241))
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
|
.highlight_symbol(">>");
|
||||||
|
f.render_stateful_widget(messages, chunks[0], &mut app.messages.state);
|
||||||
|
|
||||||
|
let mut text = Text::from(Spans::from(msg));
|
||||||
|
text.patch_style(style);
|
||||||
|
let help_message = Paragraph::new(text);
|
||||||
|
f.render_widget(help_message, chunks[1]);
|
||||||
|
|
||||||
|
let input = Paragraph::new(app.input.as_ref())
|
||||||
|
.style(match app.input_mode {
|
||||||
|
InputMode::Normal => Style::default(),
|
||||||
|
InputMode::Editing => Style::default().fg(Color::Rgb(183, 142, 241)),
|
||||||
|
})
|
||||||
|
.block(Block::default().borders(Borders::all()).title("Input"));
|
||||||
|
f.render_widget(input, chunks[2]);
|
||||||
|
match app.input_mode {
|
||||||
|
InputMode::Normal =>
|
||||||
|
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
|
||||||
|
{}
|
||||||
|
|
||||||
|
InputMode::Editing => {
|
||||||
|
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
|
||||||
|
f.set_cursor(
|
||||||
|
// Put cursor past the end of the input text
|
||||||
|
chunks[2].x + app.input.width() as u16 + 1,
|
||||||
|
// Move one line down, from the border to the input line
|
||||||
|
chunks[2].y + 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
use colored::Colorize;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
helpers::take_input::string_input,
|
|
||||||
ln::{
|
|
||||||
self,
|
|
||||||
scraper::{get_ln_chapters_urls, get_ln_id, get_ln_last_page},
|
|
||||||
search::get_ln_chapters,
|
|
||||||
},
|
|
||||||
main, page_selector,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
|
|
||||||
loop {
|
|
||||||
let ln_html = ln::scraper::get_html(ln_url);
|
|
||||||
let ln_id = get_ln_id(&ln_html);
|
|
||||||
let ln_last_page = get_ln_last_page(&ln_html);
|
|
||||||
let ln_page_html = page_selector(&ln_id, selected_page);
|
|
||||||
let ln_chapters = get_ln_chapters(&ln_page_html);
|
|
||||||
let ln_chapters_urls = get_ln_chapters_urls(&ln_page_html);
|
|
||||||
let mut count = 0;
|
|
||||||
ln_chapters.into_iter().for_each(|chaprer| {
|
|
||||||
if count % 2 == 0 {
|
|
||||||
println!(
|
|
||||||
"({})\t{}",
|
|
||||||
count.to_string().blue(),
|
|
||||||
format_args!("{}", chaprer.blue())
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
println!(
|
|
||||||
"({})\t{}",
|
|
||||||
count.to_string().yellow(),
|
|
||||||
format_args!("{}", chaprer.yellow())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
count += 1;
|
|
||||||
});
|
|
||||||
println!("{}\t{}", "n:".green(), "Go to next page".green());
|
|
||||||
println!("{}\t{}", "b:".yellow(), "Go to previous page".yellow());
|
|
||||||
println!("{}\t{}", "s:".green(), "Search another title".green());
|
|
||||||
println!("{}\t{}", "q:".red(), "quit".red());
|
|
||||||
let chapter_number = string_input("Which chapter do you want to read? ");
|
|
||||||
if chapter_number == "n" && selected_page < ln_last_page.parse::<u32>().unwrap() {
|
|
||||||
selected_page += 1;
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
} else if chapter_number == "b" && selected_page > 1 {
|
|
||||||
selected_page -= 1;
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
} else if chapter_number == "q" {
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
std::process::exit(0);
|
|
||||||
} else if chapter_number == "s" {
|
|
||||||
main();
|
|
||||||
} else {
|
|
||||||
let chapter_number = chapter_number.trim().to_string();
|
|
||||||
let mut _chapter_number_int = 0;
|
|
||||||
if chapter_number.parse::<u32>().is_ok() {
|
|
||||||
_chapter_number_int = chapter_number.parse::<u32>().unwrap();
|
|
||||||
} else {
|
|
||||||
println!("{}", "Invalid option".red());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let chapter_url = &ln_chapters_urls[_chapter_number_int as usize];
|
|
||||||
let chapter_url = chapter_url.trim().to_string();
|
|
||||||
return (chapter_url, selected_page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
pub mod menu;
|
pub mod ln;
|
||||||
pub mod open_text;
|
pub mod open_text;
|
||||||
pub mod scraper;
|
pub mod scraper;
|
||||||
pub mod search;
|
pub mod tracker;
|
||||||
pub mod ln;
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
|
use isahc::config::Configurable;
|
||||||
use isahc::{ReadResponseExt, Request, RequestExt};
|
use isahc::{ReadResponseExt, Request, RequestExt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
use crate::helpers::fixing_text::remove_after_dash;
|
||||||
|
|
||||||
use crate::helpers::fixing_text::fix_html_encoding;
|
use crate::helpers::fixing_text::fix_html_encoding;
|
||||||
|
|
||||||
//gets the full html of the page
|
//gets the full html of the page
|
||||||
pub fn get_html(url: &str) -> String {
|
pub fn get_html(url: &str) -> String {
|
||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.uri(url)
|
.uri(url)
|
||||||
.header(
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
"user-agent",
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36")
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
|
||||||
)
|
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let mut res = req.send().unwrap();
|
||||||
req.send().unwrap().text().unwrap()
|
let html = res.text().unwrap();
|
||||||
|
html
|
||||||
}
|
}
|
||||||
|
|
||||||
//using isahc::prelude::* make a php reqest to get the next page of the ln
|
//using isahc::prelude::* make a php reqest to get the next page of the ln
|
||||||
pub fn get_ln_next_page(ln_id: &str, page: &str) -> String {
|
pub fn get_ln_next_page(ln_id: &str, page: &u32) -> String {
|
||||||
let url = "https://readlightnovels.net/wp-admin/admin-ajax.php".to_string();
|
let url = "https://readlightnovels.net/wp-admin/admin-ajax.php".to_string();
|
||||||
let form = format!(
|
let form = format!(
|
||||||
"action=tw_ajax&type=pagination&id={}.html&page={}",
|
"action=tw_ajax&type=pagination&id={}.html&page={}",
|
||||||
@@ -28,14 +30,15 @@ pub fn get_ln_next_page(ln_id: &str, page: &str) -> String {
|
|||||||
let req = Request::builder()
|
let req = Request::builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
.uri(url)
|
.uri(url)
|
||||||
|
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||||
.header(
|
.header(
|
||||||
"user-agent",
|
"user-agent",
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
||||||
)
|
)
|
||||||
.body(form)
|
.body(form)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let resp = req.send().unwrap().text().unwrap();
|
||||||
req.send().unwrap().text().unwrap()
|
resp
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_full_text(chapter_url: &str) -> String {
|
pub fn get_full_text(chapter_url: &str) -> String {
|
||||||
@@ -102,3 +105,47 @@ pub fn get_ln_text(chapter_url: &str) -> Vec<String> {
|
|||||||
|
|
||||||
fix_html_encoding(&ln_text)
|
fix_html_encoding(&ln_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//gets the list of ln's from the html and returns it as a vector of the ln's name and href
|
||||||
|
pub fn get_ln_list(html: &str) -> Vec<String> {
|
||||||
|
let re = Regex::new(r#"(?m)^\s*(<a href="[^"]*" title="[^"]*")"#).unwrap();
|
||||||
|
let mut ln_list: Vec<String> = Vec::new();
|
||||||
|
for cap in re.captures_iter(html) {
|
||||||
|
ln_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
||||||
|
}
|
||||||
|
ln_list
|
||||||
|
}
|
||||||
|
//gets the titles of the ln's from the html and returns it as a vector of the ln's name
|
||||||
|
pub fn get_ln_titles(ln_list: &Vec<String>) -> Vec<String> {
|
||||||
|
let re = Regex::new(r#"(?m)^\s*<a href="[^"]*" title="([^"]*)""#).unwrap();
|
||||||
|
let mut ln_title: Vec<String> = Vec::new();
|
||||||
|
for ln in ln_list {
|
||||||
|
for cap in re.captures_iter(ln) {
|
||||||
|
ln_title.push(cap.get(1).unwrap().as_str().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ln_title
|
||||||
|
}
|
||||||
|
|
||||||
|
//gets the urls of the ln's from the html and returns it as a vector of the ln's href
|
||||||
|
pub fn get_ln_urls(ln_list: &Vec<String>) -> Vec<String> {
|
||||||
|
let re = Regex::new(r#"(?m)^\s*<a href="([^"]*)""#).unwrap();
|
||||||
|
let mut ln_url: Vec<String> = Vec::new();
|
||||||
|
for ln in ln_list {
|
||||||
|
for cap in re.captures_iter(ln) {
|
||||||
|
ln_url.push(cap.get(1).unwrap().as_str().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ln_url
|
||||||
|
}
|
||||||
|
|
||||||
|
//gets the chapter titles from the html and returns it as a vector of the chapter's name
|
||||||
|
pub fn get_ln_chapters(html: &str) -> Vec<String> {
|
||||||
|
let re = Regex::new(r#"title=(.*?)>"#).unwrap();
|
||||||
|
let mut ln_list: Vec<String> = Vec::new();
|
||||||
|
for cap in re.captures_iter(html) {
|
||||||
|
ln_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
||||||
|
}
|
||||||
|
ln_list = remove_after_dash(&ln_list);
|
||||||
|
ln_list
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
use crate::helpers::{fixing_text::remove_after_dash, take_input::string_input};
|
|
||||||
use colored::Colorize;
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
pub fn search_ln(search: &str) -> String {
|
|
||||||
let mut _is_n = false;
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
while !_is_n {
|
|
||||||
//if search is None, take input from user
|
|
||||||
let search_path = if search == "" {
|
|
||||||
string_input("What ln do you want to read? ")
|
|
||||||
} else {
|
|
||||||
search.to_string()
|
|
||||||
};
|
|
||||||
let search_path = search_path.replace(' ', "+");
|
|
||||||
let url = "https://readlightnovels.net/?s=".to_string();
|
|
||||||
let url = format!("{}{}", url, search_path.trim()).trim().to_string();
|
|
||||||
let html = crate::ln::scraper::get_html(&url).trim().to_string();
|
|
||||||
let ln_list = get_ln_list(&html);
|
|
||||||
//remove first element of ln_list
|
|
||||||
let ln_list = ln_list
|
|
||||||
.iter()
|
|
||||||
.skip(1)
|
|
||||||
.map(|x| x.to_string())
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
let ln_titles = get_ln_titles(&ln_list);
|
|
||||||
let ln_urls = get_ln_urls(&ln_list);
|
|
||||||
let mut count = 0;
|
|
||||||
ln_titles.into_iter().for_each(|ln| {
|
|
||||||
if count % 2 == 0 {
|
|
||||||
println!("({})\t{}", count.to_string().blue(), format_args!("{}", ln.blue()));
|
|
||||||
} else {
|
|
||||||
println!("({})\t{}", count.to_string().yellow(), format_args!("{}", ln.yellow()));
|
|
||||||
}
|
|
||||||
count += 1;
|
|
||||||
});
|
|
||||||
println!("{}\t{}","s:".green(), "Search another title".green());
|
|
||||||
let ln_number = string_input("Enter an option: ");
|
|
||||||
if ln_number != "s" && ln_number.parse::<usize>().is_ok() {
|
|
||||||
let ln_number = ln_number.trim().to_string();
|
|
||||||
let ln_number = ln_number.parse::<usize>().unwrap();
|
|
||||||
let ln_url = &ln_urls[ln_number];
|
|
||||||
let ln_url = ln_url.trim().to_string();
|
|
||||||
_is_n = true;
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
return ln_url;
|
|
||||||
} else {
|
|
||||||
print!("invalid input");
|
|
||||||
}
|
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
|
||||||
}
|
|
||||||
"".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
//gets the list of ln's from the html and returns it as a vector of the ln's name and href
|
|
||||||
fn get_ln_list(html: &str) -> Vec<String> {
|
|
||||||
let re = Regex::new(r#"(?m)^\s*(<a href="[^"]*" title="[^"]*")"#).unwrap();
|
|
||||||
let mut ln_list: Vec<String> = Vec::new();
|
|
||||||
for cap in re.captures_iter(html) {
|
|
||||||
ln_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
|
||||||
}
|
|
||||||
ln_list
|
|
||||||
}
|
|
||||||
//gets the titles of the ln's from the html and returns it as a vector of the ln's name
|
|
||||||
fn get_ln_titles(ln_list: &Vec<String>) -> Vec<String> {
|
|
||||||
let re = Regex::new(r#"(?m)^\s*<a href="[^"]*" title="([^"]*)""#).unwrap();
|
|
||||||
let mut ln_title: Vec<String> = Vec::new();
|
|
||||||
for ln in ln_list {
|
|
||||||
for cap in re.captures_iter(ln) {
|
|
||||||
ln_title.push(cap.get(1).unwrap().as_str().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ln_title
|
|
||||||
}
|
|
||||||
|
|
||||||
//gets the urls of the ln's from the html and returns it as a vector of the ln's href
|
|
||||||
fn get_ln_urls(ln_list: &Vec<String>) -> Vec<String> {
|
|
||||||
let re = Regex::new(r#"(?m)^\s*<a href="([^"]*)""#).unwrap();
|
|
||||||
let mut ln_url: Vec<String> = Vec::new();
|
|
||||||
for ln in ln_list {
|
|
||||||
for cap in re.captures_iter(ln) {
|
|
||||||
ln_url.push(cap.get(1).unwrap().as_str().to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ln_url
|
|
||||||
}
|
|
||||||
|
|
||||||
//gets the chapter titles from the html and returns it as a vector of the chapter's name
|
|
||||||
pub fn get_ln_chapters(html: &str) -> Vec<String> {
|
|
||||||
let re = Regex::new(r#"title=(.*?)>"#).unwrap();
|
|
||||||
let mut ln_list: Vec<String> = Vec::new();
|
|
||||||
for cap in re.captures_iter(html) {
|
|
||||||
ln_list.push(cap.get(1).unwrap().as_str().trim().to_string());
|
|
||||||
}
|
|
||||||
ln_list = remove_after_dash(&ln_list);
|
|
||||||
ln_list
|
|
||||||
}
|
|
||||||
50
src/ln/tracker.rs
Normal file
50
src/ln/tracker.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use serde_json;
|
||||||
|
use std::fs;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
pub fn get_ln_json() -> serde_json::Value {
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
if !config_path.exists() {
|
||||||
|
fs::create_dir_all(&config_path).unwrap();
|
||||||
|
}
|
||||||
|
let json_path = config_path.join("ln_progress.json");
|
||||||
|
if !json_path.exists() {
|
||||||
|
fs::File::create(&json_path).unwrap();
|
||||||
|
}
|
||||||
|
let json = fs::read_to_string(&json_path).unwrap();
|
||||||
|
let json: serde_json::Value = serde_json::from_str(&json).unwrap_or(serde_json::Value::Null);
|
||||||
|
json
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_ln_progress(title: &str, current_page: &u32, selected: &usize) {
|
||||||
|
let config_path = dirs::config_dir().unwrap().join("kami");
|
||||||
|
let json_path = config_path.join("ln_progress.json");
|
||||||
|
let json = fs::read_to_string(&json_path).unwrap();
|
||||||
|
let mut json: serde_json::Value =
|
||||||
|
serde_json::from_str(&json).unwrap_or(serde_json::Value::Null);
|
||||||
|
let mut title_json = serde_json::Map::new();
|
||||||
|
title_json.insert(
|
||||||
|
"current_page".to_string(),
|
||||||
|
serde_json::Value::from(current_page.clone()),
|
||||||
|
);
|
||||||
|
title_json.insert(
|
||||||
|
"selected".to_string(),
|
||||||
|
serde_json::Value::from(selected.clone()),
|
||||||
|
);
|
||||||
|
//insert title_json into json
|
||||||
|
if json[title].is_null() {
|
||||||
|
json[title] = serde_json::Value::from(title_json);
|
||||||
|
} else {
|
||||||
|
json[title]["current_page"] = serde_json::Value::from(current_page.clone());
|
||||||
|
json[title]["selected"] = serde_json::Value::from(selected.clone());
|
||||||
|
}
|
||||||
|
let json = serde_json::to_string_pretty(&json).unwrap();
|
||||||
|
fs::write(&json_path, json).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_ln_progress(title: &str) -> (u32, usize) {
|
||||||
|
let json = get_ln_json();
|
||||||
|
let current_page = json[title]["current_page"].as_u64().unwrap_or(1) as u32;
|
||||||
|
let selected = json[title]["selected"].as_u64().unwrap_or(0) as usize;
|
||||||
|
(current_page, selected)
|
||||||
|
}
|
||||||
171
src/main.rs
171
src/main.rs
@@ -2,68 +2,78 @@ mod anime;
|
|||||||
mod helpers;
|
mod helpers;
|
||||||
mod ln;
|
mod ln;
|
||||||
|
|
||||||
use anime::anime::anime_stream;
|
use anime::anime::anime_ui;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use ln::{scraper::get_ln_next_page, ln::ln_read};
|
//use ln::ui::ln_ui;
|
||||||
use ln::search::search_ln;
|
use ln::ln::ln_ui;
|
||||||
|
|
||||||
use crate::anime::{
|
use crate::anime::{player::*, scraper::*, trackers::*};
|
||||||
player::open_video,
|
use crate::get_token;
|
||||||
scraper::{anime_ep_range, anime_link, anime_names},
|
|
||||||
};
|
|
||||||
use crate::helpers::take_input::{int_input, string_input};
|
use crate::helpers::take_input::{int_input, string_input};
|
||||||
use crate::ln::{menu::chapter_selector, open_text::open_bat, scraper::get_full_text};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut help = false;
|
let mut help = false;
|
||||||
let mut anime = false;
|
let mut anime = false;
|
||||||
let mut ln = false;
|
let mut ln = false;
|
||||||
let mut chapter: u32 = 0;
|
let mut chapter: u32 = 0;
|
||||||
let mut episode: u32 = 0;
|
|
||||||
//let search = option string
|
//let search = option string
|
||||||
let mut search = String::new();
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
let mut provider: String = "gogo".to_string();
|
||||||
|
let mut reader: String = "bat".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 let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
//look at the next argument and see if it is a search term
|
//get the next argument and see if it is = to gogo of vrv
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
match arg.as_str() {
|
||||||
if !arg.starts_with("-") {
|
"vrv" | "gogo" => {
|
||||||
search = arg;
|
provider = arg;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
&_ => provider = "gogo".to_string(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
provider = "vrv".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"--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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"--cast" | "-C" => {
|
||||||
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
|
cast = (true, String::from(arg))
|
||||||
|
} else {
|
||||||
|
println!("{}", "please provide a ip address".red())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"--ln" | "-l" => ln = true,
|
||||||
|
"--chapter" | "-c" => {
|
||||||
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
|
chapter = arg.parse::<u32>().unwrap();
|
||||||
|
} else {
|
||||||
|
chapter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
if arg == "--ln" || arg == "-l" {
|
|
||||||
ln = true;
|
|
||||||
//if let Some(arg) = std::env::args().nth(count + 1) and that arg does not start with a '-' set search to that arg
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
|
||||||
if !arg.starts_with("-") {
|
|
||||||
search = arg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if arg == "--chapter" || arg == "-c" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
|
||||||
chapter = arg.parse::<u32>().unwrap();
|
|
||||||
}else{
|
|
||||||
chapter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if arg == "--episode" || arg == "-e" {
|
|
||||||
if let Some(arg) = std::env::args().nth(count + 1) {
|
|
||||||
episode = arg.parse::<u32>().unwrap();
|
|
||||||
}else{
|
|
||||||
episode = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if help == true{
|
if help == true {
|
||||||
print_help();
|
print_help();
|
||||||
}
|
}
|
||||||
if anime == false && ln == false {
|
if anime == false && ln == false {
|
||||||
@@ -71,50 +81,79 @@ fn main() {
|
|||||||
println!("2: Light Novel");
|
println!("2: Light Novel");
|
||||||
|
|
||||||
let a = int_input("pick your poison: ");
|
let a = int_input("pick your poison: ");
|
||||||
match a{
|
match a {
|
||||||
1 => anime = true,
|
1 => anime = true,
|
||||||
2 => ln = true,
|
2 => ln = true,
|
||||||
_=>println!("invalid option. ")
|
_ => println!("invalid option. "),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if anime == true && ln == true {
|
if anime == true && ln == true {
|
||||||
println!("you can only use one of the arguments at a time");
|
println!("you can only use one of the arguments at a time");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
if ln == true {
|
if ln == true {
|
||||||
ln_read(&search, chapter);
|
//ln_read(&search, chapter);
|
||||||
|
_ = ln_ui(chapter, reader);
|
||||||
} else if anime == true {
|
} else if anime == true {
|
||||||
anime_stream(search, episode);
|
//anime_stream(search, episode, resume);
|
||||||
|
|
||||||
|
let token = get_token();
|
||||||
|
_ = anime_ui(token, provider, cast);
|
||||||
} else {
|
} else {
|
||||||
println!("Invalid argument");
|
println!("Invalid argument");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn page_selector(ln_id: &str, selected_page: u32) -> String {
|
fn print_help() {
|
||||||
get_ln_next_page(ln_id, &selected_page.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_help(){
|
|
||||||
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
|
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
|
||||||
println!("{}", "after this^^^ argument you can enter a search term".green());
|
|
||||||
println!("{}", "for exaple kami -a \"one piece\"");
|
|
||||||
//print blank line
|
//print blank line
|
||||||
println!("");
|
println!("");
|
||||||
println!("episode:\t{}", format_args!("{}", "-e --episode".red()));
|
println!(
|
||||||
println!("{}", "after this^^^ argument you can enter a chapter number".green());
|
"cast:\t\t{}",
|
||||||
println!("{}", "for exaple kami -c 200");
|
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
|
||||||
//print blank line
|
);
|
||||||
println!("");
|
println!("");
|
||||||
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
||||||
println!("{}", "after this^^^ argument you can enter a search term".green());
|
|
||||||
println!("{}", "for exaple kami -l \"one piece\"");
|
|
||||||
//print blank line
|
//print blank line
|
||||||
println!("");
|
println!("");
|
||||||
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
|
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
|
||||||
println!("{}", "after this^^^ argument you can enter a chapter number".green());
|
println!(
|
||||||
|
"{}",
|
||||||
|
"after this^^^ argument you can enter a chapter number".green()
|
||||||
|
);
|
||||||
println!("{}", "for exaple kami -c 200");
|
println!("{}", "for exaple kami -c 200");
|
||||||
//print blank line
|
//print blank line
|
||||||
println!("");
|
println!("");
|
||||||
|
println!("provider:\t{}", format_args!("{}", "-r --provider".red()));
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
"after this^^^ argument you can enter a provider".green()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"if no provider is entered it will default to {}",
|
||||||
|
"vrv".green()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"if the -r argument is not used it will default to {}",
|
||||||
|
"gogo".green()
|
||||||
|
);
|
||||||
|
println!("the providers are {} or {}", "gogo".green(), "vrv".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!("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);
|
||||||
|
|||||||
Reference in New Issue
Block a user