aboutsummaryrefslogtreecommitdiff
path: root/import/src/plugins/trakt.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-16 17:14:48 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-16 17:14:48 +0100
commitce2b34851d38dc28d6ffbbb4fe563e226acb7445 (patch)
tree04ea331b4549df0d1a0b62e854d65f14137f528c /import/src/plugins/trakt.rs
parent30e13399fa9f815cd1884fe87914cdb22d1985af (diff)
downloadjellything-ce2b34851d38dc28d6ffbbb4fe563e226acb7445.tar
jellything-ce2b34851d38dc28d6ffbbb4fe563e226acb7445.tar.bz2
jellything-ce2b34851d38dc28d6ffbbb4fe563e226acb7445.tar.zst
finish refactoring import crate
Diffstat (limited to 'import/src/plugins/trakt.rs')
-rw-r--r--import/src/plugins/trakt.rs167
1 files changed, 101 insertions, 66 deletions
diff --git a/import/src/plugins/trakt.rs b/import/src/plugins/trakt.rs
index 5aee881..7530449 100644
--- a/import/src/plugins/trakt.rs
+++ b/import/src/plugins/trakt.rs
@@ -9,7 +9,7 @@ use crate::{
};
use anyhow::{Context, Result, anyhow, bail};
use jellycache::{HashKey, cache_memory};
-use jellycommon::jellyobject::{Object, Tag};
+use jellycommon::{jellyobject::Tag, *};
use jellydb::table::RowNum;
use log::info;
use reqwest::{
@@ -119,7 +119,7 @@ impl Trakt {
pub fn show_season_episodes(
&self,
id: u64,
- season: usize,
+ season: u64,
rt: &Handle,
) -> Result<Arc<Vec<TraktEpisode>>> {
cache_memory(
@@ -140,7 +140,7 @@ impl Trakt {
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct TraktSeason {
- pub number: usize,
+ pub number: u64,
pub ids: TraktIds,
pub rating: f64,
pub votes: usize,
@@ -154,7 +154,7 @@ pub struct TraktSeason {
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct TraktEpisode {
pub season: Option<usize>,
- pub number: usize,
+ pub number: u64,
pub number_abs: Option<usize>,
pub ids: TraktIds,
pub rating: Option<f64>,
@@ -251,7 +251,6 @@ pub enum TraktPeopleGroup {
}
impl TraktPeopleGroup {
pub fn as_credit_category(self) -> Tag {
- use jellycommon::*;
match self {
TraktPeopleGroup::Production => CRCAT_PRODUCTION,
TraktPeopleGroup::Art => CRCAT_ART,
@@ -399,42 +398,51 @@ impl ImportPlugin for Trakt {
}
Ok(())
}
- fn process(&self, ct: &ImportContext, node: RowNum, data: Object) -> Result<()> {
- self.process_primary(ct, node.clone(), data)?;
- self.process_episode(ct, node.clone(), data)?;
+ fn process(&self, ct: &ImportContext, node: RowNum) -> Result<()> {
+ self.process_primary(ct, node)?;
+ self.process_episode(ct, node)?;
Ok(())
}
}
impl Trakt {
- 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()?)
- } else if let Some(id) = data.identifiers.get(&IdentifierType::TraktMovie) {
- (TraktKind::Movie, id.parse()?)
- } else {
- return Ok(());
- };
+ fn process_primary(&self, ct: &ImportContext, node: RowNum) -> Result<()> {
+ let data = ct.dba.get_node(node)?.unwrap();
+ let data = data.as_object();
+ let (trakt_kind, trakt_id): (_, u64) = if let Some(id) = data
+ .get(NO_IDENTIFIERS)
+ .unwrap_or_default()
+ .get(IDENT_TRAKT_SHOW)
+ {
+ (TraktKind::Show, id.parse()?)
+ } else if let Some(id) = data
+ .get(NO_IDENTIFIERS)
+ .unwrap_or_default()
+ .get(IDENT_TRAKT_MOVIE)
+ {
+ (TraktKind::Movie, id.parse()?)
+ } else {
+ return Ok(());
+ };
let details = self.lookup(trakt_kind, trakt_id, ct.rt)?;
- let people = self.people(trakt_kind, trakt_id, ct.rt)?;
+ // let people = self.people(trakt_kind, trakt_id, ct.rt)?;
- let mut people_map = BTreeMap::<CreditCategory, Vec<Appearance>>::new();
- for p in people.cast.iter() {
- people_map
- .entry(CreditCategory::Cast)
- .or_default()
- .push(p.a())
- }
- for (group, people) in people.crew.iter() {
- for p in people {
- people_map
- .entry(group.as_credit_category())
- .or_default()
- .push(p.a())
- }
- }
+ // let mut people_map = BTreeMap::<CreditCategory, Vec<Appearance>>::new();
+ // for p in people.cast.iter() {
+ // people_map
+ // .entry(CreditCategory::Cast)
+ // .or_default()
+ // .push(p.a())
+ // }
+ // for (group, people) in people.crew.iter() {
+ // for p in people {
+ // people_map
+ // .entry(group.as_credit_category())
+ // .or_default()
+ // .push(p.a())
+ // }
+ // }
// for p in people_map.values_mut().flatten() {
// if let Some(id) = p.person.ids.tmdb {
@@ -446,51 +454,73 @@ impl Trakt {
// }
// }
- ct.db.update_node_init(node, |node| {
- node.kind = trakt_kind.as_node_kind();
- node.title = Some(details.title.clone());
+ ct.dba.update_node(node, |mut node| {
+ node = node.as_object().insert(NO_KIND, trakt_kind.as_node_kind());
+ node = node.as_object().insert(NO_TITLE, &details.title);
if let Some(overview) = &details.overview {
- node.description = Some(overview.clone())
+ node = node.as_object().insert(NO_DESCRIPTION, &overview);
}
if let Some(tagline) = &details.tagline {
- node.tagline = Some(tagline.clone())
+ node = node.as_object().insert(NO_TAGLINE, &tagline);
}
- node.credits.extend(people_map);
if let Some(x) = details.ids.imdb.clone() {
- node.identifiers.insert(IdentifierType::Imdb, x);
+ node = node
+ .as_object()
+ .update(NO_IDENTIFIERS, |idents| idents.insert(IDENT_IMDB, &x));
}
if let Some(x) = details.ids.tvdb.clone() {
- node.identifiers.insert(IdentifierType::Tvdb, x.to_string());
+ node = node.as_object().update(NO_IDENTIFIERS, |idents| {
+ idents.insert(IDENT_TVDB, &x.to_string())
+ });
}
if let Some(x) = details.ids.tmdb.clone() {
- match trakt_kind {
- TraktKind::Movie => node
- .identifiers
- .insert(IdentifierType::TmdbMovie, x.to_string()),
- TraktKind::Show => node
- .identifiers
- .insert(IdentifierType::TmdbSeries, x.to_string()),
- _ => None,
+ let key = match trakt_kind {
+ TraktKind::Movie => IDENT_TRAKT_MOVIE,
+ TraktKind::Show => IDENT_TRAKT_SHOW,
+ _ => return node,
};
+ node = node
+ .as_object()
+ .update(NO_IDENTIFIERS, |idents| idents.insert(key, &x.to_string()));
}
- if let Some(rating) = &details.rating {
- node.ratings.insert(RatingType::Trakt, *rating);
+ if let Some(rating) = details.rating {
+ node = node
+ .as_object()
+ .update(NO_RATINGS, |idents| idents.insert(RTYP_TRAKT, rating));
}
+ node
})?;
Ok(())
}
- 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 {
+ fn process_episode(&self, ct: &ImportContext, node: RowNum) -> Result<()> {
+ let node_data = ct.dba.get_node(node)?.unwrap();
+ let node_data = node_data.as_object();
+
+ let (Some(episode), Some(season)) =
+ (node_data.get(NO_INDEX), node_data.get(NO_SEASON_INDEX))
+ else {
return Ok(());
};
let mut show_id = None;
- for &parent in &node_data.parents {
- let parent_data = ct.db.get_node(parent)?.ok_or(anyhow!("parent missing"))?;
- if let Some(id) = parent_data.identifiers.get(&IdentifierType::TraktShow) {
- show_id = Some(id.parse::<u64>()?);
- break;
+ ct.dba.db.read_transaction(&mut |txn| {
+ for parent in node_data.iter(NO_PARENT) {
+ let parent_data = ct
+ .dba
+ .nodes
+ .get(txn, parent)?
+ .ok_or(anyhow!("parent missing"))?;
+ if let Some(id) = parent_data
+ .as_object()
+ .get(NO_IDENTIFIERS)
+ .unwrap_or_default()
+ .get(IDENT_TRAKT_SHOW)
+ {
+ show_id = Some(id.parse::<u64>()?);
+ break;
+ }
}
- }
+ Ok(())
+ })?;
let Some(show_id) = show_id else {
return Ok(());
};
@@ -498,15 +528,20 @@ impl Trakt {
let seasons = self.show_seasons(show_id, ct.rt)?;
if seasons.iter().any(|x| x.number == season) {
let episodes = self.show_season_episodes(show_id, season, ct.rt)?;
- if let Some(episode) = episodes.get(episode.saturating_sub(1)) {
- ct.db.update_node_init(node, |node| {
- node.kind = NodeKind::Episode;
- node.index = Some(episode.number);
- node.title = Some(episode.title.clone());
- node.description = episode.overview.clone().or(node.description.clone());
+ if let Some(episode) = episodes.get(episode.saturating_sub(1) as usize) {
+ ct.dba.update_node(node, |mut node| {
+ node = node.as_object().insert(NO_KIND, KIND_EPISODE);
+ node = node.as_object().insert(NO_INDEX, episode.number);
+ node = node.as_object().insert(NO_TITLE, &episode.title);
+ if let Some(overview) = &episode.overview {
+ node = node.as_object().insert(NO_DESCRIPTION, &overview);
+ }
if let Some(r) = episode.rating {
- node.ratings.insert(RatingType::Trakt, r);
+ node = node
+ .as_object()
+ .update(NO_RATINGS, |rats| rats.insert(RTYP_TRAKT, r));
}
+ node
})?;
}
}