cameo 0.2.0

Unified movie/TV show database SDK for Rust
Documentation
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
//! Constructors and builder-style setters for the unified models.
//!
//! Every `Unified*` model is `#[non_exhaustive]`, which forbids struct-literal
//! construction outside this crate. Out-of-crate providers implementing the
//! unified traits still need to *build* the values their impls return, so each
//! model exposes a `new(...)` constructor (taking the genuinely required
//! fields) plus chainable `with_*` setters for the optional ones.
//!
//! ```
//! use cameo::{MediaId, PartialDate, UnifiedMovie};
//!
//! let movie = UnifiedMovie::new(MediaId::tmdb(550), "Fight Club")
//!     .with_overview("A ticking-time-bomb insomniac...")
//!     .with_release_date(PartialDate::from_year(1999))
//!     .with_vote_average(8.4);
//! assert_eq!(movie.title, "Fight Club");
//! ```

use super::{date::PartialDate, genre::Genre, media_id::MediaId, models::*};

impl UnifiedMovie {
    /// Create a movie with the required identity fields; all other fields
    /// default to empty/absent and can be set with the `with_*` methods.
    pub fn new(provider_id: MediaId, title: impl Into<String>) -> Self {
        Self {
            provider_id,
            title: title.into(),
            original_title: None,
            overview: None,
            release_date: None,
            poster_url: None,
            backdrop_url: None,
            genres: Vec::new(),
            popularity: None,
            vote_average: None,
            vote_count: None,
            original_language: None,
            adult: None,
        }
    }

    /// Set the original-language title.
    pub fn with_original_title(mut self, value: impl Into<String>) -> Self {
        self.original_title = Some(value.into());
        self
    }
    /// Set the overview / synopsis.
    pub fn with_overview(mut self, value: impl Into<String>) -> Self {
        self.overview = Some(value.into());
        self
    }
    /// Set the release date.
    pub fn with_release_date(mut self, value: PartialDate) -> Self {
        self.release_date = Some(value);
        self
    }
    /// Set the poster image URL.
    pub fn with_poster_url(mut self, value: impl Into<String>) -> Self {
        self.poster_url = Some(value.into());
        self
    }
    /// Set the backdrop image URL.
    pub fn with_backdrop_url(mut self, value: impl Into<String>) -> Self {
        self.backdrop_url = Some(value.into());
        self
    }
    /// Set the genres.
    pub fn with_genres(mut self, value: Vec<Genre>) -> Self {
        self.genres = value;
        self
    }
    /// Set the popularity score.
    pub fn with_popularity(mut self, value: f64) -> Self {
        self.popularity = Some(value);
        self
    }
    /// Set the average vote score.
    pub fn with_vote_average(mut self, value: f64) -> Self {
        self.vote_average = Some(value);
        self
    }
    /// Set the vote count.
    pub fn with_vote_count(mut self, value: u64) -> Self {
        self.vote_count = Some(value);
        self
    }
    /// Set the original language (ISO 639-1).
    pub fn with_original_language(mut self, value: impl Into<String>) -> Self {
        self.original_language = Some(value.into());
        self
    }
    /// Set whether this is adult content.
    pub fn with_adult(mut self, value: bool) -> Self {
        self.adult = Some(value);
        self
    }
}

impl UnifiedMovieDetails {
    /// Create movie details wrapping a base [`UnifiedMovie`].
    pub fn new(movie: UnifiedMovie) -> Self {
        Self {
            movie,
            tagline: None,
            runtime: None,
            budget: None,
            revenue: None,
            status: None,
            homepage: None,
            imdb_id: None,
            production_companies: Vec::new(),
            production_countries: Vec::new(),
            spoken_languages: Vec::new(),
            video: false,
            belongs_to_collection: None,
        }
    }

