diff options
Diffstat (limited to 'import/src/trakt.rs')
| -rw-r--r-- | import/src/trakt.rs | 124 |
1 files changed, 88 insertions, 36 deletions
diff --git a/import/src/trakt.rs b/import/src/trakt.rs index f25fa9e..3f0ad47 100644 --- a/import/src/trakt.rs +++ b/import/src/trakt.rs @@ -5,9 +5,8 @@ */ use crate::USER_AGENT; use anyhow::Context; -use bincode::{Decode, Encode}; use jellycache::async_cache_memory; -use jellycommon::{Appearance, ObjectIds, PeopleGroup, Person, TraktKind}; +use jellycommon::{Appearance, CreditCategory, NodeID}; use log::info; use reqwest::{ header::{HeaderMap, HeaderName, HeaderValue}, @@ -120,10 +119,10 @@ impl Trakt { } } -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TraktSeason { pub number: usize, - pub ids: ObjectIds, + pub ids: TraktIds, pub rating: f64, pub votes: usize, pub episode_count: usize, @@ -133,12 +132,12 @@ pub struct TraktSeason { pub network: String, } -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TraktEpisode { pub season: Option<usize>, pub number: usize, pub number_abs: Option<usize>, - pub ids: ObjectIds, + pub ids: TraktIds, pub rating: f64, pub votes: usize, pub title: String, @@ -149,7 +148,7 @@ pub struct TraktEpisode { pub episode_type: String, } -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TraktPeople { #[serde(default)] pub cast: Vec<TraktAppearance>, @@ -157,7 +156,7 @@ pub struct TraktPeople { pub crew: BTreeMap<TraktPeopleGroup, Vec<TraktAppearance>>, } -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TraktAppearance { #[serde(default)] pub jobs: Vec<String>, @@ -166,13 +165,13 @@ pub struct TraktAppearance { pub person: TraktPerson, } -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] +#[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TraktPerson { pub name: String, - pub ids: ObjectIds, + pub ids: TraktIds, } -#[derive(Debug, Serialize, Deserialize, Encode, Decode)] +#[derive(Debug, Serialize, Deserialize)] pub struct TraktSearchResult { pub r#type: TraktKind, pub score: f64, @@ -180,7 +179,7 @@ pub struct TraktSearchResult { pub inner: TraktKindObject, } -#[derive(Debug, Serialize, Deserialize, Encode, Decode)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum TraktKindObject { Movie(TraktMediaObject), @@ -204,9 +203,7 @@ impl TraktKindObject { } } -#[derive( - Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Clone, Copy, -)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] pub enum TraktPeopleGroup { #[serde(rename = "production")] Production, @@ -234,20 +231,20 @@ pub enum TraktPeopleGroup { CreatedBy, } impl TraktPeopleGroup { - pub fn a(self) -> PeopleGroup { + pub fn a(self) -> CreditCategory { match self { - TraktPeopleGroup::Production => PeopleGroup::Production, - TraktPeopleGroup::Art => PeopleGroup::Art, - TraktPeopleGroup::Crew => PeopleGroup::Crew, - TraktPeopleGroup::CostumeMakeup => PeopleGroup::CostumeMakeup, - TraktPeopleGroup::Directing => PeopleGroup::Directing, - TraktPeopleGroup::Writing => PeopleGroup::Writing, - TraktPeopleGroup::Sound => PeopleGroup::Sound, - TraktPeopleGroup::Camera => PeopleGroup::Camera, - TraktPeopleGroup::VisualEffects => PeopleGroup::Vfx, - TraktPeopleGroup::Lighting => PeopleGroup::Lighting, - TraktPeopleGroup::Editing => PeopleGroup::Editing, - TraktPeopleGroup::CreatedBy => PeopleGroup::CreatedBy, + TraktPeopleGroup::Production => CreditCategory::Production, + TraktPeopleGroup::Art => CreditCategory::Art, + TraktPeopleGroup::Crew => CreditCategory::Crew, + TraktPeopleGroup::CostumeMakeup => CreditCategory::CostumeMakeup, + TraktPeopleGroup::Directing => CreditCategory::Directing, + TraktPeopleGroup::Writing => CreditCategory::Writing, + TraktPeopleGroup::Sound => CreditCategory::Sound, + TraktPeopleGroup::Camera => CreditCategory::Camera, + TraktPeopleGroup::VisualEffects => CreditCategory::Vfx, + TraktPeopleGroup::Lighting => CreditCategory::Lighting, + TraktPeopleGroup::Editing => CreditCategory::Editing, + TraktPeopleGroup::CreatedBy => CreditCategory::CreatedBy, } } } @@ -256,20 +253,20 @@ impl TraktAppearance { Appearance { jobs: self.jobs.to_owned(), characters: self.characters.to_owned(), - person: Person { - name: self.person.name.to_owned(), - headshot: None, - ids: self.person.ids.to_owned(), - }, + node: NodeID([0; 32]), // person: Person { + // name: self.person.name.to_owned(), + // headshot: None, + // ids: self.person.ids.to_owned(), + // }, } } } -#[derive(Debug, Serialize, Deserialize, Encode, Decode, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct TraktMediaObject { pub title: String, pub year: Option<u32>, - pub ids: ObjectIds, + pub ids: TraktIds, pub tagline: Option<String>, pub overview: Option<String>, @@ -287,10 +284,19 @@ pub struct TraktMediaObject { pub genres: Option<Vec<String>>, } +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +pub struct TraktIds { + pub trakt: Option<u64>, + pub slug: Option<String>, + pub tvdb: Option<u64>, + pub imdb: Option<String>, + pub tmdb: Option<u64>, +} + impl Display for TraktSearchResult { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!( - "{} ({}) \x1b[2m{} [{}]\x1b[0m", + "{} ({}) \x1b[2m{} [{:?}]\x1b[0m", self.inner.inner().title, self.inner.inner().year.unwrap_or(0), self.r#type, @@ -298,3 +304,49 @@ impl Display for TraktSearchResult { )) } } + +#[derive(Debug, Serialize, Deserialize, Clone, Copy, Hash, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum TraktKind { + Movie, + Show, + Season, + Episode, + Person, + User, +} + +impl TraktKind { + pub fn singular(self) -> &'static str { + match self { + TraktKind::Movie => "movie", + TraktKind::Show => "show", + TraktKind::Season => "season", + TraktKind::Episode => "episode", + TraktKind::Person => "person", + TraktKind::User => "user", + } + } + pub fn plural(self) -> &'static str { + match self { + TraktKind::Movie => "movies", + TraktKind::Show => "shows", + TraktKind::Season => "seasons", + TraktKind::Episode => "episodes", + TraktKind::Person => "people", + TraktKind::User => "users", // //! not used in API + } + } +} +impl Display for TraktKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + TraktKind::Movie => "Movie", + TraktKind::Show => "Show", + TraktKind::Season => "Season", + TraktKind::Episode => "Episode", + TraktKind::Person => "Person", + TraktKind::User => "User", + }) + } +} |