diff options
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | cache/src/backends/dummy.rs | 18 | ||||
| -rw-r--r-- | cache/src/backends/mod.rs | 4 | ||||
| -rw-r--r-- | cache/src/lib.rs | 8 | ||||
| -rw-r--r-- | import/src/lib.rs | 14 | ||||
| -rw-r--r-- | import/src/plugins/mod.rs | 14 | ||||
| -rw-r--r-- | import/src/plugins/trakt.rs | 4 | ||||
| -rw-r--r-- | logic/src/home.rs | 5 | ||||
| -rw-r--r-- | tool/Cargo.toml | 1 | ||||
| -rw-r--r-- | tool/src/add.rs | 8 | ||||
| -rw-r--r-- | ui/src/props.rs | 2 |
11 files changed, 49 insertions, 30 deletions
@@ -2083,6 +2083,7 @@ dependencies = [ "dialoguer", "env_logger", "indicatif", + "jellycache", "jellycommon", "jellyimport", "log", diff --git a/cache/src/backends/dummy.rs b/cache/src/backends/dummy.rs new file mode 100644 index 0000000..5ebc2e3 --- /dev/null +++ b/cache/src/backends/dummy.rs @@ -0,0 +1,18 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin <metamuffin.org> +*/ + +use crate::backends::CacheStorage; +use anyhow::Result; + +pub struct Dummy; +impl CacheStorage for Dummy { + fn store(&self, _key: String, _value: &[u8]) -> Result<()> { + Ok(()) + } + fn read(&self, _key: &str) -> Result<Option<Vec<u8>>> { + Ok(None) // sorry forgot + } +} diff --git a/cache/src/backends/mod.rs b/cache/src/backends/mod.rs index 5872255..506eace 100644 --- a/cache/src/backends/mod.rs +++ b/cache/src/backends/mod.rs @@ -3,12 +3,13 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ +pub mod dummy; pub mod filesystem; pub mod rocksdb; use crate::{ CONF, - backends::{filesystem::Filesystem, rocksdb::Rocksdb}, + backends::{dummy::Dummy, filesystem::Filesystem, rocksdb::Rocksdb}, }; use anyhow::{Result, bail}; @@ -21,6 +22,7 @@ pub fn init_backend() -> Result<Box<dyn CacheStorage>> { Ok(match CONF.driver.as_str() { "filesystem" => Box::new(Filesystem::new(&CONF)), "rocksdb" => Box::new(Rocksdb::new(&CONF)?), + "dummy" => Box::new(Dummy), _ => bail!("unknown driver"), }) } diff --git a/cache/src/lib.rs b/cache/src/lib.rs index d68266f..c939a9c 100644 --- a/cache/src/lib.rs +++ b/cache/src/lib.rs @@ -55,6 +55,14 @@ pub fn init_cache() -> Result<()> { .unwrap(); Ok(()) } +pub fn init_cache_dummy() -> Result<()> { + *CONF_PRELOAD.lock().unwrap() = Some(Config { + driver: "dummy".to_string(), + path: PathBuf::default(), + max_in_memory_cache_size: 0, + }); + init_cache() +} fn bucket(key: &str) -> usize { let mut h = DefaultHasher::new(); diff --git a/import/src/lib.rs b/import/src/lib.rs index 8e4c702..44f87f7 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -9,10 +9,7 @@ pub mod plugins; pub mod reporting; use crate::{ - plugins::{ - ImportContext, ImportPlugin, infojson::is_info_json, init_plugins, misc::is_cover, - trakt::Trakt, - }, + plugins::{ImportContext, ImportPlugin, infojson::is_info_json, init_plugins, misc::is_cover}, reporting::IMPORT_PROGRESS, }; use anyhow::{Context, Result, anyhow}; @@ -79,15 +76,6 @@ pub fn is_importing() -> bool { IMPORT_SEM.available_permits() == 0 } -pub fn get_trakt() -> Result<Trakt> { - Ok(Trakt::new( - CONF.api - .trakt - .as_ref() - .ok_or(anyhow!("no trakt api key configured"))?, - )) -} - pub async fn import_wrap(db: Database, incremental: bool) -> Result<()> { let _sem = IMPORT_SEM.try_acquire().context("already importing")?; diff --git a/import/src/plugins/mod.rs b/import/src/plugins/mod.rs index 20c3529..5a5334e 100644 --- a/import/src/plugins/mod.rs +++ b/import/src/plugins/mod.rs @@ -70,16 +70,14 @@ pub fn init_plugins(secrets: &ApiSecrets) -> Vec<Box<dyn ImportPlugin>> { plugins.push(Box::new(tags::Tags)); plugins.push(Box::new(media_info::MediaInfo)); plugins.push(Box::new(infojson::Infojson)); - - if let Some(s) = &secrets.trakt { - plugins.push(Box::new(trakt::Trakt::new(&s))); + if let Some(api_key) = &secrets.trakt { + plugins.push(Box::new(trakt::Trakt::new(&api_key))); } - if let Some(s) = &secrets.tmdb { - plugins.push(Box::new(tmdb::Tmdb::new(&s))); // deps: trakt + if let Some(api_key) = &secrets.tmdb { + plugins.push(Box::new(tmdb::Tmdb::new(&api_key))); // deps: trakt } - - if let Some(s) = &secrets.acoustid { - plugins.push(Box::new(acoustid::AcoustID::new(&s))); + if let Some(api_key) = &secrets.acoustid { + plugins.push(Box::new(acoustid::AcoustID::new(&api_key))); } plugins.push(Box::new(musicbrainz::MusicBrainz::new())); // deps: acoustid plugins.push(Box::new(wikidata::Wikidata::new())); // deps: musicbrainz diff --git a/import/src/plugins/trakt.rs b/import/src/plugins/trakt.rs index 1268e56..8dc5bdc 100644 --- a/import/src/plugins/trakt.rs +++ b/import/src/plugins/trakt.rs @@ -314,11 +314,11 @@ pub struct TraktIds { impl Display for TraktSearchResult { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!( - "{} ({}) \x1b[2m{} [{:?}]\x1b[0m", + "{} ({}) \x1b[2m{} {}\x1b[0m", self.inner.inner().title, self.inner.inner().year.unwrap_or(0), self.r#type, - self.inner.inner().ids + self.inner.inner().ids.trakt.unwrap_or_default() )) } } diff --git a/logic/src/home.rs b/logic/src/home.rs index db8a397..7e832fe 100644 --- a/logic/src/home.rs +++ b/logic/src/home.rs @@ -77,7 +77,7 @@ pub fn home(session: &Session) -> Result<ApiHomeResponse> { items.sort_by_key(|(n, _)| { n.ratings - .get(&RatingType::Tmdb) + .get(&RatingType::Trakt) .map(|x| (*x * -1000.) as i32) .unwrap_or(0) }); @@ -86,8 +86,9 @@ pub fn home(session: &Session) -> Result<ApiHomeResponse> { "home.bin.max_rating".to_string(), items .iter() + .filter(|(n, _)| n.ratings.contains_key(&RatingType::Trakt)) + .filter(|(n, _)| matches!(n.kind, NodeKind::Movie | NodeKind::Show)) .take(16) - .filter(|(n, _)| n.ratings.contains_key(&RatingType::Tmdb)) .cloned() .collect(), )); diff --git a/tool/Cargo.toml b/tool/Cargo.toml index f8fb0e6..546fdc4 100644 --- a/tool/Cargo.toml +++ b/tool/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] jellycommon = { path = "../common" } jellyimport = { path = "../import" } +jellycache = { path = "../cache" } log = { workspace = true } env_logger = "0.11.8" diff --git a/tool/src/add.rs b/tool/src/add.rs index 40b8ce4..8152aad 100644 --- a/tool/src/add.rs +++ b/tool/src/add.rs @@ -5,9 +5,11 @@ */ use crate::cli::Action; use dialoguer::{Confirm, FuzzySelect, Input, theme::ColorfulTheme}; -use jellyimport::{get_trakt, plugins::trakt::TraktKind}; +use jellycache::init_cache_dummy; +use jellyimport::plugins::trakt::{Trakt, TraktKind}; use log::warn; use std::{ + env::var, fmt::Display, fs::{OpenOptions, rename}, io::Write, @@ -16,6 +18,7 @@ use std::{ use tokio::runtime::Handle; pub fn add(action: Action, rt: &Handle) -> anyhow::Result<()> { + init_cache_dummy()?; match action { Action::Add { media } => { let theme = ColorfulTheme::default(); @@ -33,8 +36,7 @@ pub fn add(action: Action, rt: &Handle) -> anyhow::Result<()> { .interact_text() .unwrap(); - let trakt = get_trakt()?; - + let trakt = Trakt::new(&var("TRAKT_API_KEY").unwrap()); let results = trakt.search(search_kinds, &name, rt)?; if results.is_empty() { diff --git a/ui/src/props.rs b/ui/src/props.rs index 9d1f41a..ba9ff22 100644 --- a/ui/src/props.rs +++ b/ui/src/props.rs @@ -45,7 +45,7 @@ markup::define! { RatingType::Metacritic if *full => {p{ "Metacritic Score: " @value }} RatingType::Imdb => {p.rating{ "IMDb " @value }} RatingType::Tmdb => {p.rating{ "TMDB " @format!("{:.01}", value) }} - RatingType::Trakt if *full => {p.rating{ "Trakt " @format!("{:.01}", value) }} + RatingType::Trakt => {p.rating{ "Trakt " @format!("{:.01}", value) }} _ => {} } } |