diff options
Diffstat (limited to 'sys/nixpkgs/pkgs/yt/src/lib.rs')
-rw-r--r-- | sys/nixpkgs/pkgs/yt/src/lib.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/sys/nixpkgs/pkgs/yt/src/lib.rs b/sys/nixpkgs/pkgs/yt/src/lib.rs index a08b32db..2571b6b6 100644 --- a/sys/nixpkgs/pkgs/yt/src/lib.rs +++ b/sys/nixpkgs/pkgs/yt/src/lib.rs @@ -18,6 +18,27 @@ pub struct YtccListData { pub id: u32, pub playlists: Vec<YtccPlaylistData>, } + +impl std::fmt::Display for YtccListData { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!( + f, + r#"pick {} "{}" "{}" "{}" "{}" "{}"{}"#, + self.id, + self.title.replace('"', "'"), + self.publish_date, + self.playlists + .iter() + .map(|p| p.name.replace('"', "'")) + .collect::<Vec<String>>() + .join(", "), + Duration::from(self.duration.trim()), + self.url.replace('"', "'"), + "\n" + ) + } +} + #[derive(Deserialize)] pub struct YtccPlaylistData { pub name: String, @@ -80,13 +101,8 @@ impl From<&str> for Duration { fn from(v: &str) -> Self { let buf: Vec<_> = v.split(':').take(2).collect(); Self { - time: (buf[0] - .parse::<u32>() - .expect("Should be a number") - * 60) - + buf[1] - .parse::<u32>() - .expect("Should be a number"), + time: (buf[0].parse::<u32>().expect("Should be a number") * 60) + + buf[1].parse::<u32>().expect("Should be a number"), } } } |