Created
June 27, 2025 18:43
-
-
Save Vocaned/26e815398d3da190914d91ddf0683a06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
from mutagen.flac import FLAC | |
from pathlib import Path | |
import sys | |
REPLACEMENTS = { | |
'‘': "'", | |
'’': "'", | |
'“': '"', | |
'”': '"', | |
'…': '...', | |
'–': '-', | |
'—': '-', | |
'\xa0': ' ',# non-breaking space | |
} | |
rename_queue = [] | |
tag_edit_queue = [] | |
for p in Path('..').glob('**/*'): | |
if not p.is_file() or p.suffix != '.flac': | |
continue | |
curname = p.name | |
newname = curname | |
for orig, new in REPLACEMENTS.items(): | |
newname = newname.replace(orig, new) | |
if curname != newname: | |
print('Renaming file:') | |
print('<', curname) | |
print('>', newname) | |
print() | |
rename_queue.append((p, p.with_name(newname))) | |
flac = FLAC(p) | |
updated = False | |
new_tags = {} | |
for tag in ['artist', 'title', 'album']: | |
if tag in flac: | |
orig_val = flac[tag][0] | |
new_val = orig_val | |
for orig, new in REPLACEMENTS.items(): | |
new_val = new_val.replace(orig, new) | |
if orig_val != new_val: | |
print(f"Updating '{tag}' in {p.name}:") | |
print('<', orig_val) | |
print('>', new_val) | |
print() | |
new_tags[tag] = new_val | |
updated = True | |
if updated: | |
tag_edit_queue.append((p, new_tags)) | |
if not rename_queue and not tag_edit_queue: | |
print('Nothing to do.') | |
sys.exit(0) | |
response = input("Continue? (y/N): ").strip().lower() | |
if response != 'y': | |
print('Aborted.') | |
sys.exit(1) | |
for path, new_tags in tag_edit_queue: | |
flac = FLAC(path) | |
for tag, val in new_tags.items(): | |
flac[tag] = val | |
flac.save() | |
print(f"Updated tags in: {path.name}") | |
for old_path, new_path in rename_queue: | |
old_path.rename(new_path) | |
print(f"Renamed: {old_path.name} -> {new_path.name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment