From 4b4b0335e840aa7a7377564f5b3c37b9b6a839f7 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 25 May 2026 05:33:26 +0800 Subject: [PATCH] perf: optimize episode group tag parsing --- rust/moviepilot_rust/src/metainfo.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/rust/moviepilot_rust/src/metainfo.rs b/rust/moviepilot_rust/src/metainfo.rs index a197c7fc..903ded31 100644 --- a/rust/moviepilot_rust/src/metainfo.rs +++ b/rust/moviepilot_rust/src/metainfo.rs @@ -40,8 +40,6 @@ static BRACED_METAINFO_RE: Lazy = Lazy::new(|| Regex::new(r"\{\[([^\]]+)] static BRACED_TMDBID_RE: Lazy = Lazy::new(|| Regex::new(r"tmdbid=(\d+)").unwrap()); static BRACED_DOUBANID_RE: Lazy = Lazy::new(|| Regex::new(r"doubanid=(\d+)").unwrap()); static BRACED_TYPE_RE: Lazy = Lazy::new(|| Regex::new(r"type=(\w+)").unwrap()); -static BRACED_EPISODE_GROUP_RE: Lazy = - Lazy::new(|| Regex::new(r"(?:^|;)g=([0-9a-fA-F]+)(?:;|$)").unwrap()); static BRACED_BEGIN_SEASON_RE: Lazy = Lazy::new(|| Regex::new(r"s=(\d+)").unwrap()); static BRACED_END_SEASON_RE: Lazy = Lazy::new(|| Regex::new(r"s=\d+-(\d+)").unwrap()); static BRACED_BEGIN_EPISODE_RE: Lazy = Lazy::new(|| Regex::new(r"e=(\d+)").unwrap()); @@ -667,9 +665,7 @@ fn find_explicit_metainfo(title: &str) -> ExplicitMetaInfo { .captures(&result) .and_then(|cap| cap.get(1)); let mtype = BRACED_TYPE_RE.captures(&result).and_then(|cap| cap.get(1)); - let episode_group = BRACED_EPISODE_GROUP_RE - .captures(&result) - .and_then(|cap| cap.get(1)); + let episode_group = find_explicit_episode_group(&result); let begin_season = BRACED_BEGIN_SEASON_RE .captures(&result) .and_then(|cap| cap.get(1)); @@ -695,8 +691,8 @@ fn find_explicit_metainfo(title: &str) -> ExplicitMetaInfo { _ => {} } } - if let Some(value) = episode_group { - info.episode_group = Some(value.as_str().to_string()); + if let Some(value) = episode_group.as_ref() { + info.episode_group = Some(value.clone()); } if let Some(value) = begin_season { info.begin_season = value.as_str().parse::().ok(); @@ -752,6 +748,23 @@ fn find_explicit_metainfo(title: &str) -> ExplicitMetaInfo { info } +/// 从显式标签参数中提取 g= 剧集组,避免普通标题额外走正则匹配。 +fn find_explicit_episode_group(value: &str) -> Option { + if !value.starts_with("g=") && !value.contains(";g=") { + return None; + } + + value.split(';').find_map(|part| { + part.strip_prefix("g=").and_then(|group_id| { + if !group_id.is_empty() && group_id.chars().all(|item| item.is_ascii_hexdigit()) { + Some(group_id.to_string()) + } else { + None + } + }) + }) +} + /// 计算显式季集范围总数,兼容倒序输入。 fn apply_range_total(begin: &mut Option, end: &mut Option, total: &mut Option) { match (*begin, *end) {