From 0a12e76855b21ad48884cddf772039579924d71f Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Mon, 5 May 2025 21:36:33 -0500 Subject: Add converter script for .wav to.flac, and set artist, genre, and album --- album_metadata_converter/converter.py | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 album_metadata_converter/converter.py diff --git a/album_metadata_converter/converter.py b/album_metadata_converter/converter.py new file mode 100755 index 0000000..00d17c5 --- /dev/null +++ b/album_metadata_converter/converter.py @@ -0,0 +1,56 @@ +import os +import asyncio +import subprocess + + +async def run_ffmpeg(path, album): + print(f"Parsing {path}") + cmd = ["ffmpeg", "-i", f"{path}.wav", "-af", "aformat=s32:176000", f"{path}.flac"] + p = subprocess.Popen(cmd) + print(f"Running {p.args}") + while p.poll() == None: + await asyncio.sleep(1) + + if p.returncode == 0: + # Set Artist + cmd = ["metaflac", "--set-tag=artist='The Consouls'", f"{path}.flac"] + p = subprocess.Popen(cmd) + print(f"Running {p.args}") + while p.poll() == None: + await asyncio.sleep(1) + # Set Album + cmd = ["metaflac", f"--set-tag=album=\"{album}\"", f"{path}.flac"] + p = subprocess.Popen(cmd) + print(f"Running {p.args}") + while p.poll() == None: + await asyncio.sleep(1) + + # Set Genre + cmd = ["metaflac", "--set-tag=genre='Jazz'", "--set-tag=genre='Video Game'", f"{path}.flac"] + p = subprocess.Popen(cmd) + print(f"Running {p.args}") + while p.poll() == None: + await asyncio.sleep(1) + + # Delete wav + cmd = ["rm", "-f", f"{path}.wav"] + p = subprocess.Popen(cmd) + print(f"Running {p.args}") + while p.poll() == None: + await asyncio.sleep(1) + + return p.returncode + + +async def main(): + tasks = [] + for root, dirs, files in os.walk("Music"): + for file in files: + if file.endswith(".wav"): + filename = os.path.join(root, os.path.splitext(file)[0]) + album = root.split('/')[-1] + tasks.append(asyncio.create_task(run_ffmpeg(filename, album))) + + await asyncio.gather(*tasks) + +asyncio.run(main()) -- cgit