aboutsummaryrefslogtreecommitdiff
path: root/import/src/plugins/mod.rs
blob: 8fd1e679aa56ca68faf88d1959b11118a46f271d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
    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) 2026 metamuffin <metamuffin.org>
*/
pub mod acoustid;
pub mod infojson;
pub mod media_info;
pub mod misc;
pub mod musicbrainz;
pub mod omdb;
pub mod tags;
pub mod tmdb;
pub mod trakt;
pub mod vgmdb;
pub mod wikidata;

use crate::{ApiSecrets, ImportConfig, InheritedFlags, source_rank::ImportSource};
use anyhow::Result;
use jellycommon::jellyobject::Tag;
use jellydb::RowNum;
use jellyremuxer::matroska::Segment;
use std::{collections::HashSet, path::Path, sync::Mutex};
use tokio::runtime::Handle;

pub struct PluginContext<'a> {
    pub ic: &'a ImportConfig,
    pub rt: &'a Handle,
    pub is: ImportSource<'a>,
    pub iflags: InheritedFlags,
    pub pending_nodes: &'a Mutex<HashSet<RowNum>>,
}

#[derive(Default, Clone, Copy)]
pub struct PluginInfo {
    pub name: &'static str,
    pub tag: Tag,
    pub handle_file: bool,
    pub handle_media: bool,
    pub handle_instruction: bool,
    pub handle_process: bool,
}

pub trait ImportPlugin: Send + Sync {
    fn info(&self) -> PluginInfo;
    fn file(&self, ct: &PluginContext, parent: RowNum, path: &Path) -> Result<()> {
        let _ = (ct, parent, path);
        Ok(())
    }
    fn media(&self, ct: &PluginContext, node: RowNum, path: &Path, seg: &Segment) -> Result<()> {
        let _ = (ct, node, path, seg);
        Ok(())
    }
    fn instruction(&self, ct: &PluginContext, node: RowNum, line: &str) -> Result<()> {
        let _ = (ct, node, line);
        Ok(())
    }
    fn process(&self, ct: &PluginContext, node: RowNum) -> Result<()> {
        let _ = (ct, node);
        Ok(())
    }
}

pub fn init_plugins(secrets: &ApiSecrets) -> Vec<Box<dyn ImportPlugin>> {
    let mut plugins = Vec::<Box<dyn ImportPlugin>>::new();

    plugins.push(Box::new(misc::General));
    plugins.push(Box::new(misc::Children));
    plugins.push(Box::new(misc::ImageAttachments));
    plugins.push(Box::new(misc::ImageFiles));
    plugins.push(Box::new(misc::EpisodeIndex));
    plugins.push(Box::new(tags::Tags));
    plugins.push(Box::new(media_info::MediaInfo));
    plugins.push(Box::new(infojson::Infojson));
    if let Some(api_key) = &secrets.trakt {
        plugins.push(Box::new(trakt::Trakt::new(&api_key)));
    }
    if let Some(api_key) = &secrets.tmdb {
        plugins.push(Box::new(tmdb::Tmdb::new(&api_key))); // deps: trakt
    }
    if let Some(api_key) = &secrets.omdb {
        plugins.push(Box::new(omdb::Omdb::new(&api_key))); // deps: trakt
    }
    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
    // plugins.push(Box::new(vgmdb::Vgmdb::new())); // deps: wikidata

    plugins
}