forked from jbotokoe/flac-to-mp3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflac-to-mp3
executable file
·33 lines (28 loc) · 1022 Bytes
/
flac-to-mp3
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
#!/usr/bin/python3
import sys
import subprocess
import os
from shlex import quote
# Assume current directory if none given
walkroot = '.' if len(sys.argv) < 2 else sys.argv[1]
for root, subfolders, files in os.walk(walkroot):
for file in files:
# Input file path
inpath = os.path.join(root, file)
# Output file path
splitpath = inpath.split(os.sep) # List of directories
splitpath.insert(1, "MP3") # Put everything in walkroot/MP3/
# Change extension to .mp3
name, extension = os.path.splitext(splitpath[-1])
splitpath[-1] = name + ".mp3"
outPath = os.path.join(*splitpath)
if file.endswith(".flac"):
try:
os.makedirs(os.path.split(outPath)[0])
except FileExistsError: # If the directory already exists, ignore error
pass
print("Converting", file)
cmdString = "ffmpeg -i {} -ab 320k -map_metadata 0 -id3v2_version 3 {}".format(quote(inpath), quote(outPath))
p = subprocess.Popen(["powershell.exe", cmdString], stdout=sys.stdout)
p.communicate()
print("Done")