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())