#![allow(dead_code)] // See https://support.google.com/podcast-publishers/answer/9889544 // for some reasonably guidelines for how a podcast RSS feed should look. use std::fmt; use std::borrow::Cow; #[derive(Debug, serde::Deserialize)] pub struct Feed<'a> { pub(crate) rss: Rss<'a>, } #[derive(Debug, serde::Deserialize)] pub struct Rss<'a> { pub(crate) channel: Channel<'a>, } #[derive(Debug, serde::Deserialize)] pub struct Channel<'a> { #[serde(rename = "item", default)] pub(crate) items: Vec>, pub(crate) link: Option>, pub(crate) title: Cow<'a, str>, pub(crate) description: Option>, #[serde(rename = "{http://www.itunes.com/dtds/podcast-1.0.dtd}itunes:author")] pub(crate) author: Option>, #[serde(rename = "{http://www.itunes.com/dtds/podcast-1.0.dtd}itunes:summary")] pub(crate) summary: Option>, #[serde(rename = "{http://www.itunes.com/dtds/podcast-1.0.dtd}itunes:image")] pub(crate) itunes_image: Option>, pub(crate) image: Option>, } #[derive(Debug, serde::Deserialize)] pub struct Image<'a> { pub(crate) link: Option>, pub(crate) title: Cow<'a, str>, pub(crate) url: Cow<'a, str>, } #[derive(Debug, serde::Deserialize)] pub struct ItunesImage<'a> { #[serde(rename = "$attr:href")] pub(crate) href: Cow<'a, str>, } fn deserialize_publish_date<'de, D: serde::de::Deserializer<'de>> ( deserializer: D ) -> Result { struct Visitor; impl<'de> serde::de::Visitor<'de> for Visitor { type Value = chrono::NaiveDateTime; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str("a string containing json data") } fn visit_str(self, input: &str) -> Result { chrono::NaiveDateTime::parse_from_str( input, "%a, %d %b %Y %H:%M:%S %Z" ).map_err(E::custom) } } deserializer.deserialize_any(Visitor) } #[derive(Debug, serde::Deserialize)] pub struct Item<'a> { pub(crate) title: Cow<'a, str>, pub(crate) enclosure: Option>, pub(crate) description: Option>, #[serde(rename = "{http://www.itunes.com/dtds/podcast-1.0.dtd}itunes:summary")] pub(crate) summary: Option>, #[serde(rename = "pubDate", deserialize_with = "deserialize_publish_date")] pub(crate) published: chrono::NaiveDateTime, pub(crate) guid: Option>, } #[derive(Debug, serde::Deserialize)] pub struct Enclosure<'a> { #[serde(rename = "$attr:url")] pub(crate) url: Cow<'a, str>, #[serde(rename = "$attr:type")] pub(crate) mime_type: Option>, //#[serde(rename = "$attr:length")] //pub(crate) length: Option, }