Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Aug 20, 2021
1 parent 2ce612f commit d2ac3e6
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 80 deletions.
10 changes: 5 additions & 5 deletions catmanga/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Extension for Catmanga {
}

if data.is_none() {
error = Some(format!("manga not found"));
error = Some("manga not found".to_string());
}

ExtensionResult { data, error }
Expand All @@ -141,19 +141,19 @@ impl Extension for Catmanga {
title: format!(
"Chapter {} - {}",
chapter.number,
chapter.title.unwrap_or("".to_string()).clone()
chapter.title.unwrap_or_default().clone()
),
path: format!("{}/{}", path, chapter.number),
number: chapter.number,
scanlator: chapter.groups.get(0).unwrap_or(&"".to_string()).to_string(),
scanlator: chapter.groups.get(0).map(String::clone).unwrap_or_default(),
uploaded: dt.naive_local(),
});
}
data = Some(chapters)
}

if data.is_none() {
error = Some(format!("manga not found"));
error = Some("manga not found".to_string());
}

ExtensionResult { data, error }
Expand All @@ -170,7 +170,7 @@ impl Extension for Catmanga {
}

if data.is_none() {
error = Some(format!("manga not found"));
error = Some("manga not found".to_string());
}

ExtensionResult { data, error }
Expand Down
16 changes: 6 additions & 10 deletions mangadex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ register_extension!(Mangadex);

