mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
added better arguments for anime and light novels
This commit is contained in:
@@ -4,11 +4,11 @@
|
|||||||
1. [[#Why-use-kami][Why use kami]]
|
1. [[#Why-use-kami][Why use kami]]
|
||||||
2. [[#Dependencies][Dependencies]]
|
2. [[#Dependencies][Dependencies]]
|
||||||
3. [[#Install][Install]]
|
3. [[#Install][Install]]
|
||||||
- [[#Linux--Mac][Linux/mac]]
|
- [[#LinuxMac][Linux/mac]]
|
||||||
- [[#Windows][Windows]]
|
- [[#Windows][Windows]]
|
||||||
4. [[#Honorable-mentions][Honorable mentions]]
|
4. [[#Honorable-mentions][Honorable mentions]]
|
||||||
* Why use kami
|
* Why use kami
|
||||||
well its a fast and easy way to watch anime and read light novels right i 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.
|
||||||
* Dependencies
|
* Dependencies
|
||||||
1. [[https://github.com/sharkdp/bat][bat]]
|
1. [[https://github.com/sharkdp/bat][bat]]
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ use crate::open_video;
|
|||||||
use crate::main;
|
use crate::main;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
//use crate
|
//use crate
|
||||||
pub fn anime_stream(first_run: bool) {
|
pub fn anime_stream(search: String, episode: u32) {
|
||||||
let query = if std::env::args().len() > 2 && first_run {
|
let query = if search != "" {
|
||||||
std::env::args().nth(2).unwrap()
|
search
|
||||||
} else {
|
}
|
||||||
|
else{
|
||||||
string_input("Search anime: ")
|
string_input("Search anime: ")
|
||||||
};
|
};
|
||||||
|
|
||||||
let anime_list = anime_names(&query);
|
let anime_list = anime_names(&query);
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
print!("\x1B[2J\x1B[1;1H");
|
||||||
@@ -43,15 +45,24 @@ pub fn anime_stream(first_run: bool) {
|
|||||||
let link = anime_link(title, 1);
|
let link = anime_link(title, 1);
|
||||||
open_video(link);
|
open_video(link);
|
||||||
main();
|
main();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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{
|
}else{
|
||||||
println!("select episode 1-{}: ", ep_range);
|
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 {
|
while ep_num == usize::max_value() || ep_num > ep_range as usize {
|
||||||
ep_num = int_input("Enter episode number: ");
|
ep_num = int_input("Enter episode number: ");
|
||||||
if ep_num > ep_range as usize {
|
if ep_num > ep_range as usize {
|
||||||
println!("Invalid episode number");
|
println!("Invalid episode number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
loop{
|
loop{
|
||||||
let link = anime_link(title, ep_num as u64);
|
let link = anime_link(title, ep_num as u64);
|
||||||
open_video(link);
|
open_video(link);
|
||||||
@@ -74,7 +85,7 @@ pub fn anime_stream(first_run: bool) {
|
|||||||
}
|
}
|
||||||
} else if input == "s" {
|
} else if input == "s" {
|
||||||
//remove all the arguments
|
//remove all the arguments
|
||||||
anime_stream(false);
|
anime_stream("".to_string(), 0);
|
||||||
} else if input == "q" {
|
} else if input == "q" {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
pub fn string_input(prompt: &str) -> String {
|
pub fn string_input(prompt: &str) -> String {
|
||||||
print!("{}", prompt);
|
print!("{}", prompt);
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use crate::{search_ln,chapter_selector,get_full_text,open_bat};
|
use crate::{search_ln,chapter_selector,get_full_text,open_bat};
|
||||||
pub fn ln_read(){
|
pub fn ln_read(search: &str, chapter: u32){
|
||||||
let ln_url = search_ln();
|
//convert search in to Option<&str>
|
||||||
|
let ln_url = search_ln(&search);
|
||||||
|
let chapter = chapter as f64;
|
||||||
let mut selected_page = 1;
|
let mut selected_page = 1;
|
||||||
|
if chapter != 0.0{
|
||||||
|
selected_page = (chapter/48.0).ceil() as u32;
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
//make empty tuple called chapter_url with (String, u32, u32)
|
//make empty tuple called chapter_url with (String, u32, u32)
|
||||||
let chapter_url = chapter_selector(&ln_url, selected_page);
|
let chapter_url = chapter_selector(&ln_url, selected_page);
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ use crate::helpers::{fixing_text::remove_after_dash, take_input::string_input};
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
pub fn search_ln() -> String {
|
pub fn search_ln(search: &str) -> String {
|
||||||
let mut _is_n = false;
|
let mut _is_n = false;
|
||||||
print!("\x1B[2J\x1B[1;1H");
|
print!("\x1B[2J\x1B[1;1H");
|
||||||
while !_is_n {
|
while !_is_n {
|
||||||
let search_path = string_input("What ln do you want to read? ");
|
//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 search_path = search_path.replace(' ', "+");
|
||||||
let url = "https://readlightnovels.net/?s=".to_string();
|
let url = "https://readlightnovels.net/?s=".to_string();
|
||||||
let url = format!("{}{}", url, search_path.trim()).trim().to_string();
|
let url = format!("{}{}", url, search_path.trim()).trim().to_string();
|
||||||
|
|||||||
79
src/main.rs
79
src/main.rs
@@ -1,35 +1,62 @@
|
|||||||
use crate::anime::anime::anime_stream;
|
|
||||||
use crate::anime::scraper::{anime_ep_range, anime_link, anime_names};
|
|
||||||
use crate::ln::ln::ln_read;
|
|
||||||
use crate::ln::menu::chapter_selector;
|
|
||||||
use crate::ln::open_text::open_bat;
|
|
||||||
use crate::ln::scraper::get_full_text;
|
|
||||||
use crate::{
|
|
||||||
anime::player::open_video,
|
|
||||||
helpers::take_input::{int_input, string_input},
|
|
||||||
ln::search::search_ln,
|
|
||||||
};
|
|
||||||
use colored::Colorize;
|
|
||||||
use ln::scraper::get_ln_next_page;
|
|
||||||
mod anime;
|
mod anime;
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod ln;
|
mod ln;
|
||||||
|
|
||||||
|
use anime::anime::anime_stream;
|
||||||
|
use colored::Colorize;
|
||||||
|
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};
|
||||||
|
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 episode: u32 = 0;
|
||||||
|
//let search = option string
|
||||||
|
let mut search = String::new();
|
||||||
|
let mut count = 0;
|
||||||
for arg in std::env::args() {
|
for arg in std::env::args() {
|
||||||
if arg == "--help" || arg == "-h" {
|
if arg == "--help" || arg == "-h" {
|
||||||
help = true;
|
help = true;
|
||||||
}
|
}
|
||||||
if arg == "--anime" || arg == "-a" {
|
if arg == "--anime" || arg == "-a" {
|
||||||
anime = true;
|
anime = true;
|
||||||
|
//look at the next argument and see if it is a search term
|
||||||
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
|
search = arg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if arg == "--ln" || arg == "-l" {
|
if arg == "--ln" || arg == "-l" {
|
||||||
ln = true;
|
ln = true;
|
||||||
|
if let Some(arg) = std::env::args().nth(count + 1) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if help == true{
|
if help == true{
|
||||||
print_help();
|
print_help();
|
||||||
}
|
}
|
||||||
@@ -41,9 +68,9 @@ fn main() {
|
|||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
if ln == true {
|
if ln == true {
|
||||||
ln_read();
|
ln_read(&search, chapter);
|
||||||
} else if anime == true {
|
} else if anime == true {
|
||||||
anime_stream(true)
|
anime_stream(search, episode);
|
||||||
} else {
|
} else {
|
||||||
println!("Invalid argument");
|
println!("Invalid argument");
|
||||||
}
|
}
|
||||||
@@ -55,11 +82,25 @@ fn page_selector(ln_id: &str, selected_page: u32) -> String {
|
|||||||
|
|
||||||
fn print_help(){
|
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 either enter a search term".green());
|
||||||
|
println!("{}", "for exaple kami -a \"one piece\"");
|
||||||
|
//print blank line
|
||||||
|
println!("");
|
||||||
|
println!("episode:\t{}", format_args!("{}", "-e --episode".red()));
|
||||||
|
println!("{}", "after this^^^ argument you can either enter a chapter number".green());
|
||||||
|
println!("{}", "for exaple kami -c 200");
|
||||||
|
//print blank line
|
||||||
|
println!("");
|
||||||
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
println!("light novel:\t{}", format_args!("{}", "-l --ln".red()));
|
||||||
println!(
|
println!("{}", "after this^^^ argument you can either enter a search term".green());
|
||||||
"you can add the name of the anime you want to watch after the {} argument",
|
println!("{}", "for exaple kami -l \"one piece\"");
|
||||||
format_args!("{}", "-a --anime".red())
|
//print blank line
|
||||||
);
|
println!("");
|
||||||
|
println!("chapter:\t{}", format_args!("{}", "-c --chapter".red()));
|
||||||
|
println!("{}", "after this^^^ argument you can either enter a chapter number".green());
|
||||||
|
println!("{}", "for exaple kami -c 200");
|
||||||
|
//print blank line
|
||||||
|
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