Don't show duration if <= 0

This commit is contained in:
blank X 2021-02-03 14:27:40 +07:00
parent efd375e758
commit 787b22a1c1
4 changed files with 28 additions and 27 deletions

2
Cargo.lock generated
View File

@ -202,7 +202,7 @@ dependencies = [
[[package]]
name = "hanimers"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"clap",
"quick-xml",

View File

@ -1,6 +1,6 @@
[package]
name = "hanimers"
version = "0.1.0"
version = "0.1.1"
authors = ["blank X <theblankx@protonmail.com>"]
edition = "2018"

View File

@ -8,7 +8,7 @@ fn main() {
let matches = App::new("hanimers")
.about("hanime.tv downloader in rust")
// let's hope i remember to bump the version xd
.version("0.1.0")
.version("0.1.1")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("search")

View File

@ -66,6 +66,23 @@ pub struct HentaiVideo {
impl fmt::Display for HentaiInfo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let video = &self.state.data.video.hentai_video;
let mut text = format!("ID: {}\nSlug: {}\nName: {}\nViews: {}\nLikes: {}\nDislikes: {}\nCensored: {}\nHardsubbed: {}\n",
video.id,
&video.slug,
&video.name,
video.views,
video.likes,
video.dislikes,
match video.is_censored {
true => "Yes",
false => "No"
},
match video.is_hard_subtitled {
true => "Yes",
false => "No"
}
);
if video.duration_in_ms > 0 {
let mut seconds = video.duration_in_ms / 1000;
let mut minutes = seconds / 60;
if minutes > 0 {
@ -84,25 +101,9 @@ impl fmt::Display for HentaiInfo {
duration.push_str(&format!("{}:", minutes));
}
duration.push_str(&seconds.to_string());
formatter.write_str(&format!("ID: {}\nSlug: {}\nName: {}\nViews: {}\nLikes: {}\nDislikes: {}\nCensored: {}\nHardsubbed: {}\nDuration: {}\nTags: {}\nDescription: {}",
video.id,
&video.slug,
&video.name,
video.views,
video.likes,
video.dislikes,
match video.is_censored {
true => "Yes",
false => "No"
},
match video.is_hard_subtitled {
true => "Yes",
false => "No"
},
duration,
video.hentai_tags.iter().map(|i| i.text.as_str()).collect::<Vec<_>>().join(", "),
&video.description
))
text.push_str(&format!("Duration: {}\n", &duration));
}
formatter.write_str(&format!("{}Tags: {}\nDescription: {}", &text, video.hentai_tags.iter().map(|i| i.text.as_str()).collect::<Vec<_>>().join(", "), &video.description))
}
}