aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--main.py23
2 files changed, 21 insertions, 4 deletions
diff --git a/README.md b/README.md
index 9f95f28..2bfb0b1 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ The script does the following:
- Recursively searches through the provided directory
- Re-samples audio higher than 192Khz 24bit via ffmpeg
- Re-encodes files with block size higher than 4096 via `flac` CLI
-- Rename FLAC file to `TRACK_NAME.flac`
+- Rename FLAC file to `TRACK_NAME - ARTIST.flac`
- Resize album art to 500x500px
- Download LRC file
diff --git a/main.py b/main.py
index dffe4b3..1982a90 100644
--- a/main.py
+++ b/main.py
@@ -97,22 +97,35 @@ def resize_album_art(path: Path) -> None:
audio.save()
+def sanitize_filename(name: str) -> str:
+ illegal = r'\/:*?"<>|'
+ return "".join(c for c in name if c not in illegal).strip()
+
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument("base_dir", type=Path)
parser.add_argument("--nolrc", "-n", action="store_true", dest="nolrc")
+
args = parser.parse_args()
base = args.base_dir
+
files = [p for p in iter_files(base) if p.suffix == ".flac"]
for fp in tqdm(files, desc="Processing FLAC files", unit="file"):
print(f"\nProcessing: {fp.name}")
title, artist = get_track_info(fp)
- new_file_name = title + ".flac"
- rename_file(fp, new_file_name)
- fp = fp.with_name(new_file_name)
+ if not title:
+ print(f" Warning: TITLE tag is empty, using filename as title")
+ title = fp.stem
+ artist = "UNKNOWN ARTIST"
+
+ new_file_name = sanitize_filename(f"{title} - {artist}") + ".flac"
+ if new_file_name != fp.name:
+ rename_file(fp, new_file_name)
+ fp = fp.with_name(new_file_name)
issues = get_audio_issues(fp)
print(f" Stats: {issues['sample_rate']}Hz, {issues['bits_per_sample']}-bit, blocksize={issues['max_blocksize']}")
@@ -140,6 +153,10 @@ def main():
if args.nolrc:
continue
+ if not title or not artist:
+ print(f" Skipping LRC for {fp.name} (missing title or artist tag)")
+ continue
+
lrc_path = fp.with_suffix(".lrc")
if lrc_path.exists():
print(f" Skipping LRC for {fp.name} (already exists)")
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage