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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
pub struct SeriesId {
    pub seriesid: u32,
}

impl From<u32> for SeriesId {
    fn from(x: u32) -> Self {
        SeriesId { seriesid: x }
    }
}

#[derive(Debug, Clone)]
pub struct EpisodeId {
    /// Series ID
    pub seriesid: u32,
    /// Language code
    pub language: String,
}

impl EpisodeId {
    /// Constructor
    pub fn new(seriesid: u32, lang: &str) -> EpisodeId {
        EpisodeId {
            seriesid: seriesid,
            language: lang.to_owned(),
        }
    }
}

impl From<u32> for EpisodeId {
    fn from(x: u32) -> Self {
        EpisodeId {
            seriesid: x,
            language: "en".to_owned(),
        }
    }
}

/// https://api.thetvdb.com/swagger#/Authentication
#[derive(Deserialize, Debug)]
struct LoginResponse {
    token: String,
}

/// List of `SeriesSearchData`, returned from a search
#[derive(Deserialize, Debug)]
pub struct SeriesSearchResult {
    pub data: Option<Vec<SeriesSearchData>>,
    pub error: Option<String>,
}

/// Info for a single series, as returned from search query
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SeriesSearchData {
    pub aliases: Option<Vec<String>>,
    pub banner: Option<String>,
    pub first_aired: Option<String>,
    pub id: Option<u32>,
    pub network: Option<String>,
    pub overview: Option<String>,
    pub series_name: String,
    pub status: Option<String>,
}

impl From<SeriesSearchData> for EpisodeId {
    fn from(x: SeriesSearchData) -> Self {
        EpisodeId {
            seriesid: x.id.unwrap() as u32,
            language: "en".into(),
        }
    }
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct JSONErrors {
    pub invalid_filters: Option<Vec<String>>,
    pub invalid_language: Option<Vec<String>>,
    pub invalid_query_params: Option<Vec<String>>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct EpisodeRecordResult {
    pub data: Option<Episode>,
    pub errors: Option<JSONErrors>,
}

/// Complete info for an episode
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Episode {
    pub absolute_number: Option<u32>,
    pub aired_episode_number: Option<u32>,
    pub aired_season: Option<u32>,
    pub airs_after_season: Option<u32>,
    pub airs_before_episode: Option<u32>,
    pub airs_before_season: Option<u32>,
    pub director: Option<String>,
    pub directors: Option<Vec<String>>,
    pub dvd_chapter: Option<f32>,
    pub dvd_discid: Option<String>,
    pub dvd_episode_number: Option<f32>,
    pub dvd_season: Option<u32>,
    pub episode_name: String, // FIXME: Should be optional
    pub filename: Option<String>,
    pub first_aired: Option<String>,
    pub guest_stars: Option<Vec<String>>,
    pub id: Option<u32>,
    pub imdb_id: Option<String>,
    pub last_updated: Option<u32>,
    pub last_updated_by: Option<u32>, // FIXME: Should be String
    pub overview: Option<String>,
    pub production_code: Option<String>,
    pub series_id: Option<u32>,
    pub show_url: Option<String>,
    pub site_rating: Option<f32>,
    pub site_rating_count: Option<u32>,
    pub thumb_added: Option<String>,
    pub thumb_author: Option<u32>, // FIXME: Should be String
    pub thumb_height: Option<String>,
    pub thumb_width: Option<String>,
    pub writers: Option<Vec<String>>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct SeriesEpisodesResult {
    pub data: Option<Vec<BasicEpisode>>,
    pub errors: Option<JSONErrors>,
    pub links: Option<Links>,
}

/// Episode with most common attributes available
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BasicEpisode {
    pub absolute_number: Option<u32>,
    pub aired_episode_number: Option<u32>,
    pub aired_season: Option<u32>,
    pub dvd_episode_number: Option<f32>,
    pub dvd_season: Option<u32>,
    pub episode_name: Option<String>,
    pub first_aired: Option<String>,
    pub id: Option<u32>,
    pub last_updated: Option<u32>,
    pub overview: Option<String>,
}

/// Pagination links
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Links {
    pub first: Option<u32>,
    pub last: Option<u32>,
    pub next: Option<u32>,
    pub previous: Option<u32>,
}