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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
extern crate serde_derive;

use chrono::NaiveDate;

use self::serde_derive::{Deserialize, Serialize};
use std::str::FromStr;

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct EpisodeInfo {
    imdb: Option<String>,
    tvrage: Option<String>,
    tvdb: Option<String>,
    themoviedb: Option<String>,
    airdate: Option<String>,
    epnum: Option<String>,
    seasonnum: Option<String>,
    title: Option<String>,
}

impl EpisodeInfo {
    /// Return the TMDB id.
    pub fn imdb_id(&self) -> &Option<String> {
        &self.imdb
    }

    /// Return the TVRage id.
    pub fn tvrage_id(&self) -> &Option<String> {
        &self.tvrage
    }

    /// Return the TVDB id.
    pub fn tvdb_id(&self) -> &Option<String> {
        &self.tvdb
    }

    /// Return the TMDB id.
    pub fn tmdb_id(&self) -> &Option<String> {
        &self.themoviedb
    }

    /// Return the airing date.
    pub fn air_date(&self) -> Option<NaiveDate> {
        if self.airdate.is_some() {
            let date = self.airdate.as_ref().unwrap();
            if date == "0000-00-00" {
                return None;
            }
            return Some(NaiveDate::from_str(date.as_str()).unwrap());
        }
        return None;
    }

    /// Return the episode number.
    pub fn episode_number(&self) -> &Option<String> {
        &self.epnum
    }

    /// Return the season number.
    pub fn season_number(&self) -> &Option<String> {
        &self.seasonnum
    }

    /// Return the title.
    pub fn title(&self) -> &Option<String> {
        &self.title
    }
}