diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-30 10:47:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-30 10:47:54 +0200 |
commit | a2ef3f6ec4c830611fde1a2e935588ccbbc61c03 (patch) | |
tree | ddcc1cb501e6c7237edd491aa7136d02150d03d3 /import/src | |
parent | 212a0f23bc894faf88e159560c113f504349cc05 (diff) | |
download | jellything-a2ef3f6ec4c830611fde1a2e935588ccbbc61c03.tar jellything-a2ef3f6ec4c830611fde1a2e935588ccbbc61c03.tar.bz2 jellything-a2ef3f6ec4c830611fde1a2e935588ccbbc61c03.tar.zst |
config works
Diffstat (limited to 'import/src')
-rw-r--r-- | import/src/lib.rs | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index 2f7383a..da339d8 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -4,6 +4,16 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ #![feature(duration_constants)] + +pub mod acoustid; +pub mod infojson; +pub mod musicbrainz; +pub mod tmdb; +pub mod trakt; +pub mod vgmdb; +pub mod wikidata; +pub mod wikimedia_commons; + use acoustid::{acoustid_fingerprint, AcoustID}; use anyhow::{anyhow, bail, Context, Result}; use infojson::YVideo; @@ -11,7 +21,6 @@ use jellybase::{ assetfed::AssetInner, common::{Chapter, MediaInfo, Node, NodeID, NodeKind, Rating, SourceTrack, SourceTrackKind}, database::Database, - CONF, SECRETS, }; use jellycache::cache_file; use jellyclient::{ @@ -24,18 +33,19 @@ use log::info; use musicbrainz::MusicBrainz; use rayon::iter::{ParallelBridge, ParallelIterator}; use regex::Regex; +use serde::{Deserialize, Serialize}; use std::{ collections::{BTreeMap, HashMap}, fs::{read_to_string, File}, io::BufReader, - path::Path, + path::{Path, PathBuf}, sync::LazyLock, time::UNIX_EPOCH, }; use tmdb::Tmdb; use tokio::{ runtime::Handle, - sync::{RwLock, Semaphore}, + sync::{Mutex, RwLock, Semaphore}, task::spawn_blocking, }; use trakt::Trakt; @@ -43,14 +53,31 @@ use vgmdb::Vgmdb; use wikidata::Wikidata; use wikimedia_commons::WikimediaCommons; -pub mod acoustid; -pub mod infojson; -pub mod musicbrainz; -pub mod tmdb; -pub mod trakt; -pub mod vgmdb; -pub mod wikidata; -pub mod wikimedia_commons; +#[rustfmt::skip] +#[derive(Debug, Deserialize, Serialize, Default)] +pub struct Config { + media_path: PathBuf, + api: ApiSecrets, +} + +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct ApiSecrets { + pub acoustid: Option<String>, + pub tmdb: Option<String>, + pub tvdb: Option<String>, + pub imdb: Option<String>, + pub omdb: Option<String>, + pub fanart_tv: Option<String>, + pub trakt: Option<String>, +} + +pub static CONF_PRELOAD: Mutex<Option<Config>> = Mutex::const_new(None); +static CONF: LazyLock<Config> = LazyLock::new(|| { + CONF_PRELOAD + .blocking_lock() + .take() + .expect("cache config not preloaded. logic error") +}); pub const USER_AGENT: &'static str = concat!( "jellything/", @@ -78,6 +105,15 @@ 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()?; @@ -95,9 +131,9 @@ pub async fn import_wrap(db: Database, incremental: bool) -> Result<()> { fn import(db: &Database, incremental: bool) -> Result<()> { let apis = Apis { - trakt: SECRETS.api.trakt.as_ref().map(|key| Trakt::new(key)), - tmdb: SECRETS.api.tmdb.as_ref().map(|key| Tmdb::new(key)), - acoustid: SECRETS.api.acoustid.as_ref().map(|key| AcoustID::new(key)), + trakt: CONF.api.trakt.as_ref().map(|key| Trakt::new(key)), + tmdb: CONF.api.tmdb.as_ref().map(|key| Tmdb::new(key)), + acoustid: CONF.api.acoustid.as_ref().map(|key| AcoustID::new(key)), musicbrainz: MusicBrainz::new(), wikidata: Wikidata::new(), wikimedia_commons: WikimediaCommons::new(), |