aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-03-30 10:38:18 +0100
committermetamuffin <metamuffin@disroot.org>2024-03-30 10:38:18 +0100
commitd2d58e5ce076a00ad97836a036bcdacfb423dfcb (patch)
tree6d378c528e3b311bf70a6b80b6a4c84f99be1741
parent7f9ab0e949666647074f8d195308a69b224024bb (diff)
downloadjellything-d2d58e5ce076a00ad97836a036bcdacfb423dfcb.tar
jellything-d2d58e5ce076a00ad97836a036bcdacfb423dfcb.tar.bz2
jellything-d2d58e5ce076a00ad97836a036bcdacfb423dfcb.tar.zst
probably fix tmdb import
-rw-r--r--common/src/lib.rs15
-rw-r--r--import/src/lib.rs41
-rw-r--r--import/src/tmdb.rs21
3 files changed, 44 insertions, 33 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs
index 951f3f8..27ca24a 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -124,6 +124,7 @@ pub struct ImportOptions {
pub enum ImportSource {
Override(Node),
Tmdb {
+ kind: TmdbKind,
id: u64,
},
Trakt {
@@ -335,3 +336,17 @@ impl Display for PeopleGroup {
})
}
}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode)]
+pub enum TmdbKind {
+ Tv,
+ Movie,
+}
+impl Display for TmdbKind {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(match self {
+ TmdbKind::Tv => "tv",
+ TmdbKind::Movie => "movie",
+ })
+ }
+}
diff --git a/import/src/lib.rs b/import/src/lib.rs
index 7369f7a..bd8f586 100644
--- a/import/src/lib.rs
+++ b/import/src/lib.rs
@@ -8,7 +8,6 @@ pub mod infojson;
pub mod tmdb;
pub mod trakt;
-use crate::tmdb::TmdbKind;
use anyhow::{anyhow, bail, Context, Ok};
use async_recursion::async_recursion;
use base64::Engine;
@@ -23,7 +22,7 @@ use jellybase::{
use jellyclient::Session;
use jellycommon::{
Asset, ExtendedNode, ImportOptions, ImportSource, MediaInfo, Node, NodeKind, NodePrivate,
- NodePublic, PeopleGroup, Rating, SourceTrack, TrackSource,
+ NodePublic, PeopleGroup, Rating, SourceTrack, TmdbKind, TrackSource, TraktKind,
};
use jellymatroska::read::EbmlReader;
use jellyremuxer::metadata::import_metadata;
@@ -361,28 +360,35 @@ async fn process_source(
insert_node_ext(&id, node_ext)?;
if let Some(tid) = trakt_object.ids.tmdb {
- let mut index_path = index_path.to_vec();
- index_path.push(1);
- process_source(
- id,
- ImportSource::Tmdb { id: tid },
- path,
- &index_path,
- db,
- fed,
- ap,
- )
- .await?;
+ if let Some(kind) = match kind {
+ TraktKind::Movie => Some(TmdbKind::Movie),
+ TraktKind::Show => Some(TmdbKind::Tv),
+ TraktKind::Season => Some(TmdbKind::Tv), // TODO
+ TraktKind::Episode | TraktKind::Person | TraktKind::User => None,
+ } {
+ let mut index_path = index_path.to_vec();
+ index_path.push(1);
+ process_source(
+ id,
+ ImportSource::Tmdb { id: tid, kind },
+ path,
+ &index_path,
+ db,
+ fed,
+ ap,
+ )
+ .await?;
+ }
}
}
- ImportSource::Tmdb { id: tid } => {
+ ImportSource::Tmdb { id: tid, kind } => {
info!("tmdb {id}");
let tmdb = ap
.tmdb
.as_ref()
.ok_or(anyhow!("tmdb api key is required"))?;
- let details = tmdb.details(TmdbKind::Movie, tid).await?;
+ let details = tmdb.details(kind, tid).await?;
let mut node = Node::default();
@@ -517,7 +523,8 @@ async fn process_source(
serde_json::from_str(&infojson).context("parsing infojson")?;
node.public.kind = Some(
- if infojson.duration.unwrap_or(0.) < 120. && infojson.aspect_ratio.unwrap_or(2.) < 1.
+ if infojson.duration.unwrap_or(0.) < 120.
+ && infojson.aspect_ratio.unwrap_or(2.) < 1.
{
NodeKind::ShortFormVideo
} else {
diff --git a/import/src/tmdb.rs b/import/src/tmdb.rs
index 3470b90..9828b8d 100644
--- a/import/src/tmdb.rs
+++ b/import/src/tmdb.rs
@@ -6,14 +6,17 @@
use anyhow::{anyhow, bail, Context};
use bincode::{Decode, Encode};
use jellybase::cache::{async_cache_file, async_cache_memory, CachePath};
-use jellycommon::chrono::{format::Parsed, Utc};
+use jellycommon::{
+ chrono::{format::Parsed, Utc},
+ TmdbKind,
+};
use log::info;
use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue},
Client, ClientBuilder,
};
use serde::Deserialize;
-use std::{fmt::Display, sync::Arc};
+use std::sync::Arc;
use tokio::io::AsyncWriteExt;
pub struct Tmdb {
@@ -212,17 +215,3 @@ pub struct TmdbProductionCompany {
pub name: String,
pub logo_path: Option<String>,
}
-
-#[derive(Debug, Clone, Copy)]
-pub enum TmdbKind {
- Tv,
- Movie,
-}
-impl Display for TmdbKind {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.write_str(match self {
- TmdbKind::Tv => "tv",
- TmdbKind::Movie => "movie",
- })
- }
-}