diff options
author | Soispha <soispha@vhack.eu> | 2024-01-20 15:52:39 +0100 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2024-01-20 15:57:56 +0100 |
commit | ba3273c9adffee3d8538aecee18b39374bf6e195 (patch) | |
tree | eb292946e997102f0340f85a26f65f7f0f839f67 /sys/nixpkgs/pkgs/yt/src/lib.rs | |
parent | fix(sys/nixpkgs/yt/{yt,ytc}): Ignore sponsor block API access errors (diff) | |
download | nixos-config-ba3273c9adffee3d8538aecee18b39374bf6e195.zip |
feat(sys/nixpkgs/yt/{yt,ytc}): Persist old selection file
Diffstat (limited to '')
-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"), } } } |