diff options
Diffstat (limited to 'import/src/plugins/trakt.rs')
| -rw-r--r-- | import/src/plugins/trakt.rs | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/import/src/plugins/trakt.rs b/import/src/plugins/trakt.rs index 7981713..5aee881 100644 --- a/import/src/plugins/trakt.rs +++ b/import/src/plugins/trakt.rs @@ -9,6 +9,8 @@ use crate::{ }; use anyhow::{Context, Result, anyhow, bail}; use jellycache::{HashKey, cache_memory}; +use jellycommon::jellyobject::{Object, Tag}; +use jellydb::table::RowNum; use log::info; use reqwest::{ Client, ClientBuilder, @@ -248,33 +250,21 @@ pub enum TraktPeopleGroup { CreatedBy, } impl TraktPeopleGroup { - pub fn as_credit_category(self) -> CreditCategory { + pub fn as_credit_category(self) -> Tag { + use jellycommon::*; match self { - 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, - } - } -} -impl TraktAppearance { - pub fn a(&self) -> Appearance { - Appearance { - jobs: self.jobs.to_owned(), - characters: self.characters.to_owned(), - node: NodeID([0; 32]), // person: Person { - // name: self.person.name.to_owned(), - // headshot: None, - // ids: self.person.ids.to_owned(), - // }, + TraktPeopleGroup::Production => CRCAT_PRODUCTION, + TraktPeopleGroup::Art => CRCAT_ART, + TraktPeopleGroup::Crew => CRCAT_CREW, + TraktPeopleGroup::CostumeMakeup => CRCAT_COSTUME_MAKEUP, + TraktPeopleGroup::Directing => CRCAT_DIRECTING, + TraktPeopleGroup::Writing => CRCAT_WRITING, + TraktPeopleGroup::Sound => CRCAT_SOUND, + TraktPeopleGroup::Camera => CRCAT_CAMERA, + TraktPeopleGroup::VisualEffects => CRCAT_VFX, + TraktPeopleGroup::Lighting => CRCAT_LIGHTING, + TraktPeopleGroup::Editing => CRCAT_EDITING, + TraktPeopleGroup::CreatedBy => CRCAT_CREATED_BY, } } } @@ -334,14 +324,15 @@ pub enum TraktKind { } impl TraktKind { - pub fn as_node_kind(self) -> NodeKind { + pub fn as_node_kind(self) -> Tag { + use jellycommon::*; match self { - TraktKind::Movie => NodeKind::Movie, - TraktKind::Show => NodeKind::Show, - TraktKind::Season => NodeKind::Season, - TraktKind::Episode => NodeKind::Episode, - TraktKind::Person => NodeKind::Channel, - TraktKind::User => NodeKind::Channel, + TraktKind::Movie => KIND_MOVIE, + TraktKind::Show => KIND_SHOW, + TraktKind::Season => KIND_SEASON, + TraktKind::Episode => KIND_EPISODE, + TraktKind::Person => KIND_CHANNEL, + TraktKind::User => KIND_CHANNEL, } } } @@ -390,31 +381,33 @@ impl ImportPlugin for Trakt { ..Default::default() } } - fn instruction(&self, ct: &ImportContext, node: NodeID, line: &str) -> Result<()> { + fn instruction(&self, ct: &ImportContext, node: RowNum, line: &str) -> Result<()> { + use jellycommon::*; if let Some(value) = line.strip_prefix("trakt-").or(line.strip_prefix("trakt=")) { let (ty, id) = value.split_once(":").unwrap_or(("movie", value)); let ty = match ty { - "movie" => IdentifierType::TraktMovie, - "show" => IdentifierType::TraktShow, - "season" => IdentifierType::TraktSeason, - "episode" => IdentifierType::TraktEpisode, + "movie" => IDENT_TRAKT_MOVIE, + "show" => IDENT_TRAKT_SHOW, + "season" => IDENT_TRAKT_SEASON, + "episode" => IDENT_TRAKT_EPISODE, _ => bail!("unknown trakt kind"), }; - ct.db.update_node_init(node, |node| { - node.identifiers.insert(ty, id.to_owned()); + ct.dba.update_node(node, |node| { + node.as_object() + .update(NO_IDENTIFIERS, |idents| idents.insert(ty, id)) })?; } Ok(()) } - fn process(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> { - self.process_primary(ct, node, data)?; - self.process_episode(ct, node, data)?; + fn process(&self, ct: &ImportContext, node: RowNum, data: Object) -> Result<()> { + self.process_primary(ct, node.clone(), data)?; + self.process_episode(ct, node.clone(), data)?; Ok(()) } } impl Trakt { - fn process_primary(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> { + fn process_primary(&self, ct: &ImportContext, node: RowNum, data: Object) -> Result<()> { let (trakt_kind, trakt_id): (_, u64) = if let Some(id) = data.identifiers.get(&IdentifierType::TraktShow) { (TraktKind::Show, id.parse()?) @@ -486,7 +479,7 @@ impl Trakt { })?; Ok(()) } - fn process_episode(&self, ct: &ImportContext, node: NodeID, node_data: &Node) -> Result<()> { + fn process_episode(&self, ct: &ImportContext, node: RowNum, node_data: Object) -> Result<()> { let (Some(episode), Some(season)) = (node_data.index, node_data.season_index) else { return Ok(()); }; |