diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-09-27 14:16:39 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-09-27 14:16:39 -0700 |
| commit | 89c4a9ad5258bca27fcdc34df4956d4ffca20b25 (patch) | |
| tree | 4c4a3ee0e10989e7c9dad07ade4b3a10aa472fae | |
| parent | f453c956bd4d0f3eb3726cf41a1c11e246e315d1 (diff) | |
fix: correctly sync lyric semaphore corretly into download_lrc
| -rw-r--r-- | main.py | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -8,7 +8,6 @@ from typing import Iterator from tqdm import tqdm import syncedlyrics from mutagen.flac import FLAC -import ffmpeg _lyrics_semaphore = threading.Semaphore(3) @@ -23,9 +22,23 @@ def iter_files(base: Path) -> Iterator[Path]: yield p.resolve() -def rename_file(filepath: Path, new_name: str) -> None: +def rename_file(filepath: Path, new_name: str) -> Path: target = filepath.with_name(new_name) filepath.rename(target) + lrc, new_lrc = filepath.with_suffix(".lrc"), target.with_suffix(".lrc") + if lrc.exists() and not new_lrc.exists(): + lrc.rename(new_lrc) + return target + + +def download_lrc(lrc_path: Path, title: str, artist: str) -> bool: + with _lyrics_semaphore: + lrc = syncedlyrics.search(f"{title} {artist}", providers=["Lrclib", "Megalobiz", "NetEase"]) + time.sleep(0.3) + + with open(lrc_path, "w", encoding="utf-8") as f: + f.write(lrc if lrc else "") + return bool(lrc) def get_audio_issues(path: Path) -> dict: @@ -198,12 +211,7 @@ def process_file(fp: Path, nolrc: bool) -> str: return "\n".join(lines) log(f" Fetching LRC for: {title} - {artist}") - with _lyrics_semaphore: - lrc = syncedlyrics.search(f"{title} {artist}", providers=["Lrclib", "Megalobiz", "NetEase"]) - time.sleep(0.3) - - with open(lrc_path, "w", encoding="utf-8") as f: - f.write(lrc if lrc else "") + download_lrc(lrc_path, title, artist) return "\n".join(lines) |
