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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
//! Standard Media Objects
mod de;
mod ser;
use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
use time::{Date, OffsetDateTime};
use trakt_core::EmojiString;
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)]
#[serde(untagged)]
pub enum Id {
Trakt(u64),
Slug(SmolStr),
Tvdb(u64),
Imdb(SmolStr),
Tmdb(u64),
}
impl From<Id> for Ids {
fn from(value: Id) -> Self {
let mut ret = Self::default();
match value {
Id::Trakt(trakt) => ret.trakt = Some(trakt),
Id::Slug(slug) => ret.slug = Some(slug),
Id::Tvdb(tvdb) => ret.tvdb = Some(tvdb),
Id::Imdb(imdb) => ret.imdb = Some(imdb),
Id::Tmdb(tmdb) => ret.tmdb = Some(tmdb),
}
ret
}
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
pub struct Ids {
#[serde(skip_serializing_if = "Option::is_none")]
pub trakt: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub slug: Option<SmolStr>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tvdb: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub imdb: Option<SmolStr>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tmdb: Option<u64>,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Movie {
pub title: String,
pub year: u16,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Show {
pub title: String,
pub year: u16,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Season {
pub number: u16,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Episode {
pub season: u16,
pub number: u16,
pub title: String,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct Person {
pub name: String,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct User {
pub username: String,
pub private: bool,
pub name: String,
pub vip: bool,
pub vip_ep: bool,
pub ids: Ids,
}
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Default, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Period {
Daily,
#[default]
Weekly,
Monthly,
Yearly,
All,
}
/// 2-letter country code
pub type Country = TwoLetter;
/// 2-letter language code
pub type Language = TwoLetter;
/// 2-letter Codes
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct TwoLetter([u8; 2]);
impl TwoLetter {
#[must_use]
pub fn new(code: &str) -> Self {
let mut bytes = [0; 2];
bytes.copy_from_slice(code.as_bytes());
unsafe { Self::from_bytes_unchecked(bytes) }
}
/// Create a `TwoLetter` from bytes without checking if the bytes are valid UTF-8
///
/// # Arguments
///
/// * `bytes`: Bytes to convert to a `TwoLetter`
///
/// # Safety
///
/// The bytes must be valid UTF-8.
#[must_use]
pub const unsafe fn from_bytes_unchecked(bytes: [u8; 2]) -> Self {
Self(bytes)
}
#[must_use]
pub const fn as_str(&self) -> &str {
unsafe { std::str::from_utf8_unchecked(&self.0) }
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Sort {
#[default]
Newest,
Oldest,
Likes,
Replies,
Highest,
Lowest,
Plays,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct Comment {
pub id: u32,
pub parent_id: Option<u32>,
#[serde(with = "time::serde::iso8601")]
pub created_at: OffsetDateTime,
#[serde(with = "time::serde::iso8601")]
pub updated_at: OffsetDateTime,
pub comment: EmojiString,
pub spoiler: bool,
pub review: bool,
pub replies: u32,
pub likes: u32,
pub user_stats: UserStats,
pub user: User,
pub sharing: Option<Sharing>,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct UserStats {
pub rating: u8,
pub play_count: u32,
pub completed_count: u32,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct List {
pub name: EmojiString,
pub description: EmojiString,
pub privacy: ListPrivacy,
pub share_link: String,
pub r#type: ListType,
pub display_numbers: bool,
pub allow_comments: bool,
pub sort_by: ListSortBy,
pub sort_how: ListSortHow,
#[serde(with = "time::serde::iso8601")]
pub created_at: OffsetDateTime,
#[serde(with = "time::serde::iso8601")]
pub updated_at: OffsetDateTime,
pub item_count: u64,
pub comment_count: u64,
pub likes: u64,
pub ids: Ids,
pub user: User,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ListType {
Personal,
Official,
Watchlist,
Favorites,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ListSortBy {
Rank,
Added,
Title,
Released,
Runtime,
Popularity,
Percentage,
Votes,
MyRating,
Random,
Watched,
Collected,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ListSortHow {
Asc,
Desc,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ListPrivacy {
#[default]
Private,
Link,
Friends,
Public,
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Ratings {
pub rating: f32,
pub votes: u32,
pub distribution: Distribution,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Distribution(pub [u32; 10]);
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct Studio {
pub name: String,
pub country: Country,
pub ids: Ids,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct EpisodeAirEvent {
#[serde(with = "time::serde::iso8601")]
pub first_aired: OffsetDateTime,
pub episode: Episode,
pub show: Show,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize)]
pub struct MovieReleaseEvent {
#[serde(with = "crate::iso8601_date")]
pub release_date: Date,
pub movie: Movie,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
pub struct Sharing {
pub twitter: bool,
pub mastodon: bool,
pub tumblr: bool,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum CommentType {
#[default]
All,
Reviews,
Shouts,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum CommentItemType {
#[default]
All,
Movies,
Shows,
Seasons,
Episodes,
Lists,
}
#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(tag = "type")]
pub enum CommentWithItem {
Movie {
movie: Box<Movie>,
comment: Comment,
},
Show {
show: Box<Show>,
comment: Comment,
},
Season {
season: Box<Season>,
comment: Comment,
},
Episode {
episode: Box<Episode>,
comment: Comment,
},
List {
list: Box<List>,
comment: Comment,
},
}
|