Implement duplicate resolution strategy by quality and enhance related documentation
- Updated `duplicate_resolve.py` to introduce a new strategy for keeping files based on quality, considering resolution, source, codec, and size. - Enhanced `planner.py` to utilize the new quality-based strategy during plan generation, updating quarantine reasons accordingly. - Modified `README.md` to document the new `plan.duplicate_keep` options, including `by_quality`, and provided detailed descriptions of each strategy. - Added unit tests in `test_duplicate_resolve.py` to validate the new quality-based resolution logic. - Updated `analysis.json` and `plan.json` with new timestamps and IDs to reflect recent changes. These updates improve the Video Library Manager's ability to handle duplicate files more effectively, ensuring users retain the highest quality versions.
This commit is contained in:
+25
-10
@@ -22,6 +22,7 @@ from vlm.models import (
|
||||
)
|
||||
|
||||
QUARANTINE_REASON_DUPLICATE = "重复项(已按外部评分保留一条)"
|
||||
QUARANTINE_REASON_DUPLICATE_BY_QUALITY = "重复项(已按画质保留最优)"
|
||||
|
||||
|
||||
def generate_plan(
|
||||
@@ -50,26 +51,40 @@ def generate_plan(
|
||||
for dup in analysis_data.get("duplicates", []):
|
||||
paths = dup.get("files", [])
|
||||
indices = [path_to_index[p] for p in paths if p in path_to_index]
|
||||
items = [
|
||||
(identities[i][0].path, identities[i][1])
|
||||
for i in indices
|
||||
if identities[i][1] is not None
|
||||
and isinstance(identities[i][1], (MovieIdentity, SeriesIdentity))
|
||||
]
|
||||
path_to_qc = {qc.get("path"): qc for qc in dup.get("quality_comparison", [])}
|
||||
items = []
|
||||
valid_indices = []
|
||||
for i in indices:
|
||||
identity = identities[i][1]
|
||||
if identity is not None and isinstance(
|
||||
identity, (MovieIdentity, SeriesIdentity)
|
||||
):
|
||||
items.append((identities[i][0].path, identity))
|
||||
valid_indices.append(i)
|
||||
if not items:
|
||||
continue
|
||||
keep_idx = choose_keep_index(items, config.duplicate_keep)
|
||||
quality_list = [
|
||||
path_to_qc.get(str(p), {}) for p, _ in items
|
||||
]
|
||||
keep_idx = choose_keep_index(
|
||||
items, config.duplicate_keep, quality_comparison=quality_list
|
||||
)
|
||||
if keep_idx is None:
|
||||
continue
|
||||
keep_identity_index = indices[keep_idx]
|
||||
quarantine_indices = set(indices) - {keep_identity_index}
|
||||
keep_identity_index = valid_indices[keep_idx]
|
||||
quarantine_indices = set(valid_indices) - {keep_identity_index}
|
||||
reason = (
|
||||
QUARANTINE_REASON_DUPLICATE_BY_QUALITY
|
||||
if config.duplicate_keep == "by_quality"
|
||||
else QUARANTINE_REASON_DUPLICATE
|
||||
)
|
||||
for i in quarantine_indices:
|
||||
vf = identities[i][0]
|
||||
operations[i] = FileOperation(
|
||||
operation_type="quarantine",
|
||||
source_path=vf.path,
|
||||
destination_path=None,
|
||||
reason=QUARANTINE_REASON_DUPLICATE,
|
||||
reason=reason,
|
||||
has_conflict=False,
|
||||
conflict_reason=None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user