-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconvert.py
44 lines (36 loc) · 1.12 KB
/
convert.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# RUN THIS PROGRAM TO:
# 1.convert mp3 to wav
# 2.extract mp3 metadata
from pydub import AudioSegment
import eyed3
import os
import logging
log = logging.getLogger(__name__)
def convert(infile):
"""convert mp3 to wav
Param: infile(str): a mp3 file, like "music.mp3"
Export: outfile: a wav file with the same name, like "music.wav"
"""
try:
# format outfile name
filename = os.path.basename(infile)
outfile = "./music/wav/" + filename[:-3] + "wav"
# export wav
sound = AudioSegment.from_mp3(infile)
sound.export(outfile, format="wav")
except OSError:
log.Error("expected an mp3 file in the directory")
def meta(infile):
""" get metadata (title,artist,etc) from mp3 """
try:
file = eyed3.load(infile)
title = file.tag.title
artist = file.tag.artist
album = file.tag.album
# create a tuple to store metadata
tup = (title, artist, album)
return tup
except OSError:
log.Error("expected an mp3 file in the directory")
except AttributeError:
log.Error('expected an mp3 file')