Properly show hentai ID
This commit is contained in:
		
							parent
							
								
									e03d746ce6
								
							
						
					
					
						commit
						56898120d9
					
				| 
						 | 
				
			
			@ -206,7 +206,7 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
 | 
			
		|||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "hentaihavenrs"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
version = "0.1.1"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "clap",
 | 
			
		||||
 "quick-xml",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
[package]
 | 
			
		||||
name = "hentaihavenrs"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
version = "0.1.1"
 | 
			
		||||
authors = ["blank X <theblankx@protonmail.com>"]
 | 
			
		||||
edition = "2018"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								src/utils.rs
								
								
								
								
							
							
						
						
									
										21
									
								
								src/utils.rs
								
								
								
								
							| 
						 | 
				
			
			@ -19,7 +19,7 @@ pub async fn search(client: reqwest::Client, query: &str) -> Result<Vec<structs:
 | 
			
		|||
pub async fn get_hentai(client: reqwest::Client, id: &str) -> Result<Option<structs::HentaiInfo>, 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<Option<stru
 | 
			
		|||
    if resp.status() != 200 {
 | 
			
		||||
        return Ok(None);
 | 
			
		||||
    }
 | 
			
		||||
    let mut id = String::new();
 | 
			
		||||
    let slug = resp.url().path().trim_end_matches('/').rsplitn(2, '/').nth(0).unwrap().to_string();
 | 
			
		||||
    let text = resp.text().await?.replace(" ", " ");
 | 
			
		||||
    let mut reader = Reader::from_str(&text);
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +110,20 @@ pub async fn get_hentai(client: reqwest::Client, id: &str) -> Result<Option<stru
 | 
			
		|||
                                Err(_) => ()
 | 
			
		||||
                            };
 | 
			
		||||
                        }
 | 
			
		||||
                    } 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<Option<stru
 | 
			
		|||
        };
 | 
			
		||||
        buf.clear();
 | 
			
		||||
    }
 | 
			
		||||
    if id.is_empty() {
 | 
			
		||||
        return Ok(None);
 | 
			
		||||
    }
 | 
			
		||||
    episode_urls.reverse();
 | 
			
		||||
    summary = summary.trim().to_string();
 | 
			
		||||
    Ok(Some(structs::HentaiInfo {
 | 
			
		||||
        id: id,
 | 
			
		||||
        slug: slug,
 | 
			
		||||
        title: title,
 | 
			
		||||
        views: rank,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue