scripts/flac2mp3_V0
2020-06-14 21:48:19 -04:00

44 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/bash python3
import os
from shutil import copyfile
import pathlib
from multiprocessing import Pool, Value
SRC = "/mnt/merger/audio/music"
DST = "/mnt/merger/audio/music_[V0]"
to_convert = []
counter = Value("d")
def convert(path):
global counter
destination = DST + path[len(SRC):]
destination = os.path.splitext(destination)[0] + ".mp3"
pathlib.Path(os.path.split(destination)[0]).mkdir(parents=True, exist_ok=True)
if not os.path.exists(destination):
os.system("ffmpeg -i \"" + path + "\" -c:a libmp3lame -q:a 0 -y \"" + destination + "\" -loglevel panic")
print("[%.2f%%] - " % (counter.value / len(to_convert) * 100) + destination)
counter.value += 1
def recursive_convert(path):
for item in os.listdir(path):
full_path = path + os.sep + item
if os.path.isdir(full_path):
recursive_convert(full_path)
else:
if os.path.splitext(item)[1] in [".mp3", ".flac", ".m4a", ".ape"]:
to_convert.append(full_path)
recursive_convert(SRC)
print("Converting " + str(len(to_convert)) + " files...")
pool = Pool(processes=4)
pool.map(convert, to_convert)