Don't show duration if <= 0

master
blank X 2 years ago
parent efd375e758
commit 787b22a1c1

2
Cargo.lock generated

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

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

@ -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")

@ -66,25 +66,7 @@ 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 seconds = video.duration_in_ms / 1000;
let mut minutes = seconds / 60;
if minutes > 0 {
seconds -= minutes * 60;
}
let hours = minutes / 60;
if hours > 0 {
minutes -= hours * 60;
seconds -= hours * 60 * 60;
}
let mut duration = String::new();
if hours > 0 {
duration.push_str(&format!("{}:", hours));
}
if minutes > 0 {
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: {}",
let mut text = format!("ID: {}\nSlug: {}\nName: {}\nViews: {}\nLikes: {}\nDislikes: {}\nCensored: {}\nHardsubbed: {}\n",
video.id,
&video.slug,
&video.name,
@ -98,11 +80,30 @@ impl fmt::Display for HentaiInfo {
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
))
}
);
if video.duration_in_ms > 0 {
let mut seconds = video.duration_in_ms / 1000;
let mut minutes = seconds / 60;
if minutes > 0 {
seconds -= minutes * 60;
}
let hours = minutes / 60;
if hours > 0 {
minutes -= hours * 60;
seconds -= hours * 60 * 60;
}
let mut duration = String::new();
if hours > 0 {
duration.push_str(&format!("{}:", hours));
}
if minutes > 0 {
duration.push_str(&format!("{}:", minutes));
}
duration.push_str(&seconds.to_string());
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))
}
}

Loading…
Cancel
Save