    /// Set the tagline.
    pub fn with_tagline(mut self, value: impl Into<String>) -> Self {
        self.tagline = Some(value.into());
        self
    }
    /// Set the runtime in minutes.
    pub fn with_runtime(mut self, value: u32) -> Self {
        self.runtime = Some(value);
        self
    }
    /// Set the production budget in USD.
    pub fn with_budget(mut self, value: u64) -> Self {
        self.budget = Some(value);
        self
    }
    /// Set the box-office revenue in USD.
    pub fn with_revenue(mut self, value: u64) -> Self {
        self.revenue = Some(value);
        self
    }
    /// Set the release status.
    pub fn with_status(mut self, value: impl Into<String>) -> Self {
        self.status = Some(value.into());
        self
    }
    /// Set the homepage URL.
    pub fn with_homepage(mut self, value: impl Into<String>) -> Self {
        self.homepage = Some(value.into());
        self
    }
    /// Set the IMDB id.
    pub fn with_imdb_id(mut self, value: impl Into<String>) -> Self {
        self.imdb_id = Some(value.into());
        self
    }
    /// Set the production companies.
    pub fn with_production_companies(mut self, value: Vec<Company>) -> Self {
        self.production_companies = value;
        self
    }
    /// Set the production countries.
    pub fn with_production_countries(mut self, value: Vec<String>) -> Self {
        self.production_countries = value;
        self
    }
    /// Set the spoken languages.
    pub fn with_spoken_languages(mut self, value: Vec<String>) -> Self {
        self.spoken_languages = value;
        self
    }
    /// Set whether the movie has a video.
    pub fn with_video(mut self, value: bool) -> Self {
        self.video = value;
        self
    }
    /// Set the collection this movie belongs to.
    pub fn with_collection(mut self, value: Collection) -> Self {
        self.belongs_to_collection = Some(value);
        self
    }
}

impl UnifiedTvShow {
    /// Create a TV show with the required identity fields.
    pub fn new(provider_id: MediaId, name: impl Into<String>) -> Self {
        Self {
            provider_id,
            name: name.into(),
            original_name: None,
            overview: None,
            first_air_date: None,
            poster_url: None,
            backdrop_url: None,
            genres: Vec::new(),
            popularity: None,
            vote_average: None,
            vote_count: None,
            original_language: None,
            origin_country: Vec::new(),
            adult: None,
        }
    }

    /// Set the original-language name.
    pub fn with_original_name(mut self, value: impl Into<String>) -> Self {
        self.original_name = Some(value.into());
        self
    }
    /// Set the overview / synopsis.
    pub fn with_overview(mut self, value: impl Into<String>) -> Self {
        self.overview = Some(value.into());
        self
    }
    /// Set the first air date.
    pub fn with_first_air_date(mut self, value: PartialDate) -> Self {
        self.first_air_date = Some(value);
        self
    }
    /// Set the poster image URL.
    pub fn with_poster_url(mut self, value: impl Into<String>) -> Self {
        self.poster_url = Some(value.into());
        self
    }
    /// Set the backdrop image URL.
    pub fn with_backdrop_url(mut self, value: impl Into<String>) -> Self {
        self.backdrop_url = Some(value.into());
        self
    }
    /// Set the genres.
    pub fn with_genres(mut self, value: Vec<Genre>) -> Self {
        self.genres = value;
        self
    }
    /// Set the popularity score.
    pub fn with_popularity(mut self, value: f64) -> Self {
        self.popularity = Some(value);
        self
    }
    /// Set the average vote score.
    pub fn with_vote_average(mut self, value: f64) -> Self {
        self.vote_average = Some(value);
        self
    }
    /// Set the vote count.
    pub fn with_vote_count(mut self, value: u64) -> Self {
        self.vote_count = Some(value);
        self
    }
    /// Set the original language (ISO 639-1).
    pub fn with_original_language(mut self, value: impl Into<String>) -> Self {
        self.original_language = Some(value.into());
        self
    }
    /// Set the origin countries.
    pub fn with_origin_country(mut self, value: Vec<String>) -> Self {
        self.origin_country = value;
        self
    }
    /// Set whether this is adult content.
    pub fn with_adult(mut self, value: bool) -> Self {
        self.adult = Some(value);
        self
    }
}

impl UnifiedTvShowDetails {
    /// Create TV show details wrapping a base [`UnifiedTvShow`].
    pub fn new(show: UnifiedTvShow) -> Self {
        Self {
            show,
            tagline: None,
            number_of_seasons: None,
            number_of_episodes: None,
            in_production: false,
            status: None,
            homepage: None,
            networks: Vec::new(),
            production_companies: Vec::new(),
            last_air_date: None,
            type_: None,
            media_format: None,
            created_by: Vec::new(),
            episode_run_time: Vec::new(),
            spoken_languages: Vec::new(),
            production_countries: Vec::new(),
            seasons: Vec::new(),
        }
    }

    /// Set the tagline.
    pub fn with_tagline(mut self, value: impl Into<String>) -> Self {
        self.tagline = Some(value.into());
        self
    }
    /// Set the number of seasons.
    pub fn with_number_of_seasons(mut self, value: u32) -> Self {
        self.number_of_seasons = Some(value);
        self
    }
    /// Set the number of episodes.
    pub fn with_number_of_episodes(mut self, value: u32) -> Self {
        self.number_of_episodes = Some(value);
        self
    }
    /// Set whether the show is still in production.
    pub fn with_in_production(mut self, value: bool) -> Self {
        self.in_production = value;
        self
    }
    /// Set the release status.
    pub fn with_status(mut self, value: impl Into<String>) -> Self {
        self.status = Some(value.into());
        self
    }
    /// Set the homepage URL.
    pub fn with_homepage(mut self, value: impl Into<String>) -> Self {
        self.homepage = Some(value.into());
        self
    }
    /// Set the networks.
    pub fn with_networks(mut self, value: Vec<Network>) -> Self {
        self.networks = value;
        self
    }
    /// Set the production companies.
    pub fn with_production_companies(mut self, value: Vec<Company>) -> Self {
        self.production_companies = value;
        self
    }
    /// Set the last air date.
    pub fn with_last_air_date(mut self, value: PartialDate) -> Self {
        self.last_air_date = Some(value);
        self
    }
    /// Set the show classification (e.g. "Scripted").
    pub fn with_type(mut self, value: impl Into<String>) -> Self {
        self.type_ = Some(value.into());
        self
    }
    /// Set the provider media format (e.g. "TV", "OVA").
    pub fn with_media_format(mut self, value: impl Into<String>) -> Self {
        self.media_format = Some(value.into());
        self
    }
    /// Set the creators.
    pub fn with_created_by(mut self, value: Vec<Creator>) -> Self {
        self.created_by = value;
        self
    }
    /// Set the episode run times in minutes.
    pub fn with_episode_run_time(mut self, value: Vec<u32>) -> Self {
        self.episode_run_time = value;
        self
    }
    /// Set the spoken languages.
    pub fn with_spoken_languages(mut self, value: Vec<String>) -> Self {
        self.spoken_languages = value;
        self
    }
    /// Set the production countries.
    pub fn with_production_countries(mut self, value: Vec<String>) -> Self {
        self.production_countries = value;
        self
    }
    /// Set the seasons.
    pub fn with_seasons(mut self, value: Vec<UnifiedSeason>) -> Self {
        self.seasons = value;
        self
    }
}

impl UnifiedSeason {
    /// Create a season summary for the given season number.
    pub fn new(season_number: u32) -> Self {
        Self {
            season_number,
            name: None,
            overview: None,
            air_date: None,
            episode_count: None,
            poster_url: None,
        }
    }

    /// Set the season name.
    pub fn with_name(mut self, value: impl Into<String>) -> Self {
        self.name = Some(value.into());
        self
    }
    /// Set the overview.
    pub fn with_overview(mut self, value: impl Into<String>) -> Self {
        self.overview = Some(value.into());
        self
    }
    /// Set the air date.
    pub fn with_air_date(mut self, value: PartialDate) -> Self {
        self.air_date = Some(value);
        self
    }
    /// Set the episode count.
    pub fn with_episode_count(mut self, value: u32) -> Self {
        self.episode_count = Some(value);
        self
    }
    /// Set the poster image URL.
    pub fn with_poster_url(mut self, value: impl Into<String>) -> Self {
        self.poster_url = Some(value.into());
        self
    }
}

impl UnifiedPerson {
    /// Create a person with the required identity fields.
    pub fn new(provider_id: MediaId, name: impl Into<String>) -> Self {
        Self {
            provider_id,
            name: name.into(),
            known_for_department: None,
            profile_url: None,
            popularity: None,
            gender: None,
            adult: None,
        }
    }

    /// Set the known-for department.
    pub fn with_known_for_department(mut self, value: impl Into<String>) -> Self {
        self.known_for_department = Some(value.into());
        self
    }
    /// Set the profile image URL.
    pub fn with_profile_url(mut self, value: impl Into<String>) -> Self {
        self.profile_url = Some(value.into());
        self
    }
    /// Set the popularity score.
    pub fn with_popularity(mut self, value: f64) -> Self {
        self.popularity = Some(value);
        self
    }
    /// Set the gender.
    pub fn with_gender(mut self, value: Gender) -> Self {
        self.gender = Some(value);
        self
    }
    /// Set whether the person is associated with adult content.
    pub fn with_adult(mut self, value: bool) -> Self {
        self.adult = Some(value);
        self
    }
}

impl UnifiedPersonDetails {
    /// Create person details wrapping a base [`UnifiedPerson`].
    pub fn new(person: UnifiedPerson) -> Self {
        Self {
            person,
            biography: None,
            birthday: None,
            deathday: None,
            place_of_birth: None,
            imdb_id: None,
            homepage: None,
            also_known_as: Vec::new(),
        }
    }

    /// Set the biography.
    pub fn with_biography(mut self, value: impl Into<String>) -> Self {
        self.biography = Some(value.into());
        self
    }
    /// Set the birthday.
    pub fn with_birthday(mut self, value: PartialDate) -> Self {
        self.birthday = Some(value);
        self
    }
    /// Set the death day.
    pub fn with_deathday(mut self, value: PartialDate) -> Self {
        self.deathday = Some(value);
        self
    }
    /// Set the place of birth.
    pub fn with_place_of_birth(mut self, value: impl Into<String>) -> Self {
        self.place_of_birth = Some(value.into());
        self
    }
    /// Set the IMDB id.
    pub fn with_imdb_id(mut self, value: impl Into<String>) -> Self {
        self.imdb_id = Some(value.into());
        self
    }
    /// Set the homepage URL.
    pub fn with_homepage(mut self, value: impl Into<String>) -> Self {
        self.homepage = Some(value.into());
        self
    }
    /// Set the other names the person is known by.
    pub fn with_also_known_as(mut self, value: Vec<String>) -> Self {
        self.also_known_as = value;
        self
    }
}

impl UnifiedSeasonDetails {
    /// Create season details for the given show and season number.
    pub fn new(show_id: MediaId, season_number: u32) -> Self {
        Self {
            show_id,
            season_number,
            name: None,
            overview: None,
            air_date: None,
            poster_url: None,
            episodes: Vec::new(),
        }
    }

    /// Set the season name.
    pub fn with_name(mut self, value: impl Into<String>) -> Self {
        self.name = Some(value.into());
        self
    }
    /// Set the overview.
    pub fn with_overview(mut self, value: impl Into<String>) -> Self {
        self.overview = Some(value.into());
        self
    }
    /// Set the air date.
    pub fn with_air_date(mut self, value: PartialDate) -> Self {
        self.air_date = Some(value);
        self
    }
    /// Set the poster image URL.
    pub fn with_poster_url(mut self, value: impl Into<String>) -> Self {
        self.poster_url = Some(value.into());
        self
    }
    /// Set the episodes.
    pub fn with_episodes(mut self, value: Vec<UnifiedEpisode>) -> Self {
        self.episodes = value;
        self
    }
}

impl UnifiedEpisode {
    /// Create an episode for the given episode number.
    pub fn new(episode_number: u32) -> Self {
        Self {
            episode_number,
            name: None,
            overview: None,
            air_date: None,
            runtime: None,
            still_url: None,
            vote_average: None,
        }
    }

    /// Set the episode name.
    pub fn with_name(mut self, value: impl Into<String>) -> Self {
        self.name = Some(value.into());
        self
    }
    /// Set the overview.
    pub fn with_overview(mut self, value: impl Into<String>) -> Self {
        self.overview = Some(value.into());
        self
    }
    /// Set the air date.
    pub fn with_air_date(mut self, value: PartialDate) -> Self {
        self.air_date = Some(value);
        self
    }
    /// Set the runtime in minutes.
    pub fn with_runtime(mut self, value: u32) -> Self {
        self.runtime = Some(value);
        self
    }
    /// Set the still image URL.
    pub fn with_still_url(mut self, value: impl Into<String>) -> Self {
        self.still_url = Some(value.into());
        self
    }
    /// Set the average vote score.
    pub fn with_vote_average(mut self, value: f64) -> Self {
        self.vote_average = Some(value);
        self
    }
}

impl UnifiedWatchProviders {
    /// Create an empty watch-providers set for the given media id.
    pub fn new(provider_id: MediaId) -> Self {
        Self {
            provider_id,
            results: std::collections::HashMap::new(),
        }
    }

    /// Insert a per-country entry.
    pub fn with_country(
        mut self,
        country_code: impl Into<String>,
        entry: UnifiedWatchProviderEntry,
    ) -> Self {
        self.results.insert(country_code.into(), entry);
        self
    }
}

impl UnifiedWatchProviderEntry {
    /// Create an empty entry (equivalent to [`Default::default`]).
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the flat-rate / subscription services.
    pub fn with_flatrate(mut self, value: Vec<UnifiedStreamingService>) -> Self {
        self.flatrate = value;
        self
    }
    /// Set the rental services.
    pub fn with_rent(mut self, value: Vec<UnifiedStreamingService>) -> Self {
        self.rent = value;
        self
    }
    /// Set the purchase services.
    pub fn with_buy(mut self, value: Vec<UnifiedStreamingService>) -> Self {
        self.buy = value;
        self
    }
}

impl UnifiedStreamingService {
    /// Create a streaming service with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            logo_url: None,
        }
    }

    /// Set the logo image URL.
    pub fn with_logo_url(mut self, value: impl Into<String>) -> Self {
        self.logo_url = Some(value.into());
        self
    }
}

impl Collection {
    /// Create a collection with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            id: None,
            name: name.into(),
            poster_url: None,
            backdrop_url: None,
        }
    }

    /// Set the collection id.
    pub fn with_id(mut self, value: u64) -> Self {
        self.id = Some(value);
        self
    }
    /// Set the poster image URL.
    pub fn with_poster_url(mut self, value: impl Into<String>) -> Self {
        self.poster_url = Some(value.into());
        self
    }
    /// Set the backdrop image URL.
    pub fn with_backdrop_url(mut self, value: impl Into<String>) -> Self {
        self.backdrop_url = Some(value.into());
        self
    }
}

impl Company {
    /// Create a company with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            id: None,
            name: name.into(),
            logo_url: None,
            origin_country: None,
        }
    }

    /// Set the company id.
    pub fn with_id(mut self, value: u64) -> Self {
        self.id = Some(value);
        self
    }
    /// Set the logo image URL.
    pub fn with_logo_url(mut self, value: impl Into<String>) -> Self {
        self.logo_url = Some(value.into());
        self
    }
    /// Set the origin country.
    pub fn with_origin_country(mut self, value: impl Into<String>) -> Self {
        self.origin_country = Some(value.into());
        self
    }
}

impl Network {
    /// Create a network with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            id: None,
            name: name.into(),
            logo_url: None,
            origin_country: None,
        }
    }

    /// Set the network id.
    pub fn with_id(mut self, value: u64) -> Self {
        self.id = Some(value);
        self
    }
    /// Set the logo image URL.
    pub fn with_logo_url(mut self, value: impl Into<String>) -> Self {
        self.logo_url = Some(value.into());
        self
    }
    /// Set the origin country.
    pub fn with_origin_country(mut self, value: impl Into<String>) -> Self {
        self.origin_country = Some(value.into());
        self
    }
}

impl Creator {
    /// Create a creator with the given name.
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            id: None,
            name: name.into(),
            profile_url: None,
        }
    }

    /// Set the creator id.
    pub fn with_id(mut self, value: u64) -> Self {
        self.id = Some(value);
        self
    }
    /// Set the profile image URL.
    pub fn with_profile_url(mut self, value: impl Into<String>) -> Self {
        self.profile_url = Some(value.into());
        self
    }
}

impl UnifiedSearchResult {
    /// Wrap a movie as a search result.
    pub fn movie(movie: UnifiedMovie) -> Self {
        UnifiedSearchResult::Movie(movie)
    }
    /// Wrap a TV show as a search result.
    pub fn tv_show(show: UnifiedTvShow) -> Self {
        UnifiedSearchResult::TvShow(show)
    }
    /// Wrap a person as a search result.
    pub fn person(person: UnifiedPerson) -> Self {
        UnifiedSearchResult::Person(person)
    }
}