9 Commits
img ... main

Author SHA1 Message Date
mrfluffy-dev
b2b4243dd2 yugen.to moved to yugenanime.ru 2023-03-09 09:26:47 +00:00
mrfluffy
9f0df00b19 Merge pull request #19 from newbee1905/main
Add option to use glow to read light novel
2023-02-02 07:26:50 -08:00
newbee1905
03166deb7e chore: fix helpers 2023-02-02 22:24:54 +07:00
newbee1905
2dea2c86ec chore: add reader args to help 2023-02-01 22:49:11 +07:00
newbee1905
330eb6239a feat: add option to use glow instead of bat 2023-02-01 22:42:51 +07:00
newbee1905
652548057b feat: switch from if else to match case for handling args 2023-02-01 22:31:43 +07:00
Zastian Pretorius
f435f290ac removed a debug print 2023-01-17 15:42:43 +00:00
mrfluffy
97fe7e30a7 Merge pull request #18 from mrfluffy-dev/img
added better anime history
2023-01-17 07:09:56 -08:00
mrfluffy
2c3d883f1f Merge pull request #17 from mrfluffy-dev/img
added full image support
2023-01-16 14:19:48 -08:00
5 changed files with 111 additions and 52 deletions

View File

@@ -22,7 +22,7 @@ pub fn get_anime_html(url: &str) -> String {
pub fn get_post(id: &str) -> String {
let resp = Request::builder()
.method("POST")
.uri("https://yugen.to/api/embed/")
.uri("https://yugenanime.ro/api/embed/")
.header("x-requested-with", "XMLHttpRequest")
.body(id)
.unwrap()
@@ -35,7 +35,7 @@ pub fn get_post(id: &str) -> String {
pub fn get_animes(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
let query = query.replace(" ", "+");
let html = get_anime_html(&format!("https://yugen.to/search/?q={}", query));
let html = get_anime_html(&format!("https://yugenanime.ro/discover/?q={}", query));
let re = Regex::new(r#"href="(/anime[^"]*)""#).unwrap();
let mut animes_links = Vec::new();
for cap in re.captures_iter(&html) {
@@ -55,7 +55,7 @@ pub fn get_animes(query: String) -> (Vec<String>, Vec<String>, Vec<String>) {
}
pub fn get_anime_info(url: &str) -> (i32, u16) {
let url = format!("https://yugen.to{}watch", url);
let url = format!("https://yugenanime.ro{}watch", url);
let html = get_anime_html(&url);
//print html and exit
let re = Regex::new(r#""mal_id":(\d*)"#).unwrap();
@@ -69,7 +69,7 @@ pub fn get_anime_info(url: &str) -> (i32, u16) {
pub fn get_anime_link(url: &str, episode: u64) -> String {
let url = &format!(
"https://yugen.to/watch{}{}/",
"https://yugenanime.ro/watch{}{}/",
url.replace("/anime", ""),
episode
);

View File

@@ -264,7 +264,6 @@ pub fn get_an_history() -> (Vec<String>, Vec<String>, Vec<String>) {
titles.push(key.to_string());
links.push(value["link"].as_str().unwrap().to_string());
images.push(value["image"].as_str().unwrap().to_string());
println!("{}", value["updated"].as_u64().unwrap());
last_updated.push(value["updated"].as_u64().unwrap());
}
let mut indices: Vec<usize> = (0..last_updated.len()).collect();

View File

@@ -1,4 +1,4 @@
use crate::ln::open_text::*;
use crate::ln::open_text::{open_bat, open_glow};
use crate::ln::scraper::*;
use crate::ln::tracker::*;
use crossterm::{
@@ -113,7 +113,7 @@ impl<'a> App {
}
}
pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
pub fn ln_ui(chapter: u32, reader: String) -> Result<(), Box<dyn Error>> {
// setup terminal
let _ = get_ln_json();
enable_raw_mode()?;
@@ -130,7 +130,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
app.current_page_number = (chapter / 48.0).ceil() as u32;
}
let res = run_app(&mut terminal, app);
let res = run_app(&mut terminal, app, &*reader);
// restore terminal
disable_raw_mode()?;
@@ -148,7 +148,7 @@ pub fn ln_ui(chapter: u32) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App, reader: &str) -> io::Result<()> {
let mut chapter_select = false;
loop {
@@ -244,7 +244,11 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
file.sync_all().expect("Unable to sync file");
};
terminal.clear()?;
let _ = open_bat();
let _ = match reader {
"bat" => open_bat(),
"glow" => open_glow(),
&_ => todo!(),
};
write_ln_progress(
&app.title,
&app.current_page_number,

View File

@@ -11,8 +11,7 @@ pub fn open_bat() -> Result<ExitStatus> {
home.drain(0..6);
home.drain(home.len() - 2..home.len());
path = format!("{}/AppData/Roaming/log_e", home).to_string();
}
else{
} else {
path = "/tmp/log_e".to_string();
}
@@ -37,3 +36,36 @@ pub fn open_bat() -> Result<ExitStatus> {
.spawn()?
.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()
}

View File

@@ -18,48 +18,57 @@ fn main() {
//let search = option string
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() {
if arg == "--help" || arg == "-h" {
help = true;
}
if arg == "--anime" || arg == "-a" {
anime = true;
}
if arg == "--provider" || arg == "-r" {
match &*arg {
"--help" | "-h" => help = true,
"--anime" | "-a" => anime = true,
"--provider" | "-r" => {
if let Some(arg) = std::env::args().nth(count + 1) {
//get the next argument and see if it is = to gogo of vrv
if arg == "vrv" {
provider = "vrv".to_string();
match arg.as_str() {
"vrv" | "gogo" => {
provider = arg;
count += 1;
} else if arg == "gogo" {
provider = "gogo".to_string();
count += 1;
} else {
provider = "gogo".to_string();
}
&_ => provider = "gogo".to_string(),
}
} else {
provider = "vrv".to_string();
}
}
if arg == "--cast" || arg == "-C" {
"--reader" | "-R" => {
if let Some(arg) = std::env::args().nth(count + 1) {
//get the next argument and see if it is = to gogo of vrv
match arg.as_str() {
"bat" | "glow" => {
reader = arg;
count += 1;
}
&_ => reader = "bat".to_string(),
}
} else {
provider = "glow".to_string();
}
}
"--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())
}
}
if arg == "--ln" || arg == "-l" {
ln = true;
}
if arg == "--chapter" || arg == "-c" {
"--ln" | "-l" => ln = true,
"--chapter" | "-c" => {
if let Some(arg) = std::env::args().nth(count + 1) {
chapter = arg.parse::<u32>().unwrap();
} else {
chapter = 0;
}
}
&_ => {}
}
count += 1;
}
@@ -84,7 +93,7 @@ fn main() {
}
if ln == true {
//ln_read(&search, chapter);
_ = ln_ui(chapter);
_ = ln_ui(chapter, reader);
} else if anime == true {
//anime_stream(search, episode, resume);
@@ -130,6 +139,21 @@ fn print_help() {
);
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()));
//kill the program
std::process::exit(0);