diff options
| author | Jokler <jokler@protonmail.com> | 2020-02-02 19:50:33 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-02-22 23:20:10 +0100 |
| commit | 2831c2b60cb61a14c7efee4ab5c0389eb3ad5469 (patch) | |
| tree | 835f1abad6e234f6d74d4be999f690709954be89 /src/youtube_dl.rs | |
| parent | ca4c0158f417b87f04313053a3f656f2de4e803b (diff) | |
| download | pokebot-2831c2b60cb61a14c7efee4ab5c0389eb3ad5469.tar.gz pokebot-2831c2b60cb61a14c7efee4ab5c0389eb3ad5469.zip | |
Add a very basic template using available info
Diffstat (limited to 'src/youtube_dl.rs')
| -rw-r--r-- | src/youtube_dl.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/youtube_dl.rs b/src/youtube_dl.rs index b62d4b3..99e50e7 100644 --- a/src/youtube_dl.rs +++ b/src/youtube_dl.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use futures::compat::Future01CompatExt; use std::process::{Command, Stdio}; use tokio_process::CommandExt; @@ -9,7 +11,33 @@ use log::debug; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct AudioMetadata { pub url: String, + pub webpage_url: String, pub title: String, + pub thumbnail: Option<String>, + #[serde(default, deserialize_with = "duration_deserialize")] + #[serde(serialize_with = "duration_serialize")] + pub duration: Option<Duration>, + #[serde(skip)] + pub added_by: String, +} + +fn duration_serialize<S>(d: &Option<Duration>, s: S) -> Result<S::Ok, S::Error> +where + S: serde::Serializer, +{ + match d { + Some(d) => s.serialize_some(&d.as_secs_f64()), + None => s.serialize_none(), + } +} + +fn duration_deserialize<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error> +where + D: serde::Deserializer<'de>, +{ + let dur: Option<f64> = Deserialize::deserialize(deserializer)?; + + Ok(dur.map(|v| Duration::from_secs_f64(v))) } pub async fn get_audio_download_url(uri: String) -> Result<AudioMetadata, String> { |
