aboutsummaryrefslogtreecommitdiffstats
path: root/src/structs.rs
diff options
context:
space:
mode:
authornjaremko2017-07-17 00:28:18 -0400
committernjaremko2017-07-17 00:28:18 -0400
commit3483b857cf687fe3d1568b82ca7bb8ffec938a7c (patch)
tree76fa8948da2b919c79e66d23617c3076ccb90fd2 /src/structs.rs
downloadpodcast-3483b857cf687fe3d1568b82ca7bb8ffec938a7c.tar.bz2
First commit
Diffstat (limited to 'src/structs.rs')
-rw-r--r--src/structs.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/structs.rs b/src/structs.rs
new file mode 100644
index 0000000..626072b
--- /dev/null
+++ b/src/structs.rs
@@ -0,0 +1,54 @@
+use std::fs::File;
+use std::io::BufReader;
+use rss::{Channel, Item};
+
+pub struct Podcast(Channel);
+
+pub struct Episode(Item);
+
+impl From<Channel> for Podcast {
+ fn from(channel: Channel) -> Podcast {
+ Podcast(channel)
+ }
+}
+
+impl From<Item> for Episode {
+ fn from(item: Item) -> Episode {
+ Episode(item)
+ }
+}
+
+impl Podcast {
+ pub fn episodes(&self) -> Vec<Episode> {
+ let mut result = Vec::new();
+
+ let items = self.0.items().to_vec();
+ for item in items {
+ result.push(Episode::from(item));
+ }
+ result
+ }
+
+
+ pub fn list_titles(&self) -> Vec<&str> {
+ let mut result = Vec::new();
+
+ let items = self.0.items();
+ for item in items {
+ match item.title() {
+ Some(val) => result.push(val),
+ None => (),
+ }
+ }
+ result
+ }
+}
+
+impl Episode {
+ pub fn download_url(&self) -> Option<&str> {
+ match self.0.enclosure() {
+ Some(val) => Some(val.url()),
+ None => None,
+ }
+ }
+}