Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(metadata): 无番号视频用同目录图片作本地海报

longmeidaoce3322fe8e3f
diff --git a/src/peach/library_processing.py b/src/peach/library_processing.py
index fddb4ffc4..e53f9893a 100644
--- a/src/peach/library_processing.py
+++ b/src/peach/library_processing.py
@@ -308,6 +308,14 @@ def process_library(config, db_path, candidate_root, cover_root, *, location='co
issue(row['id'], str(error), action='reading_local')
continue
if not code and not payload:
+ # 番号认不出不影响本地封面:正片旁边的同名 PNG/JPG 就是它的海报,
+ # 落在 `{id}_4.jpg` 后卡片和详情直接用这一张,不再回退九宫格。
+ try:
+ state['covers'] += int(_local_poster(
+ video, f"{row['id']}_4",
+ config.directory('generated') / 'posters'))
+ except (OSError, ValueError):
+ issue(row['id'], '本地封面无法读取', action='reading_local', retryable=True)
issue(row['id'], '未识别到番号,请在详情中补充资料', action='reading_local')
continue
if code:
diff --git a/tests/test_metadata_library.py b/tests/test_metadata_library.py
index b851c51e5..3ca472120 100644
--- a/tests/test_metadata_library.py
+++ b/tests/test_metadata_library.py
@@ -115,6 +115,26 @@ class LibraryNfoTests(unittest.TestCase):
self.assertEqual(q_library_processing(contract, {})['job_id'], 'one')
worker.assert_not_called()
+ @unittest.skipUnless(os.name == 'nt', '真实声明根使用 Windows 盘符')
+ def test_no_code_video_pairs_with_its_sibling_image_without_nfo(self):
+ """无番号、无 NFO 的视频也拿同目录图片当海报,落在 `{id}_4.jpg`。"""
+ from PIL import Image
+ media = self.root / 'media'
+ media.mkdir()
+ (media / '梓怡-背著老公.mp4').write_bytes(b'video')
+ Image.new('RGB', (24, 36), (180, 120, 90)).save(media / '梓怡-背著老公.png')
+ db = fresh_ledger(self.root)
+ config = PeachConfig(self.root, self.root / 'config.toml', present=True,
+ locations={'local': (str(media),)})
+ result = process_library(config, db, self.root / 'generated',
+ self.root / 'covers', provider_factory=Mock())
+ with closing(sqlite3.connect(db)) as connection:
+ asset_id = connection.execute(
+ "SELECT id FROM asset WHERE name='梓怡-背著老公.mp4'").fetchone()[0]
+ self.assertEqual(result['covers'], 1)
+ self.assertTrue(
+ (self.root / 'generated' / 'posters' / f'{asset_id}_4.jpg').is_file())
+
def test_reader_cannot_scan_or_create_candidates(self):
from peach.settings_file import ReplicationSettings
config = PeachConfig(self.root, self.root / 'config.toml', replication=ReplicationSettings(enabled=True))