6 Commits

Author SHA1 Message Date
newbee1905
c2ca356940 Merge branch 'consumet' into clap 2023-02-06 02:21:30 +07:00
newbee1905
578e773b04 Merge branch 'merge-an-ln-ui' into clap 2023-02-05 02:43:20 +07:00
newbee1905
6bd2ad922c feat: Use subcommands instead of flags for mode 2023-02-05 02:37:40 +07:00
newbee1905
c0d17dd230 chore: merge with _real_ consumet branch 2023-02-05 00:37:45 +07:00
newbee1905
5b9f060da3 feat: Setting up clap 2023-02-04 15:10:25 +07:00
newbee1905
c289177f65 feat(wip): Setting up clap 2023-02-04 14:35:38 +07:00
3 changed files with 267 additions and 169 deletions

227
Cargo.lock generated
View File

@@ -126,6 +126,43 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"is-terminal",
"once_cell",
"strsim",
"termcolor",
]
[[package]]
name = "clap_derive"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "color_quant" name = "color_quant"
version = "1.1.0" version = "1.1.0"
@@ -352,6 +389,27 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.2" version = "2.5.2"
@@ -501,6 +559,12 @@ dependencies = [
"crunchy", "crunchy",
] ]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@@ -519,6 +583,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hermit-abi"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01"
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.8" version = "0.2.8"
@@ -569,6 +639,28 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "io-lifetimes"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
dependencies = [
"libc",
"windows-sys 0.45.0",
]
[[package]]
name = "is-terminal"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.0",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
]
[[package]] [[package]]
name = "isahc" name = "isahc"
version = "1.7.2" version = "1.7.2"
@@ -625,6 +717,7 @@ name = "kami"
version = "0.6.0" version = "0.6.0"
dependencies = [ dependencies = [
"base64", "base64",
"clap",
"colored", "colored",
"crossterm 0.24.0", "crossterm 0.24.0",
"dirs", "dirs",
@@ -663,9 +756,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.126" version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]] [[package]]
name = "libnghttp2-sys" name = "libnghttp2-sys"
@@ -689,6 +782,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.7" version = "0.4.7"
@@ -868,6 +967,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]] [[package]]
name = "parking" name = "parking"
version = "2.0.0" version = "2.0.0"
@@ -961,10 +1066,34 @@ dependencies = [
] ]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro-error"
version = "1.0.39" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -1117,6 +1246,20 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "rustix"
version = "0.36.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.45.0",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.11" version = "1.0.11"
@@ -1263,6 +1406,12 @@ dependencies = [
"lock_api", "lock_api",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.96" version = "1.0.96"
@@ -1484,6 +1633,12 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "viuer" name = "viuer"
version = "0.6.2" version = "0.6.2"
@@ -1656,19 +1811,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0", "windows_aarch64_msvc 0.42.1",
"windows_i686_gnu 0.42.0", "windows_i686_gnu 0.42.1",
"windows_i686_msvc 0.42.0", "windows_i686_msvc 0.42.1",
"windows_x86_64_gnu 0.42.0", "windows_x86_64_gnu 0.42.1",
"windows_x86_64_gnullvm", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0", "windows_x86_64_msvc 0.42.1",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.1",
"windows_i686_gnu 0.42.1",
"windows_i686_msvc 0.42.1",
"windows_x86_64_gnu 0.42.1",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.1",
] ]
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
@@ -1678,9 +1857,9 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
@@ -1690,9 +1869,9 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
@@ -1702,9 +1881,9 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
@@ -1714,15 +1893,15 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
@@ -1732,6 +1911,6 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.42.0" version = "0.42.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"

View File

