aboutsummaryrefslogtreecommitdiff
path: root/album_metadata_converter/converter.py
blob: 00d17c54f1c94406b2319f41d4851341626daff1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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())