fixes #15, adds handling for KeyboardInterrupt. added some handling for #4, now skips file not sampled at 44100hz

This commit is contained in:
Pedro Guridi 2013-12-18 00:38:27 -03:00
parent 907637a633
commit 880af4a5b9
2 changed files with 17 additions and 7 deletions

View file

@ -58,8 +58,14 @@ class Dejavu():
processes.append(p)
# wait for all processes to complete
for p in processes:
p.join()
try:
for p in processes:
p.join()
except KeyboardInterrupt:
print "-> Exiting.."
for worker in processes:
worker.terminate()
worker.join()
# delete orphans
# print "Done fingerprinting. Deleting orphaned fingerprints..."
@ -77,11 +83,16 @@ class Dejavu():
# convert to WAV
wavout_path = self.converter.convert(filename, extension, Converter.WAV, output)
# for each channel perform FFT analysis and fingerprinting
try:
channels = self.extract_channels(wavout_path)
except AssertionError, e:
print "-> File not supported, skipping."
continue
# insert song name into database
song_id = sql_connection.insert_song(filename)
# for each channel perform FFT analysis and fingerprinting
channels = self.extract_channels(wavout_path)
for c in range(len(channels)):
channel = channels[c]
print "-> Fingerprinting channel %d of song %s..." % (c+1, filename)
@ -89,7 +100,6 @@ class Dejavu():
# remove wav file if not required
if not keep_wav:
print "removing ", wavout_path
os.unlink(wavout_path)
# only after done fingerprinting do confirm

View file

@ -24,7 +24,7 @@ class Converter():
filepaths = []
extensions = [e.replace(".", "") for e in extensions if e.replace(".", "") in Converter.FORMATS]
print "Supported formats: %s" % extensions
for dirpath, dirnames, files in os.walk(path) :
for dirpath, dirnames, files in os.walk(path):
for extension in extensions:
for f in fnmatch.filter(files, "*.%s" % extension):
p = os.path.join(dirpath, f)
@ -46,7 +46,7 @@ class Converter():
else:
mp3file = AudioSegment.from_mp3(orig_path)
if self.max_input_len:
print "Reading input seconds: ", self.max_input_len
print "-> Reading input seconds: ", self.max_input_len
mp3file = mp3file[:self.max_input_len * 1000]
mp3file.export(newpath, format=Converter.WAV)