impl Default for Mangadex {
fn default() -> Self {
Mangadex {
Self {
url: URL.to_string(),
}
}
Expand Down Expand Up @@ -84,10 +84,9 @@ impl Mangadex {
genre,
status: attributes
.clone()
.and_then(|attr| attr.status.clone())
.and_then(|attr| attr.status)
.map(|s| s.to_string()),
description: attributes
.clone()
.and_then(|attr| attr.description.get("en").cloned())
.map(|description| Self::remove_bbcode(&description)),
path: format!("/manga/{}", id),
Expand All @@ -100,14 +99,11 @@ impl Mangadex {
pub fn map_result_to_chapter(result: Result) -> Option<Chapter> {
let mut scanlator = "".to_string();
for relationship in result.relationships {
match relationship {
data::Relationship::ScanlationGroup { attributes, .. } => {
if let Some(name) = attributes.map(|attr| attr.name) {
scanlator = name;
}
if let data::Relationship::ScanlationGroup { attributes, .. } = relationship {
if let Some(name) = attributes.map(|attr| attr.name) {
scanlator = name;
}
_ => {}
};
}
}

match result.data {
Expand Down
57 changes: 30 additions & 27 deletions mangalife/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ register_extension!(Mangalife);

impl Default for Mangalife {
fn default() -> Self {
Mangalife {
Self {
url: "https://manga4life.com".to_string(),
}
}
Expand All @@ -26,7 +26,7 @@ impl Default for Mangalife {
impl Mangalife {
fn find_filter_map_value(
filter_map: &Option<Filters>,
key: &String,
key: &str,
index: usize,
) -> Result<FilterValue, Box<dyn std::error::Error>> {
Ok(filter_map
Expand Down Expand Up @@ -256,11 +256,9 @@ impl Extension for Mangalife {
let selector = scraper::Selector::parse("div[class=\"top-5 Content\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();

for element in document.select(&selector) {
for text in element.text() {
desc = Some(text.to_string());
break;
}
desc = element.text().next().map(str::to_string);
}
desc
};
Expand All @@ -269,6 +267,7 @@ impl Extension for Mangalife {
let selector = scraper::Selector::parse("a[href^=\"/search/?author=\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();

for element in document.select(&selector) {
for text in element.text() {
author.push(text.to_string());
Expand All @@ -279,41 +278,45 @@ impl Extension for Mangalife {
let selector = scraper::Selector::parse("a[href^=\"/search/?genre=\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();

for element in document.select(&selector) {
for text in element.text() {
genre.push(String::from(text));
}
}

let status = {
let mut status = None;
let selector = scraper::Selector::parse("a[href^=\"/search/?status=\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();
for element in document.select(&selector) {
status = element.value().attr("href").map(|h| {

let status = document.select(&selector).next().and_then(|element| {
element.value().attr("href").map(|h| {
h.strip_prefix("/search/?status=")
.map(|s| s.to_string())
.unwrap_or(h.to_string())
});
break;
}
.unwrap_or_else(|| h.to_string())
})
});

status
};

let mut cover_url = "".to_string();
let selector = scraper::Selector::parse("img[class=\"img-fluid bottom-5\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();
for element in document.select(&selector) {
cover_url = element
.value()
.attr("src")
.map(|src| src.to_string())
.ok_or(format!("no src"))
.unwrap();
break;
}

let cover_url = document
.select(&selector)
.next()
.map(|element| {
element
.value()
.attr("src")
.map(str::to_string)
.ok_or_else(|| "no src".to_string())
.unwrap()
})
.unwrap_or_default();

ExtensionResult::ok(Manga {
source_id: ID,
Expand All @@ -322,7 +325,7 @@ impl Extension for Mangalife {
author,
genre,
status,
path: path.clone(),
path,
cover_url,
})
}
Expand Down Expand Up @@ -372,7 +375,7 @@ impl Extension for Mangalife {
"".to_string()
};

chapter.insert_str(chapter.len() - 1, ".");
chapter.insert(chapter.len() - 1, '.');
let number = chapter.parse::<f64>().unwrap();

chapters.push(Chapter {
Expand All @@ -385,7 +388,7 @@ impl Extension for Mangalife {
index,
),
uploaded: ch.date,
number: number + if index == "" { 0.0 } else { 10000.0 },
number: number + if index.is_empty() { 0.0 } else { 10000.0 },
scanlator: "".to_string(),
})
}
Expand Down Expand Up @@ -426,7 +429,7 @@ impl Extension for Mangalife {
};

let directory = {
if cur_chapter.directory == "" {
if cur_chapter.directory.is_empty() {
"".to_string()
} else {
format!("{}/", cur_chapter.directory)
Expand Down
2 changes: 1 addition & 1 deletion mangalife/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod date_format {
use chrono::NaiveDateTime;
use serde::{self, Deserialize, Deserializer};

const FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";
const FORMAT: &str = "%Y-%m-%d %H:%M:%S";

pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error>
where
Expand Down
52 changes: 25 additions & 27 deletions mangasee/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ register_extension!(Mangasee);

impl Default for Mangasee {
fn default() -> Self {
Mangasee {
Self {
url: "https://mangasee123.com".to_string(),
}
}
Expand Down Expand Up @@ -259,10 +259,7 @@ impl Extension for Mangasee {
.map_err(|e| format!("{:?}", e))
.unwrap();
for element in document.select(&selector) {
for text in element.text() {
desc = Some(text.to_string());
break;
}
desc = element.text().next().map(str::to_string);
}
desc
};
Expand All @@ -288,34 +285,35 @@ impl Extension for Mangasee {
}

let status = {
let mut status = None;
let selector = scraper::Selector::parse("a[href^=\"/search/?status=\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();
for element in document.select(&selector) {
status = element.value().attr("href").map(|h| {

document.select(&selector).next().and_then(|element| {
element.value().attr("href").map(|h| {
h.strip_prefix("/search/?status=")
.map(|s| s.to_string())
.unwrap_or(h.to_string())
});
break;
}
status
.unwrap_or_else(|| h.to_string())
})
})
};

let mut cover_url = "".to_string();
let selector = scraper::Selector::parse("img[class=\"img-fluid bottom-5\"]")
.map_err(|e| format!("{:?}", e))
.unwrap();
for element in document.select(&selector) {
cover_url = element
.value()
.attr("src")
.map(|src| src.to_string())
.ok_or(format!("no src"))
.unwrap();
break;
}

let cover_url = document
.select(&selector)
.next()
.map(|element| {
element
.value()
.attr("src")
.map(str::to_string)
.ok_or_else(|| "no src".to_string())
.unwrap()
})
.unwrap_or_default();

ExtensionResult::ok(Manga {
source_id: ID,
Expand All @@ -324,7 +322,7 @@ impl Extension for Mangasee {
author,
genre,
status,
path: path.clone(),
path,
cover_url,
})
}
Expand Down Expand Up @@ -374,7 +372,7 @@ impl Extension for Mangasee {
"".to_string()
};

chapter.insert_str(chapter.len() - 1, ".");
chapter.insert(chapter.len() - 1, '.');
let number = chapter.parse::<f64>().unwrap();

chapters.push(Chapter {
Expand All @@ -387,7 +385,7 @@ impl Extension for Mangasee {
index,
),
uploaded: ch.date,
number: number + if index == "" { 0.0 } else { 10000.0 },
number: number + if index.is_empty() { 0.0 } else { 10000.0 },
scanlator: "".to_string(),
})
}
Expand Down Expand Up @@ -428,7 +426,7 @@ impl Extension for Mangasee {
};

let directory = {
if cur_chapter.directory == "" {
if cur_chapter.directory.is_empty() {
"".to_string()
} else {
format!("{}/", cur_chapter.directory)
Expand Down
2 changes: 1 addition & 1 deletion mangasee/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod date_format {
use chrono::NaiveDateTime;
use serde::{self, Deserialize, Deserializer};

const FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";
const FORMAT: &str = "%Y-%m-%d %H:%M:%S";

pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDateTime, D::Error>
where
Expand Down
15 changes: 6 additions & 9 deletions nhentai/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ impl Extension for Nhentai {
.unwrap_or("popular");
let page = param.page.unwrap_or(1);

let url = if let Some(keyword) = param.keyword.and_then(|keyword| {
if keyword.is_empty() {
None
} else {
Some(keyword)
}
}) {
let url = if let Some(keyword) = param
.keyword
.and_then(|keyword| (!keyword.is_empty()).then(|| keyword))
{
let sort = if !sort_by.is_empty() {
format!("&sort={}", sort_by)
} else {
Expand Down Expand Up @@ -152,7 +149,7 @@ impl Extension for Nhentai {
let mut manga = Manga {
source_id: ID,
status: Some("ongoing".to_string()),
path: path.to_string(),
path,
description: Some("".to_string()),
..Default::default()
};
Expand Down Expand Up @@ -216,7 +213,7 @@ impl Extension for Nhentai {
let chapter = Chapter {
source_id: ID,
title: "Chapter 1".to_string(),
path: path.to_string(),
path,
number: 1_f64,
scanlator: group.unwrap_or_else(|| "".to_string()),
uploaded: uploaded.unwrap_or_else(|| NaiveDateTime::from_timestamp(0, 0)),
Expand Down

0 comments on commit d2ac3e6

Please sign in to comment.