diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-04-25 20:34:11 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-04-25 20:34:11 -0700 |
| commit | dcd27b416075a47a6ea097e05de7f5bf4261b07e (patch) | |
| tree | 3693b73b6cdf7fb23592e3f0a54993e2d9559115 | |
| parent | 0a956ca81e839d3e56bcc2aa674444f0cf9756fe (diff) | |
use lock to track global claimed names in case of config
| -rw-r--r-- | main.py | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -12,6 +12,9 @@ import ffmpeg _lyrics_semaphore = threading.Semaphore(3) +_claimed_names: set[Path] = set() +_claimed_names_lock = threading.Lock() + def iter_files(base: Path) -> Iterator[Path]: iterator = base.rglob("*") @@ -141,15 +144,20 @@ def process_file(fp: Path, nolrc: bool) -> str: artist = "UNKNOWN ARTIST" new_stem = sanitize_filename(f"{title} - {artist}") - target = fp.with_name(new_stem + ".flac") - if target.exists() and target.resolve() != fp.resolve(): - if album: - log(f" Conflict detected, adding album name as differentiator") - new_stem = sanitize_filename(f"{title} - {artist} ({album})") - else: - log(f" Warning: filename conflict but no album tag, keeping original name") - new_stem = fp.stem - new_file_name = new_stem + ".flac" + with _claimed_names_lock: + target = fp.with_name(new_stem + ".flac") + conflict = (target.resolve() in _claimed_names) or ( + target.exists() and target.resolve() != fp.resolve() + ) + if conflict: + if album: + log(f" Conflict detected, adding album name as differentiator") + new_stem = sanitize_filename(f"{title} - {artist} ({album})") + else: + log(f" Warning: filename conflict but no album tag, keeping original name") + new_stem = fp.stem + new_file_name = new_stem + ".flac" + _claimed_names.add(fp.with_name(new_file_name).resolve()) if new_file_name != fp.name: rename_file(fp, new_file_name) fp = fp.with_name(new_file_name) |
