From 56898120d97e868de456c071637868eed3d46793 Mon Sep 17 00:00:00 2001 From: blank X Date: Sat, 13 Feb 2021 16:53:15 +0700 Subject: [PATCH] Properly show hentai ID --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/view.rs | 2 +- src/structs.rs | 4 +++- src/utils.rs | 21 ++++++++++++++++++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c8e0b5..643fdc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,7 +206,7 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "hentaihavenrs" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "quick-xml", diff --git a/Cargo.toml b/Cargo.toml index fcf134e..1a10409 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hentaihavenrs" -version = "0.1.0" +version = "0.1.1" authors = ["blank X "] edition = "2018" diff --git a/src/commands/view.rs b/src/commands/view.rs index 845b7b7..239cb6e 100644 --- a/src/commands/view.rs +++ b/src/commands/view.rs @@ -37,7 +37,7 @@ pub async fn view(arg_m: &ArgMatches<'_>) { if one_done { println!(""); } - println!("ID: {}\n{}", id, &hentai); + println!("{}", &hentai); }, None => { if one_done { diff --git a/src/structs.rs b/src/structs.rs index 07cbf73..1c18d96 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -23,6 +23,7 @@ impl fmt::Display for SearchResult { #[derive(Debug)] pub struct HentaiInfo { + pub id: String, pub slug: String, pub title: String, pub views: usize, @@ -34,7 +35,8 @@ pub struct HentaiInfo { impl fmt::Display for HentaiInfo { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(formatter, "Title: {}\nViews: {}\nCensored: {}\nGenres: {}\nEpisodes: {}\nSummary:\n{}", + write!(formatter, "ID: {}\nTitle: {}\nViews: {}\nCensored: {}\nGenres: {}\nEpisodes: {}\nSummary:\n{}", + &self.id, &self.title, self.views, match self.censored { diff --git a/src/utils.rs b/src/utils.rs index bcef1d2..a323399 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,7 +19,7 @@ pub async fn search(client: reqwest::Client, query: &str) -> Result Result, structs::Error> { let url = match id.contains(|c: char| !c.is_digit(10)) { true => format!("https://hentaihaven.xxx/watch/{}", &id), - false => format!("https://hentaihaven.xxx/?post_type=wp-manga&p={}", &id) + false => format!("https://hentaihaven.xxx/?p={}", &id) }; let resp = client.get(&url) .send() @@ -27,6 +27,7 @@ pub async fn get_hentai(client: reqwest::Client, id: &str) -> Result Result () }; } + } else if id.is_empty() { + let data_post = e.attributes() + .find(|i| { + match i.as_ref() { + Ok(i) => i.key == b"data-post", + Err(_) => false + } + }); + if let Some(data_post) = data_post { + match data_post.unwrap().unescape_and_decode_value(&reader) { + Ok(data_post) => id = data_post, + Err(_) => () + }; + } } } }, @@ -166,9 +181,13 @@ pub async fn get_hentai(client: reqwest::Client, id: &str) -> Result