Skip to main content

tmdb_rs/endpoints/
person.rs

1use serde::Deserialize;
2use time::Date;
3
4use crate::append::appendable;
5use crate::common::{Changes, ExternalIds, Image};
6use crate::{Backdrop, CountryCode, Language, Page, Poster, Profile};
7
8/// one person in a list or search response
9#[derive(Debug, Clone, Deserialize)]
10pub struct PersonShort {
11    pub id: u64,
12    pub name: String,
13    pub original_name: String,
14    #[serde(rename = "profile_path")]
15    pub profile: Option<Profile>,
16    pub known_for_department: Option<String>,
17    pub popularity: f64,
18    pub gender: Option<u32>,
19    pub adult: bool,
20}
21
22/// a movie acting credit in a person's filmography
23#[derive(Debug, Clone, Deserialize)]
24pub struct MovieCastCredit {
25    pub id: u64,
26    #[serde(rename = "title")]
27    pub name: String,
28    #[serde(rename = "original_title")]
29    pub original_name: String,
30    pub character: Option<String>,
31    #[serde(rename = "poster_path")]
32    pub poster: Option<Poster>,
33    #[serde(rename = "backdrop_path")]
34    pub backdrop: Option<Backdrop>,
35    #[serde(default, deserialize_with = "crate::common::opt_date")]
36    pub release_date: Option<Date>,
37    pub credit_id: String,
38    pub vote_average: f64,
39    pub vote_count: u32,
40    pub popularity: f64,
41    #[serde(default)]
42    pub genre_ids: Vec<u64>,
43    pub overview: String,
44    pub adult: bool,
45}
46
47/// a series acting credit in a person's filmography
48#[derive(Debug, Clone, Deserialize)]
49pub struct TvCastCredit {
50    pub id: u64,
51    pub name: String,
52    pub original_name: String,
53    pub character: Option<String>,
54    #[serde(rename = "poster_path")]
55    pub poster: Option<Poster>,
56    #[serde(rename = "backdrop_path")]
57    pub backdrop: Option<Backdrop>,
58    #[serde(
59        rename = "first_air_date",
60        default,
61        deserialize_with = "crate::common::opt_date"
62    )]
63    pub release_date: Option<Date>,
64    pub credit_id: String,
65    pub episode_count: Option<u32>,
66    pub vote_average: f64,
67    pub vote_count: u32,
68    pub popularity: f64,
69    #[serde(default)]
70    pub genre_ids: Vec<u64>,
71    pub overview: String,
72    #[serde(default)]
73    pub origin_country: Vec<String>,
74}
75
76/// one acting credit, discriminated by TMDB's `media_type`
77#[derive(Debug, Clone, Deserialize)]
78#[serde(tag = "media_type", rename_all = "snake_case")]
79pub enum CastCredit {
80    Movie(MovieCastCredit),
81    Tv(TvCastCredit),
82}
83
84/// a movie crew credit in a person's filmography
85#[derive(Debug, Clone, Deserialize)]
86pub struct MovieCrewCredit {
87    pub id: u64,
88    #[serde(rename = "title")]
89    pub name: String,
90    #[serde(rename = "original_title")]
91    pub original_name: String,
92    pub job: String,
93    pub department: String,
94    #[serde(rename = "poster_path")]
95    pub poster: Option<Poster>,
96    #[serde(rename = "backdrop_path")]
97    pub backdrop: Option<Backdrop>,
98    #[serde(default, deserialize_with = "crate::common::opt_date")]
99    pub release_date: Option<Date>,
100    pub credit_id: String,
101    pub vote_average: f64,
102    pub vote_count: u32,
103    pub popularity: f64,
104    #[serde(default)]
105    pub genre_ids: Vec<u64>,
106    pub overview: String,
107    pub adult: bool,
108}
109
110/// a series crew credit in a person's filmography
111#[derive(Debug, Clone, Deserialize)]
112pub struct TvCrewCredit {
113    pub id: u64,
114    pub name: String,
115    pub original_name: String,
116    pub job: String,
117    pub department: String,
118    #[serde(rename = "poster_path")]
119    pub poster: Option<Poster>,
120    #[serde(rename = "backdrop_path")]
121    pub backdrop: Option<Backdrop>,
122    #[serde(
123        rename = "first_air_date",
124        default,
125        deserialize_with = "crate::common::opt_date"
126    )]
127    pub release_date: Option<Date>,
128    pub credit_id: String,
129    pub episode_count: Option<u32>,
130    pub vote_average: f64,
131    pub vote_count: u32,
132    pub popularity: f64,
133    #[serde(default)]
134    pub genre_ids: Vec<u64>,
135    pub overview: String,
136    #[serde(default)]
137    pub origin_country: Vec<String>,
138}
139
140/// one crew credit, discriminated by TMDB's `media_type`
141#[derive(Debug, Clone, Deserialize)]
142#[serde(tag = "media_type", rename_all = "snake_case")]
143pub enum CrewCredit {
144    Movie(MovieCrewCredit),
145    Tv(TvCrewCredit),
146}
147
148/// a person's filmography; combined, movie-only and tv-only share the shape
149#[derive(Debug, Clone, Deserialize)]
150pub struct PersonCredits {
151    pub cast: Vec<CastCredit>,
152    pub crew: Vec<CrewCredit>,
153}
154
155#[derive(Debug, Clone, Deserialize)]
156pub struct PersonImages {
157    pub profiles: Vec<Image<Profile>>,
158}
159
160#[derive(Debug, Clone, Deserialize)]
161pub struct PersonTranslationData {
162    pub biography: String,
163}
164
165#[derive(Debug, Clone, Deserialize)]
166pub struct PersonTranslation {
167    #[serde(rename = "iso_639_1")]
168    pub language: Language,
169    #[serde(rename = "iso_3166_1")]
170    pub country: CountryCode,
171    pub name: String,
172    pub english_name: String,
173    pub data: PersonTranslationData,
174}
175
176#[derive(Debug, Clone, Deserialize)]
177pub struct PersonTranslations {
178    pub translations: Vec<PersonTranslation>,
179}
180
181appendable! {
182    PersonCredits,
183    PersonImages,
184    PersonTranslations,
185}
186
187endpoint! {
188    /// the primary details of a person
189    person(id: u64): GET "/person/{id}" => PersonDetails {
190        params { language: Language }
191        base {
192            pub id: u64,
193            pub name: String,
194            #[serde(default)]
195            pub also_known_as: Vec<String>,
196            pub biography: String,
197            #[serde(default, deserialize_with = "crate::common::opt_date")]
198            pub birthday: Option<Date>,
199            #[serde(default, deserialize_with = "crate::common::opt_date")]
200            pub deathday: Option<Date>,
201            pub gender: Option<u32>,
202            #[serde(rename = "homepage")]
203            pub website: Option<String>,
204            pub imdb_id: Option<String>,
205            pub known_for_department: Option<String>,
206            pub place_of_birth: Option<String>,
207            pub popularity: f64,
208            #[serde(rename = "profile_path")]
209    pub profile: Option<Profile>,
210            pub adult: bool,
211        }
212        appends {
213            changes: Changes,
214            combined_credits: PersonCredits,
215            external_ids: ExternalIds,
216            images: PersonImages,
217            movie_credits: PersonCredits,
218            translations: PersonTranslations,
219            tv_credits: PersonCredits,
220        }
221    }
222}
223
224endpoint! {
225    /// the newest person
226    person_latest(): GET "/person/latest" => PersonDetails {
227        params { language: Language }
228    }
229}
230
231endpoint! {
232    /// people ordered by popularity
233    person_popular(): GET "/person/popular" => Page<PersonShort> {
234        params { language: Language, page: u32 }
235    }
236}
237
238endpoint! {
239    /// a person's recent changes
240    person_changes(id: u64): GET "/person/{id}/changes" => Changes {
241        params { start_date: Date, end_date: Date, page: u32 }
242    }
243}
244
245endpoint! {
246    /// a person's combined movie and series credits
247    person_combined_credits(id: u64): GET "/person/{id}/combined_credits" => PersonCredits {
248        params { language: Language }
249    }
250}
251
252endpoint! {
253    /// a person's movie credits
254    person_movie_credits(id: u64): GET "/person/{id}/movie_credits" => PersonCredits {
255        params { language: Language }
256    }
257}
258
259endpoint! {
260    /// a person's series credits
261    person_tv_credits(id: u64): GET "/person/{id}/tv_credits" => PersonCredits {
262        params { language: Language }
263    }
264}
265
266endpoint! {
267    /// a person's ids on other databases
268    person_external_ids(id: u64): GET "/person/{id}/external_ids" => ExternalIds
269}
270
271endpoint! {
272    /// a person's profile images
273    person_images(id: u64): GET "/person/{id}/images" => Vec<Image<Profile>> [profiles]
274}
275
276endpoint! {
277    /// a person's translations
278    person_translations(id: u64): GET "/person/{id}/translations" => PersonTranslations
279}