mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
refactor: better file hierarchy
This commit is contained in:
179
Cargo.lock
generated
179
Cargo.lock
generated
@@ -30,7 +30,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -45,6 +45,12 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.1.0"
|
||||
@@ -83,7 +89,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"lazy_static",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -117,7 +123,7 @@ dependencies = [
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"socket2",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -133,7 +139,27 @@ dependencies = [
|
||||
"openssl-sys",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -203,6 +229,17 @@ dependencies = [
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@@ -276,6 +313,28 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
|
||||
|
||||
[[package]]
|
||||
name = "kami"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"colored",
|
||||
"dirs",
|
||||
"isahc",
|
||||
"regex",
|
||||
"termsize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
dependencies = [
|
||||
"winapi 0.2.8",
|
||||
"winapi-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -319,16 +378,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log_e"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"colored",
|
||||
"isahc",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.9"
|
||||
@@ -347,6 +396,12 @@ version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
||||
|
||||
[[package]]
|
||||
name = "numtoa"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.12.0"
|
||||
@@ -426,7 +481,7 @@ dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wepoll-ffi",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -447,6 +502,35 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_termios"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
||||
dependencies = [
|
||||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.6"
|
||||
@@ -498,7 +582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -512,6 +596,51 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"numtoa",
|
||||
"redox_syscall",
|
||||
"redox_termios",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termsize"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e86d824a8e90f342ad3ef4bd51ef7119a9b681b0cc9f8ee7b2852f02ccd2517"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"kernel32-sys",
|
||||
"libc",
|
||||
"termion",
|
||||
"winapi 0.2.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
@@ -615,6 +744,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wepoll-ffi"
|
||||
version = "0.1.2"
|
||||
@@ -624,6 +759,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@@ -634,6 +775,12 @@ dependencies = [
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-build"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "log_e"
|
||||
#author = "mrfluffy-dev"
|
||||
name = "kami"
|
||||
author = "mrfluffy-dev"
|
||||
license = "GPL-3.0"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -12,3 +12,5 @@ regex = "1.5.6"
|
||||
colored = "2.0.0"
|
||||
isahc = "1.7.2"
|
||||
base64 = "0.13"
|
||||
termsize = "0.1.6"
|
||||
dirs = "4.0"
|
||||
|
||||
95
README.org
95
README.org
@@ -1,15 +1,86 @@
|
||||
#+title: Readme
|
||||
#+OPTIONS: toc:2
|
||||
* Table of content
|
||||
1. [[#Why-use-kami][Why use kami]]
|
||||
2. [[#Dependencies][Dependencies]]
|
||||
3. [[#Install][Install]]
|
||||
- [[#LinuxMac][Linux/mac]]
|
||||
- [[#Windows][Windows]]
|
||||
4. [[#Honorable-mentions][Honorable mentions]]
|
||||
* 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.
|
||||
Also rust is fast as fuck boiiiii.
|
||||
* Dependencies
|
||||
1. [[https://github.com/sharkdp/bat][bat]]
|
||||
2. [[https://mpv.io/][mpv]]
|
||||
3. [[https://git-scm.com/][gitbash]](if on windows)
|
||||
I will be explaining how to install them.
|
||||
|
||||
* Install
|
||||
1.
|
||||
#+begin_src shell
|
||||
git clone https://github.com/mrfluffy-dev/kami.git && cd kami
|
||||
#+end_src
|
||||
2.
|
||||
#+begin_src shell
|
||||
cargo build --release
|
||||
#+end_src
|
||||
3.
|
||||
#+begin_src shell
|
||||
cp target/release/kami /usr/bin/kami
|
||||
#+end_src
|
||||
** Linux/Mac
|
||||
1. install bat and mpv with your package manager(homebrew if on mac)
|
||||
2. Clone the repo for kami.
|
||||
#+begin_src shell
|
||||
git clone https://github.com/mrfluffy-dev/kami.git && cd kami
|
||||
#+end_src
|
||||
4. install [[https://www.rust-lang.org/tools/install][Rust]]
|
||||
5. Build kami using cargo.
|
||||
#+begin_src shell
|
||||
cargo build --release
|
||||
#+end_src
|
||||
6. Copy kami to your path.
|
||||
#+begin_src shell
|
||||
cp target/release/kami /usr/local/bin/kami
|
||||
#+end_src
|
||||
** Windows
|
||||
1. install scoop
|
||||
#+begin_src shell
|
||||
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
irm get.scoop.sh | iex
|
||||
#+end_src
|
||||
2. install git
|
||||
#+begin_src shell
|
||||
scoop install git
|
||||
#+end_src
|
||||
1. install mpv
|
||||
#+begin_src shell
|
||||
scoop bucket add extras
|
||||
scoop install mpv
|
||||
#+end_src
|
||||
2. install bat
|
||||
#+begin_src shell
|
||||
scoop install bat
|
||||
#+end_src
|
||||
3. install [[https://www.rust-lang.org/tools/install][Rust]]
|
||||
4. (Optional but I highly recommend it) adding bash to windows terminal.
|
||||
1. install windows terminal from the Microsoft store.
|
||||
2. open the terminal.
|
||||
3. open settings.
|
||||
4. click "Add a new profile"
|
||||
5. click "New empty profile"
|
||||
6. Click on "name" and rename it to "Git Bash"
|
||||
7. Click on "Command line" and click "Browse..."
|
||||
8. if you installed git using scoop then follow this(else the steps are mostly the same just a different path)
|
||||
navigate to ~C:\User\USERNAME\scoop\apps\git\2.37.1.windows.1\bin\bash.exe~
|
||||
Where USERNAME is your username
|
||||
note that the name ~2.37.1.windows.1~ might be slightly different on your system
|
||||
9. click "Open"
|
||||
10. Click "Starting directory" and uncheck "Use parent process directory"
|
||||
11. Click "Save"
|
||||
12. now you can open gitbash from windows terminal
|
||||
5. Clone the repo for kami
|
||||
#+begin_src shell
|
||||
git clone https://github.com/mrfluffy-dev/kami.git && cd kami
|
||||
#+end_src
|
||||
6. Build kami using cargo
|
||||
#+begin_src shell
|
||||
cargo build --release
|
||||
#+end_src
|
||||
7. copy kami to path
|
||||
#+begin_src
|
||||
cp target/release/kami.exe /usr/bin/kami
|
||||
#+end_src
|
||||
8. open kami by using ~kami~
|
||||
* Honorable mentions
|
||||
- [[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.
|
||||
|
||||
86
src/anime/anime.rs
Normal file
86
src/anime/anime.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use crate::{string_input,int_input};
|
||||
use crate::{anime_names,anime_ep_range,anime_link};
|
||||
use crate::open_video;
|
||||
use crate::main;
|
||||
use colored::Colorize;
|
||||
//use crate
|
||||
pub fn anime_stream(first_run: bool) {
|
||||
let query = if std::env::args().len() > 2 && first_run {
|
||||
std::env::args().nth(2).unwrap()
|
||||
} else {
|
||||
string_input("Search anime: ")
|
||||
};
|
||||
let anime_list = anime_names(&query);
|
||||
let mut count = 0;
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
anime_list.iter().for_each(|anime| {
|
||||
if count % 2 == 0 {
|
||||
println!(
|
||||
"({})\t{}",
|
||||
format_args!("{}", count.to_string().blue()),
|
||||
format_args!("{}", anime.blue())
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"({})\t{}",
|
||||
format_args!("{}", count.to_string().yellow()),
|
||||
format_args!("{}", anime.yellow())
|
||||
);
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
let mut anime_num: usize = usize::MAX;
|
||||
while anime_num == usize::max_value() || anime_num > anime_list.len() {
|
||||
anime_num = int_input("Enter anime number: ");
|
||||
if anime_num > anime_list.len() {
|
||||
println!("Invalid anime number");
|
||||
}
|
||||
}
|
||||
let title = &anime_list[anime_num];
|
||||
let ep_range = anime_ep_range(title);
|
||||
// if there is only one episode, then don't ask user to choose episode
|
||||
if ep_range == 1 {
|
||||
let link = anime_link(title, 1);
|
||||
open_video(link);
|
||||
main();
|
||||
} else {
|
||||
println!("select episode 1-{}: ", ep_range);
|
||||
let mut ep_num: usize = usize::MAX;
|
||||
while ep_num == usize::max_value() || ep_num > ep_range as usize {
|
||||
ep_num = int_input("Enter episode number: ");
|
||||
if ep_num > ep_range as usize {
|
||||
println!("Invalid episode number");
|
||||
}
|
||||
}
|
||||
loop{
|
||||
let link = anime_link(title, ep_num as u64);
|
||||
open_video(link);
|
||||
println!("{}","n: next episode".green());
|
||||
println!("{}","p: previous episode".yellow());
|
||||
println!("{}","s: search another anime".green());
|
||||
println!("{}","q: quit".red());
|
||||
let input = string_input("Enter command: ");
|
||||
if input == "n" {
|
||||
if ep_num == ep_range as usize {
|
||||
println!("No more episodes");
|
||||
} else {
|
||||
ep_num += 1;
|
||||
}
|
||||
} else if input == "p" {
|
||||
if ep_num == 1 {
|
||||
println!("No previous episodes");
|
||||
} else {
|
||||
ep_num -= 1;
|
||||
}
|
||||
} else if input == "s" {
|
||||
//remove all the arguments
|
||||
anime_stream(false);
|
||||
} else if input == "q" {
|
||||
std::process::exit(0);
|
||||
}
|
||||
else{
|
||||
println!("Invalid command");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod player;
|
||||
pub mod scraper;
|
||||
pub mod anime;
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn anime_ep_range(anime_name: &str) -> u16 {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn anime_link(title: &str, ep: u16) -> (String, String) {
|
||||
pub fn anime_link(title: &str, ep: u64) -> (String, String) {
|
||||
let url = format!("https://animixplay.to/v1/{}", title);
|
||||
let html = get_anime_html(&url);
|
||||
let re = Regex::new(r#"(?m)\?id=([^&]+)"#).unwrap();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
pub fn string_input(prompt: &str) -> String {
|
||||
print!("{}", prompt);
|
||||
let mut input = String::new();
|
||||
@@ -17,15 +16,21 @@ pub fn int_input(prompt: &str) -> usize {
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Error reading from STDIN");
|
||||
input.trim().parse::<usize>().unwrap()
|
||||
//try to parse the input as usize else return max usize
|
||||
match input.trim().parse::<usize>() {
|
||||
Ok(i) => i,
|
||||
Err(_) => {
|
||||
usize::max_value()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn u16_input(prompt: &str) -> u16 {
|
||||
print!("{}", prompt);
|
||||
let mut input = String::new();
|
||||
let _ = io::stdout().flush();
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Error reading from STDIN");
|
||||
input.trim().parse::<u16>().unwrap()
|
||||
}
|
||||
//pub fn u16_input(prompt: &str) -> u16 {
|
||||
// print!("{}", prompt);
|
||||
// let mut input = String::new();
|
||||
// let _ = io::stdout().flush();
|
||||
// io::stdin()
|
||||
// .read_line(&mut input)
|
||||
// .expect("Error reading from STDIN");
|
||||
// input.trim().parse::<u16>().unwrap()
|
||||
//}
|
||||
|
||||
31
src/ln/ln.rs
Normal file
31
src/ln/ln.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use crate::{search_ln,chapter_selector,get_full_text,open_bat};
|
||||
pub fn ln_read(){
|
||||
let ln_url = search_ln();
|
||||
let mut selected_page = 1;
|
||||
loop {
|
||||
//make empty tuple called chapter_url with (String, u32, u32)
|
||||
let chapter_url = chapter_selector(&ln_url, selected_page);
|
||||
selected_page = chapter_url.1;
|
||||
let full_text = get_full_text(&chapter_url.0);
|
||||
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");
|
||||
};
|
||||
//open temp.txt in cat for user to read
|
||||
let _com = open_bat();
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
|
||||
let exit = false;
|
||||
while exit == false {
|
||||
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);
|
||||
@@ -22,15 +21,16 @@ pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
|
||||
let mut count = 0;
|
||||
ln_chapters.into_iter().for_each(|chaprer| {
|
||||
if count % 2 == 0 {
|
||||
println!("({})\t{}", count, format_args!("{}", chaprer.blue()));
|
||||
println!("({})\t{}", count.to_string().blue(), format_args!("{}", chaprer.blue()));
|
||||
} else {
|
||||
println!("({})\t{}", count, format_args!("{}", chaprer.yellow()));
|
||||
println!("({})\t{}", count.to_string().yellow(), format_args!("{}", chaprer.yellow()));
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
println!("(n)\t{}", "Go to next page".red());
|
||||
println!("(b)\t{}", "Go to previous page".red());
|
||||
println!("(q)\t{}", "go back to main menu".red());
|
||||
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;
|
||||
@@ -39,14 +39,23 @@ pub fn chapter_selector(ln_url: &str, mut selected_page: u32) -> (String, u32) {
|
||||
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 {
|
||||
}
|
||||
else {
|
||||
let chapter_number = chapter_number.trim().to_string();
|
||||
let chapter_number = chapter_number.parse::<usize>().unwrap();
|
||||
let chapter_url = &ln_chapters_urls[chapter_number];
|
||||
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);
|
||||
}
|
||||
}
|
||||
("".to_string(), 1)
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ pub mod menu;
|
||||
pub mod open_text;
|
||||
pub mod scraper;
|
||||
pub mod search;
|
||||
pub mod ln;
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
use std::io::Result;
|
||||
use std::process::{Command, ExitStatus};
|
||||
use std::process::{Command, ExitStatus, Stdio};
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
pub fn open_bat() -> 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("bat")
|
||||
.arg("--paging")
|
||||
.arg("always")
|
||||
.arg("/tmp/log_e")
|
||||
.arg("-l")
|
||||
.arg("markdown")
|
||||
.stdin(soft_wrap.stdout.unwrap())
|
||||
.spawn()?
|
||||
.wait()
|
||||
}
|
||||
|
||||
@@ -23,19 +23,15 @@ pub fn search_ln() -> String {
|
||||
let mut count = 0;
|
||||
ln_titles.into_iter().for_each(|ln| {
|
||||
if count % 2 == 0 {
|
||||
println!("({})\t{}", count, format_args!("{}", ln.blue()));
|
||||
println!("({})\t{}", count.to_string().blue(), format_args!("{}", ln.blue()));
|
||||
} else {
|
||||
println!("({})\t{}", count, format_args!("{}", ln.yellow()));
|
||||
println!("({})\t{}", count.to_string().yellow(), format_args!("{}", ln.yellow()));
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
println!("(n)\t{}", "Search another title".red());
|
||||
let mut ln_number = String::new();
|
||||
std::io::stdin()
|
||||
.read_line(&mut ln_number)
|
||||
.expect("Failed to read line");
|
||||
ln_number = ln_number.trim().to_string();
|
||||
if ln_number != "n" {
|
||||
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];
|
||||
@@ -43,6 +39,8 @@ pub fn search_ln() -> String {
|
||||
_is_n = true;
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
return ln_url;
|
||||
} else {
|
||||
print!("invalid input");
|
||||
}
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
}
|
||||
|
||||
66
src/main.rs
66
src/main.rs
@@ -2,18 +2,16 @@ mod anime;
|
||||
mod helpers;
|
||||
mod ln;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use anime::anime::anime_stream;
|
||||
use colored::Colorize;
|
||||
use ln::scraper::get_ln_next_page;
|
||||
use ln::{scraper::get_ln_next_page, ln::ln_read};
|
||||
use ln::search::search_ln;
|
||||
|
||||
use crate::anime::{
|
||||
player::open_video,
|
||||
scraper::{anime_ep_range, anime_link, anime_names},
|
||||
};
|
||||
use crate::helpers::take_input::{int_input, string_input, u16_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() {
|
||||
@@ -31,63 +29,9 @@ fn main() {
|
||||
std::process::exit(0);
|
||||
}
|
||||
if _arg == "l" {
|
||||
let ln_url = search_ln();
|
||||
let mut selected_page = 1;
|
||||
loop {
|
||||
//make empty tuple called chapter_url with (String, u32, u32)
|
||||
let chapter_url = chapter_selector(&ln_url, selected_page);
|
||||
selected_page = chapter_url.1;
|
||||
let full_text = get_full_text(&chapter_url.0);
|
||||
//write full_text to file called temp.txt
|
||||
let mut file = File::create("/tmp/log_e").expect("Unable to create file");
|
||||
file.write_all(full_text.as_bytes())
|
||||
.expect("Unable to write to file");
|
||||
//close file
|
||||
file.sync_all().expect("Unable to sync file");
|
||||
//open temp.txt in cat for user to read
|
||||
let _com = open_bat();
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
}
|
||||
ln_read();
|
||||
} else if _arg == "a" {
|
||||
let query = if std::env::args().len() > 2 {
|
||||
std::env::args().nth(2).unwrap()
|
||||
} else {
|
||||
string_input("Enter query: ")
|
||||
};
|
||||
let anime_list = anime_names(&query);
|
||||
let mut count = 0;
|
||||
print!("\x1B[2J\x1B[1;1H");
|
||||
anime_list.iter().for_each(|anime| {
|
||||
if count % 2 == 0 {
|
||||
println!(
|
||||
"({})\t{}",
|
||||
format_args!("{}", count.to_string().blue()),
|
||||
format_args!("{}", anime.blue())
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"({})\t{}",
|
||||
format_args!("{}", count.to_string().yellow()),
|
||||
format_args!("{}", anime.yellow())
|
||||
);
|
||||
}
|
||||
count += 1;
|
||||
});
|
||||
let anime_num = int_input("Enter anime number: ");
|
||||
let title = &anime_list[anime_num];
|
||||
let ep_range = anime_ep_range(title);
|
||||
// if there is only one episode, then don't ask user to choose episode
|
||||
if ep_range == 1 {
|
||||
let link = anime_link(title, 1);
|
||||
open_video(link);
|
||||
main();
|
||||
} else {
|
||||
println!("select episode 1-{}: ", ep_range);
|
||||
let ep_num = u16_input("Enter episode number: ");
|
||||
let link = anime_link(title, ep_num);
|
||||
open_video(link);
|
||||
main();
|
||||
}
|
||||
anime_stream(true)
|
||||
} else {
|
||||
println!("Invalid argument");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user