From ba3273c9adffee3d8538aecee18b39374bf6e195 Mon Sep 17 00:00:00 2001 From: Soispha Date: Sat, 20 Jan 2024 15:52:39 +0100 Subject: feat(sys/nixpkgs/yt/{yt,ytc}): Persist old selection file --- sys/nixpkgs/pkgs/yt/src/lib.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'sys/nixpkgs/pkgs/yt/src/lib.rs') 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, } + +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::>() + .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::() - .expect("Should be a number") - * 60) - + buf[1] - .parse::() - .expect("Should be a number"), + time: (buf[0].parse::().expect("Should be a number") * 60) + + buf[1].parse::().expect("Should be a number"), } } } -- cgit 1.4.1