aboutsummaryrefslogtreecommitdiff
path: root/import/src/plugins/tmdb.rs
diff options
context:
space:
mode:
Diffstat (limited to 'import/src/plugins/tmdb.rs')
-rw-r--r--import/src/plugins/tmdb.rs85
1 files changed, 77 insertions, 8 deletions
diff --git a/import/src/plugins/tmdb.rs b/import/src/plugins/tmdb.rs
index 427f27c..c718976 100644
--- a/import/src/plugins/tmdb.rs
+++ b/import/src/plugins/tmdb.rs
@@ -10,7 +10,7 @@ use crate::{
use anyhow::{Context, Result, anyhow, bail};
use jellycache::{EscapeKey, HashKey, cache_memory, cache_store};
use jellycommon::{
- Asset, Node, NodeID,
+ Asset, IdentifierType, Node, NodeID, PictureSlot, RatingType,
chrono::{Utc, format::Parsed},
};
use log::info;
@@ -160,17 +160,86 @@ impl ImportPlugin for Tmdb {
fn info(&self) -> PluginInfo {
PluginInfo {
name: "tmdb",
+ handle_process: true,
..Default::default()
}
}
fn process(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> {
- // let trakt_details = trakt.lookup(TraktKind::Show, trakt_id, rthandle)?;
- // if let Some(tmdb_id) = trakt_details.ids.tmdb {
- // let tmdb_details = tmdb.episode_details(tmdb_id, season, episode, rthandle)?;
- // if let Some(still) = &tmdb_details.still_path {
- // poster = Some(tmdb.image(still, rthandle)?)
- // }
- // }
+ self.process_primary(ct, node, data)?;
+ self.process_episode(ct, node, data)?;
+ Ok(())
+ }
+}
+impl Tmdb {
+ fn process_primary(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> {
+ let (tmdb_kind, tmdb_id): (_, u64) =
+ if let Some(id) = data.identifiers.get(&IdentifierType::TmdbSeries) {
+ (TmdbKind::Tv, id.parse()?)
+ } else if let Some(id) = data.identifiers.get(&IdentifierType::TmdbMovie) {
+ (TmdbKind::Movie, id.parse()?)
+ } else {
+ return Ok(());
+ };
+
+ let details = self.details(tmdb_kind, tmdb_id, ct.rt)?;
+ let mut images = Vec::new();
+ if let Some(path) = &details.backdrop_path {
+ images.push((
+ PictureSlot::Backdrop,
+ self.image(path, ct.rt).context("backdrop image")?,
+ ));
+ }
+ if let Some(path) = &details.poster_path {
+ images.push((
+ PictureSlot::Cover,
+ self.image(path, ct.rt).context("poster image")?,
+ ));
+ }
+
+ let release_date = details
+ .release_date
+ .as_ref()
+ .map(|s| parse_release_date(s))
+ .transpose()?
+ .flatten();
+
+ ct.db.update_node_init(node, |node| {
+ node.title = details.title.clone().or(node.title.clone());
+ node.tagline = details.tagline.clone().or(node.tagline.clone());
+ node.description = Some(details.overview.clone());
+ node.ratings.insert(RatingType::Tmdb, details.vote_average);
+ node.pictures.extend(images);
+ node.release_date = release_date.or(node.release_date);
+ Ok(())
+ })?;
+ Ok(())
+ }
+ fn process_episode(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> {
+ let (Some(episode), Some(season)) = (data.index, data.season_index) else {
+ return Ok(());
+ };
+ let mut series_id = None;
+ for &parent in &data.parents {
+ let parent_data = ct.db.get_node(parent)?.ok_or(anyhow!("parent missing"))?;
+ if let Some(id) = parent_data.identifiers.get(&IdentifierType::TmdbSeries) {
+ series_id = Some(id.parse::<u64>()?);
+ break;
+ }
+ }
+ let Some(series_id) = series_id else {
+ return Ok(());
+ };
+ let details = self.episode_details(series_id, season, episode, ct.rt)?;
+ let mut images = Vec::new();
+ if let Some(path) = &details.still_path {
+ images.push((PictureSlot::Cover, self.image(path, ct.rt)?))
+ }
+
+ ct.db.update_node_init(node, |node| {
+ node.ratings.insert(RatingType::Tmdb, details.vote_average);
+ node.pictures.extend(images);
+ Ok(())
+ })?;
Ok(())
}
}