diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-12-11 01:20:17 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-12-11 01:20:17 +0100 |
| commit | 6e5f6d9b9c6fedb4ab80190c156595d321d33bbf (patch) | |
| tree | b6c2140e744fc3018ad08975afefad40386ebbc6 /import/src/plugins/misc.rs | |
| parent | e4f865e9da9d6660399e22a6fbeb5b84a749b07a (diff) | |
| download | jellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar jellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar.bz2 jellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar.zst | |
refactor import plugins part 3
Diffstat (limited to 'import/src/plugins/misc.rs')
| -rw-r--r-- | import/src/plugins/misc.rs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/import/src/plugins/misc.rs b/import/src/plugins/misc.rs index 6f2c18e..8d7028c 100644 --- a/import/src/plugins/misc.rs +++ b/import/src/plugins/misc.rs @@ -4,15 +4,17 @@ Copyright (C) 2025 metamuffin <metamuffin.org> */ use crate::plugins::{ImportContext, ImportPlugin, PluginInfo}; -use anyhow::{Result, bail}; +use anyhow::{Context, Result, bail}; use jellycache::{HashKey, cache_store}; use jellycommon::{Asset, NodeID, NodeKind, PictureSlot, Visibility}; use jellyremuxer::matroska::{AttachedFile, Segment}; use log::info; +use regex::Regex; use std::{ fs::{File, read_to_string}, io::Read, path::Path, + sync::LazyLock, }; pub struct ImageFiles; @@ -152,3 +154,36 @@ impl ImportPlugin for Children { Ok(()) } } + +static RE_EPISODE_FILENAME: LazyLock<Regex> = + LazyLock::new(|| Regex::new(r#"([sS](?<season>\d+))?([eE](?<episode>\d+))( (.+))?"#).unwrap()); + +pub struct EpisodeIndex; +impl ImportPlugin for EpisodeIndex { + fn info(&self) -> PluginInfo { + PluginInfo { + name: "episode-info", + handle_media: true, + ..Default::default() + } + } + fn media(&self, ct: &ImportContext, node: NodeID, path: &Path, _seg: &Segment) -> Result<()> { + let filename = path.file_name().unwrap().to_string_lossy(); + if let Some(cap) = RE_EPISODE_FILENAME.captures(&filename) { + if let Some(episode) = cap.name("episode").map(|m| m.as_str()) { + let season = cap.name("season").map(|m| m.as_str()); + let episode = episode.parse::<usize>().context("parse episode num")?; + let season = season + .unwrap_or("1") + .parse::<usize>() + .context("parse season num")?; + + ct.db.update_node_init(node, |node| { + node.index = Some(episode); + Ok(()) + })?; + } + } + Ok(()) + } +} |