@@ -20,4 +20,5 @@ crossterm = "0.24.0"
unicode-width = "0.1.9" unicode-width = "0.1.9"
rust_cast = "0.17.0" rust_cast = "0.17.0"
viuer = { version = "0.6", features = ["sixel"] } viuer = { version = "0.6", features = ["sixel"] }
clap = { version = "4.1.4", features = ["derive"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"

View File

@@ -7,159 +7,77 @@ mod ui;
extern crate lazy_static; extern crate lazy_static;
use anime::anime::anime_ui; use anime::anime::anime_ui;
use colored::Colorize;
//use ln::ui::ln_ui;
use ln::ln::ln_ui; use ln::ln::ln_ui;
use crate::anime::trackers::*; use crate::anime::trackers::*;
use crate::get_token; use crate::get_token;
use crate::helpers::take_input::{int_input, string_input}; use crate::helpers::take_input::{int_input, string_input};
use clap::{Parser, Subcommand};
#[derive(Subcommand, Debug)]
enum KamiMode {
#[command(name = "ln", about = "Search Light Novel to read.")]
LightNovel,
#[command(about = "Search Anime to read.")]
Anime,
}
#[derive(Parser, Debug)]
#[command(author, version, about = "A scraper to read light novels and watch anime in your terminal.", long_about = None)]
struct Args {
#[command(subcommand)]
mode: Option<KamiMode>,
/// Use anime mode
#[arg(short, long)]
anime: bool,
/// Use light novel mode
#[arg(short, long)]
ln: bool,
#[arg(short, long, default_value_t = 0)]
chapter: u32,
#[arg(short = 'C', long, default_value = "0")]
cast: String,
/// Provider for anime or light novel
#[arg(short = 'r', long, default_value = "gogo")]
provider: String,
/// Text renderer for light novel
#[arg(short = 'R', long, default_value = "bat")]
reader: String,
}
fn main() { fn main() {
let mut help = false; let args = Args::parse();
let mut anime = false;
let mut ln = false; let mode = match &args.mode {
let mut chapter: u32 = 0; None => {
//let search = option string println!("1: Anime");
let mut count = 0; println!("2: Light Novel");
let mut provider: String = "zoro".to_string();
let mut reader: String = "bat".to_string(); let opt = int_input("pick your poison: ");
let mut cast = (false, "0".to_string());
for arg in std::env::args() { match opt {
match &*arg { 1 => &KamiMode::Anime,
"--help" | "-h" => help = true, 2 => &KamiMode::LightNovel,
"--anime" | "-a" => anime = true, _ => {
"--provider" | "-r" => { println!("invalid option.");
if let Some(arg) = std::env::args().nth(count + 1) { std::process::exit(0);
//get the next argument and see if it is = to gogo of vrv
match arg.as_str() {
"zoro" | "gogo" => {
provider = arg;
count += 1;
}
&_ => provider = "gogo".to_string(),
}
} else {
provider = "zoro".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;
}
}
&_ => {}
} }
Some(m) => m,
};
count += 1; let _ = match mode {
} &KamiMode::LightNovel => ln_ui(args.chapter, args.reader),
&KamiMode::Anime => {
if help == true { let token = get_token();
print_help(); anime_ui(token, args.provider, (args.cast == "0", args.cast))
} }
if anime == false && ln == false { };
println!("1: Anime");
println!("2: Light Novel");
let a = int_input("pick your poison: ");
match a {
1 => anime = true,
2 => ln = true,
_ => println!("invalid option. "),
};
}
if anime == true && ln == true {
println!("you can only use one of the arguments at a time");
std::process::exit(0);
}
if ln == true {
//ln_read(&search, chapter);
_ = ln_ui(chapter, reader);
} else if anime == true {
//anime_stream(search, episode, resume);
let token = get_token();
_ = anime_ui(token, provider, cast);
} else {
println!("Invalid argument");
}
}
fn print_help() {
println!("anime:\t\t{}", format_args!("{}", "-a --anime".red()));
//print blank line
println!("");
println!(
"cast:\t\t{}",
format_args!("{} {}", "-C --cast".red(), "<IP Adress>".green())
);
println!("");
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
//print blank line
println!("");
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
println!(
"{}",
"after this^^^ argument you can enter a chapter number".green()
);
println!("{}", "for exaple kami -c 200");
//print blank line
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 {}",
"gogo".green()
);
println!(
"if the -r argument is not used it will default to {}",
"zoro".green()
);
println!("the providers are {} or {}", "gogo".green(), "zoro".green());
println!("");
println!("reader:\t\t{}", format_args!("{}", "-R --reader".red()));
println!(
"{}",
"after this^^^ argument you can enter a reader".green()
);
println!(
"if no reader is entered it will default to {}",
"bat".green()
);
println!(
"if the -R argument is not used it will default to {}",
"bat".green()
);
println!("the readers are {} or {}", "bat".green(), "glow".green());
println!("");
println!("help:\t\t{}", format_args!("{}", "-h --help".red()));
//kill the program
std::process::exit(0);
} }