blob: 626072b09cca6e69343dc618d1f43e1d16bb3ed5 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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, 
        }
    }
}
 |