-
-
Save BrownCoatJustice/ea17480b5f8c7324d3380de02f5c6ae5 to your computer and use it in GitHub Desktop.
Script to split delimited Vorbis tags to separate fields
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
| #!/usr/bin/env python3 | |
| # kebab case for life | |
| # thanks to Aiden Marsh of Stack Overflow (cant find their username anymore) for helping me convert this into a usable local bin script -- just needed that shebang and chmod +x | |
| from pathlib import Path | |
| from mutagen.flac import FLAC | |
| TAGS = ("artist", "composer", "lyricist") # todo: add more later, but not sure where this is going to be useful. | |
| DRY_RUN = False | |
| """ | |
| LOOK THE FUCK OVER HERE | |
| THIS IS A DOC STRING or smth i wasnt paying attention to class when they explained this | |
| CHANGE THE FUCKING DRY_RUN TAG TO FALSE WHEN YOU actually WANT TO CHANGE THE TAGS | |
| UNDERSTOOD?????? | |
| DONT COMPLAIN oH tHiS sCrIpT iS Ai GeNeRaTeD sLoP | |
| I HATE YOU | |
| """ | |
| DELIMITER = ";" # so for the fkers who use something other than semicolons... wtf is wrong with yall | |
| def split_values(values): | |
| out = [] | |
| seen = set() | |
| for value in values: | |
| for part in value.split(DELIMITER): | |
| part = part.strip() | |
| if part and part not in seen: | |
| seen.add(part) | |
| out.append(part) | |
| return out | |
| def process_file(path): | |
| audio = FLAC(path) | |
| changed = False | |
| for tag in TAGS: | |
| if tag not in audio: | |
| continue | |
| old = audio[tag] | |
| new = split_values(old) | |
| # skip if already correct | |
| if old == new: | |
| continue | |
| print(f"{path}: {tag}") | |
| print(f" {old!r}") | |
| print(f" -> {new!r}") | |
| audio[tag] = new | |
| changed = True | |
| if changed: | |
| if not DRY_RUN: | |
| audio.save() | |
| print(" " + "Saved.") | |
| else: | |
| print(" " + "(dry run: not saved)") | |
| if __name__ == "__main__": # this took so long to figure out, thank god for gemini... and stack overflow i guess; and it works on Windows as well! | |
| for file in Path(".").rglob("*.flac"): | |
| try: | |
| process_file(file) | |
| except Exception as e: | |
| print(f"{file}: ERROR: {e}") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sorry i didnt mean any of that... i love you
take care of yourself
call that one person you've been meaning to call
go outside and take in that fresh soup of NOx, SO2, and diesel soot.