Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(library): 完善 NFO 身份识别与管理页验证

longmeidaod7205009bf0c
diff --git a/src/peach/library_nfo.py b/src/peach/library_nfo.py
index 7bc4e6e1f..d4ffbd2e9 100644
--- a/src/peach/library_nfo.py
+++ b/src/peach/library_nfo.py
@@ -1,5 +1,6 @@
"""Kodi/Jellyfin 影片及单集 NFO 的本地边车适配。"""
from pathlib import Path
+import re
import xml.etree.ElementTree as ET
from .catalog_rules import release_code_from_text
@@ -38,6 +39,10 @@ def read_nfo(path: Path):
identifiers = [node.text for node in root.findall('uniqueid')
if node.get('type', '').lower() in {'javboss', 'jav', 'javid', 'dvdid', 'num'}]
identifiers.extend([text('num'), text('sorttitle')])
+ # 通用 id 常是 IMDb/TMDb;仅明确的番号形状参与 JAV 身份识别。
+ for value in [text('id'), *(node.text or '' for node in root.findall('uniqueid'))]:
+ if re.fullmatch(r'(?:[A-Za-z]{2,12}[-_]\d{2,8}|FC2[-_](?:PPV[-_])?\d+)', value.strip(), re.I):
+ identifiers.append(value)
codes = {code for value in identifiers if (code := release_code_from_text(value or ''))}
if len(codes) > 1:
raise ValueError('NFO 包含多个不同番号')
diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.py
index 1a142043a..b080a43e0 100644
--- a/tests/test_metadata_library.py
+++ b/tests/test_metadata_library.py
@@ -56,6 +56,13 @@ class LibraryNfoTests(unittest.TestCase):
self.assertEqual(payload['series'], 'Collection')
self.assertEqual(payload['release_date'], '2024-01-02')
+ def test_jav_id_and_imdb_id_have_distinct_meanings(self):
+ path = self.root / 'movie.nfo'
+ path.write_text('<movie><id>ABW-358</id></movie>', encoding='utf-8')
+ self.assertEqual(read_nfo(path)[0]['id'], 'ABW-358')
+ path.write_text('<movie><id>tt1234567</id></movie>', encoding='utf-8')
+ self.assertEqual(read_nfo(path)[0]['id'], '')
+
def test_entity_declarations_rejected_in_utf16(self):
path = self.root / 'unsafe.nfo'
path.write_bytes('<!DOCTYPE movie [<!ENTITY x "test">]><movie><title>&x;</title></movie>'.encode('utf-16'))
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 2df2ea4a8..6afe81635 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -3608,7 +3608,9 @@ class WebUiSourceTests(unittest.TestCase):
def test_scraping_uses_shared_controls_and_source_links(self):
self.assertPageContains("'/scraping':'采集来源'")
- self.assertPageContains('data-cleanup-open="scraping"')
+ self.assertPageContains('id="libraryProcessing"')
+ processing = (Path(__file__).resolve().parents[1] / 'frontend/src/islands/library-processing.tsx').read_text(encoding='utf-8')
+ self.assertIn('href="/scraping"', processing)
self.assertPageContains('.scraping-fields .gselectfield{justify-content:space-between;padding-right:16px;')
self.assertPageContains('.scraping-fields .scraping-url{text-decoration:none;')
self.assertPageContains('.scraping-fields .scraping-url:hover{color:var(--ink);text-decoration:none}')
diff --git a/web/css/04-manage.css b/web/css/04-manage.css
index 3720b9fb9..4b40cc375 100644
--- a/web/css/04-manage.css
+++ b/web/css/04-manage.css
@@ -83,9 +83,9 @@
.taste-history-guide-content .taste-guide-skip{width:100%;height:var(--control-h);color:var(--ink)}
.fsrcoption{display:flex;align-items:center;gap:8px;justify-content:space-between}
.fsrcoption label{flex:1;min-width:0}
-.fsrcoption .geist-button{font-size:12px;white-space:nowrap}
+.fsrcoption .geist-button{font-size:var(--fs-sm);white-space:nowrap}
.library-processing ul{padding-left:20px}
-.statsdashboard .emptystate{border:0;background:transparent}
+.statsdashboard .emptystate{border:0;background:var(--ground)}
.taste-history-guide-content a{color:var(--tungsten);text-decoration:none}
.taste-history-guide-content a:hover{text-decoration:underline;text-underline-offset:3px}
.taste-history-guide-content a svg{width:14px;height:14px;margin-left:4px;vertical-align:-2px;fill:none;stroke:currentColor}