Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(library): 补齐 FC2 分片识别与来源连续错误计数

longmeidaoaaa1ad81e577
diff --git a/scripts/organize_library_dirs.py b/scripts/organize_library_dirs.py
index 85a083ee0..6a83c27ca 100644
--- a/scripts/organize_library_dirs.py
+++ b/scripts/organize_library_dirs.py
@@ -16,7 +16,7 @@ from pathlib import Path, PureWindowsPath
PROJECT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT / 'src'))
from peach import organize
-from peach.catalog_rules import is_jav_code, is_korean_mib_code, normalise_code_key, promo_free_key, western_release_identity, release_code_from_filename, same_release_code
+from peach.catalog_rules import is_jav_code, is_korean_mib_code, normalise_code_key, promo_free_key, western_release_identity, release_code_from_filename, same_release_code, strip_promo_markers
from peach.classification import is_structural_creator
from peach.config import DATABASE_PATH, GENERATED_DIR
from peach.entity_classification import category_predicates
@@ -114,9 +114,15 @@ def release_code(row):
studio = re.sub(r'[-_ ]', '', row['studio'] or '').upper()
if studio not in {'', 'FC2', 'FC2PPV'}:
return ''
- explicit = re.match(r'^@?FC2(?:[-_ ]?PPV)?[-_ ]*(\d{5,})(?!\d)', row['name'], re.I)
+ explicit = re.match(r'^@?FC2(?:[-_ ]?PPV)?[-_ ]*(\d{5,})(?!\d)',
+ strip_promo_markers(row['name']), re.I)
if explicit:
return normalise_code_key('FC2-' + explicit.group(1))
+ platform_parent = re.fullmatch(r'FC2(?:[-_ ]?PPV)?',
+ PureWindowsPath(row.get('path', '')).parent.name, re.I)
+ platform_part = re.match(r'^(\d{5,})(?=早期購入|本編)', row['name'])
+ if platform_parent and platform_part:
+ return normalise_code_key('FC2-' + platform_part.group(1))
short = re.match(r'^@?FC[-_ ]*(\d{5,})(?=[_.-]|$)', row['name'], re.I)
parent = re.match(r'^FC(?:2)?(?:[-_ ]?PPV)?[-_ ]*(\d{5,})(?!\d)',
PureWindowsPath(row.get('path', '')).parent.name, re.I)
@@ -725,6 +731,8 @@ def run_apply(stage, backup, limit, seconds, location=None, retry_failed=False,
error = execute_operation(db,payload,op,stage,receipt,receipt_path,deadline,retry_failed)
if isinstance(error,OfflineSource):
unavailable.add(owner)
+ if error is None:
+ provider_errors[owner] = 0
if isinstance(error,OSError) and getattr(error,'winerror',None) in {50,1}:
provider_errors[owner] += 1
if provider_errors[owner]>=3:
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index 4f248097c..81bd60d66 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -220,6 +220,40 @@ class LibraryDirectoryTests(unittest.TestCase):
self.assertEqual(db.execute('SELECT path FROM asset WHERE id=3').fetchone()[0], target + r'\FC2-PPV-1234567.srt')
+ def test_supported_moves_reset_the_source_error_circuit(self):
+ script=self.script
+ for outcomes,expected in [([False,True,False,True,False,True],6),([False,False,False,True],3)]:
+ with self.subTest(outcomes=outcomes), tempfile.TemporaryDirectory() as directory:
+ root=Path(directory).resolve()
+ ledger=fresh_ledger(root)
+ operations=[script.operation('rename',rf'A:\source{i}',rf'A:\creators\source{i}',[],'已确认归属') for i in range(len(outcomes))]
+ script.save(root/'rehome-circuit-manifest.json',dict(format=1,stage='rehome',roots={'pikpak':['A:\\']},operations=operations))
+ calls=[]
+ def backend(db,payload,op,stage,receipt,path,deadline,retry,*,calls=calls,outcomes=outcomes):
+ index=len(calls);calls.append(op['key'])
+ if outcomes[index]:
+ receipt['entries'].append(dict(key=op['key'],status='committed'))
+ return None
+ error=OSError('不支持该请求');error.winerror=50
+ receipt['failures'].append(dict(key=op['key'],source=op['source'],error=str(error)))
+ return error
+ with mock.patch.object(script,'DATABASE_PATH',ledger),mock.patch.object(script,'OUT',root), \
+ mock.patch.object(script,'execute_operation',side_effect=backend),redirect_stdout(io.StringIO()):
+ script.run_apply('rehome',root/'backup.db',100,20,location='pikpak',batch='circuit')
+ self.assertEqual(len(calls),expected)
+
+ def test_fc2_promotional_prefixes_and_platform_named_parts(self):
+ row = dict(code=None, studio=None, name='[email protected]',
+ path=r'B:\番号\FC2-PPV\[email protected]')
+ self.assertEqual(self.script.release_code(row), 'FC2-PPV-1314799')
+ for name in ('3933828早期購入.mp4', '3933828本編.mp4'):
+ part = dict(row, name=name, path=str(PureWindowsPath(r'B:\番号\FC2-PPV', name)))
+ self.assertEqual(self.script.release_code(part), 'FC2-PPV-3933828')
+ self.assertEqual(self.script.release_code(dict(part, studio='Prestige')), '')
+ self.assertEqual(self.script.release_code(dict(part, path=str(PureWindowsPath(r'B:\unknown', name)))), '')
+ self.assertEqual(self.script.release_code(dict(row, name='20250105.mp4')), '')
+ self.assertIsNone(row['code'])
+
def test_mixed_creator_files_keep_unknown_media_and_original_structure(self):
from peach.entity_classification import write_claim
script = self.script