const NET: &str = "nhentai.net";
const XXX: &str = "nhentai.xxx";
fn get_type(file_type: &str) -> &str {
if file_type == "j" {
"jpg"
} else if file_type == "p" {
"png"
} else {
"gif"
}
}
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum Website {
NET,
XXX,
}
pub struct Make {
pub mode: Website,
}
impl Make {
pub fn new(mode: Website) -> Make {
Make { mode }
}
pub fn doujin_url(&self, id: &String) -> String {
match self.mode {
Website::NET => format!("https://{}/g/{}", NET, id),
Website::XXX => format!("https://{}/g/{}", XXX, id),
}
}
pub fn cover(&self, media_id: &str, file_type: &str) -> String {
match self.mode {
Website::NET => format!(
"https://t.{}/galleries/{}/cover.{}",
NET,
media_id,
get_type(file_type)
),
Website::XXX => format!(
"https://cdn.{}/g/{}/cover.{}",
XXX,
media_id,
get_type(file_type)
),
}
}
pub fn cover_thumbnail(&self, media_id: &str, file_type: &str) -> String {
match self.mode {
Website::NET => format!(
"https://t.{}/galleries/{}/thumb.{}",
NET,
media_id,
get_type(file_type)
),
Website::XXX => format!(
"https://cdn.{}/g/{}/thumb.{}",
XXX,
media_id,
get_type(file_type)
),
}
}
pub fn page(&self, media_id: &str, number: u32, file_type: &str) -> String {
match self.mode {
Website::NET => format!(
"https://i.{}/galleries/{}/{}.{}",
NET,
media_id,
number.to_string(),
get_type(file_type)
),
Website::XXX => format!(
"https://cdn.{}/g/{}/{}.{}",
XXX,
media_id,
number.to_string(),
get_type(file_type)
),
}
}
#[allow(dead_code)]
pub fn page_thumbnail(&self, media_id: &str, number: u32, file_type: &str) -> String {
match self.mode {
Website::NET => format!(
"https://t.{}/galleries/{}/{}t.{}",
NET,
media_id,
number.to_string(),
get_type(file_type)
),
Website::XXX => format!(
"https://cdn.{}/g/{}/{}t.{}",
XXX,
media_id,
number.to_string(),
get_type(file_type)
),
}
}
}
pub fn doujin(id: u32) -> String {
format!("https://nhentai.net/api/gallery/{}", id.to_string())
}