-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
24 lines (22 loc) · 1012 Bytes
/
converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
from pydub import AudioSegment
mydir = os.getcwd()
for (dirpath, dirnames, filenames) in os.walk(mydir):
for filename in filenames:
if filename.endswith('.m4a'):
fpath = dirpath + '/' + filename
(fpath, file_extension) = os.path.splitext(fpath)
ext = file_extension.replace('.', '')
try:
track = AudioSegment.from_file(str(fpath+"."+ext))
wav_filename = filename.replace(ext, 'wav')
os.system(("ffmpeg -i " + filename + " -ac 2 -f wav " + wav_filename))
ext = "wav"
flac_filename = wav_filename.replace(ext, 'flac')
os.system(("ffmpeg -i " + wav_filename+ " -ac 1 " + flac_filename))
wav_path = dirpath + '/' + wav_filename
os.remove(str(filename))
os.remove(str(fpath+"wav"))
except:
print("Something went wrong with converting " + str(fpath))
exit(3)