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

View file

@ -46,7 +46,7 @@ class Converter():
else: else:
mp3file = AudioSegment.from_mp3(orig_path) mp3file = AudioSegment.from_mp3(orig_path)
if self.max_input_len: 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 = mp3file[:self.max_input_len * 1000]
mp3file.export(newpath, format=Converter.WAV) mp3file.export(newpath, format=Converter.WAV)