aboutsummaryrefslogtreecommitdiff
path: root/import
diff options
context:
space:
mode:
Diffstat (limited to 'import')
-rw-r--r--import/src/lib.rs1
-rw-r--r--import/src/plugins/tmdb.rs85
-rw-r--r--import/src/plugins/trakt.rs75
3 files changed, 104 insertions, 57 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs
index bba81d9..3b7c8fc 100644
--- a/import/src/lib.rs
+++ b/import/src/lib.rs
@@ -256,6 +256,7 @@ fn import_file(
else {
return;
};
+ nodes.lock().unwrap().insert(parent);
for line in content.lines() {
for p in plugins {
let inf = p.info();
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(())
}
}
diff --git a/import/src/plugins/trakt.rs b/import/src/plugins/trakt.rs
index 8c66c85..706d2b7 100644
--- a/import/src/plugins/trakt.rs
+++ b/import/src/plugins/trakt.rs
@@ -416,17 +416,17 @@ impl ImportPlugin for Trakt {
}
impl Trakt {
- fn process_show(&self, ct: &ImportContext, node: NodeID, node_data: &Node) -> Result<()> {
+ fn process_show(&self, ct: &ImportContext, node: NodeID, data: &Node) -> Result<()> {
let (trakt_kind, trakt_id): (_, u64) =
- if let Some(id) = node_data.identifiers.get(&IdentifierType::TraktShow) {
+ if let Some(id) = data.identifiers.get(&IdentifierType::TraktShow) {
(TraktKind::Show, id.parse()?)
- } else if let Some(id) = node_data.identifiers.get(&IdentifierType::TraktMovie) {
+ } else if let Some(id) = data.identifiers.get(&IdentifierType::TraktMovie) {
(TraktKind::Movie, id.parse()?)
} else {
return Ok(());
};
- let data = self.lookup(trakt_kind, trakt_id, ct.rt)?;
+ let details = self.lookup(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();
@@ -445,28 +445,6 @@ impl Trakt {
}
}
- // let mut tmdb_data = None;
- // let mut backdrop = None;
- // let mut poster = None;
- // if let Some(tmdb_id) = data.ids.tmdb {
- // let data = tmdb.details(
- // match trakt_kind {
- // TraktKind::Movie => TmdbKind::Movie,
- // TraktKind::Show => TmdbKind::Tv,
- // _ => TmdbKind::Movie,
- // },
- // tmdb_id,
- // rthandle,
- // )?;
- // tmdb_data = Some(data.clone());
-
- // if let Some(path) = &data.backdrop_path {
- // backdrop = Some(tmdb.image(path, rthandle).context("tmdb backdrop image")?);
- // }
- // if let Some(path) = &data.poster_path {
- // poster = Some(tmdb.image(path, rthandle).context("tmdb poster image")?);
- // }
-
// for p in people_map.values_mut().flatten() {
// if let Some(id) = p.person.ids.tmdb {
// let k = rthandle.block_on(tmdb.person_image(id))?;
@@ -476,38 +454,37 @@ impl Trakt {
// }
// }
// }
- // }
ct.db.update_node_init(node, |node| {
- node.title = Some(data.title.clone());
- node.credits.extend(people_map);
node.kind = trakt_kind.as_node_kind();
- if let Some(overview) = &data.overview {
+ node.title = Some(details.title.clone());
+ if let Some(overview) = &details.overview {
node.description = Some(overview.clone())
}
- if let Some(tagline) = &data.tagline {
+ if let Some(tagline) = &details.tagline {
node.tagline = Some(tagline.clone())
}
- if let Some(rating) = &data.rating {
+ node.credits.extend(people_map);
+ if let Some(x) = details.ids.imdb.clone() {
+ node.identifiers.insert(IdentifierType::Imdb, x);
+ }
+ if let Some(x) = details.ids.tvdb.clone() {
+ node.identifiers.insert(IdentifierType::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,
+ };
+ }
+ if let Some(rating) = &details.rating {
node.ratings.insert(RatingType::Trakt, *rating);
}
- // if let Some(poster) = poster {
- // node.pictures.insert(PictureSlot::Cover, poster);
- // }
- // if let Some(backdrop) = backdrop {
- // node.pictures.insert(PictureSlot::Backdrop, backdrop);
- // }
- // if let Some(data) = tmdb_data {
- // node.title = data.title.clone().or(node.title.clone());
- // node.tagline = data.tagline.clone().or(node.tagline.clone());
- // node.description = Some(data.overview.clone());
- // node.ratings.insert(RatingType::Tmdb, data.vote_average);
- // if let Some(date) = data.release_date.clone() {
- // if let Ok(date) = tmdb::parse_release_date(&date) {
- // node.release_date = date;
- // }
- // }
- // }
Ok(())
})?;
Ok(())