adds a config option to limit the input seconds for fingerprinting.

This commit is contained in:
Pedro Guridi 2013-12-17 20:21:59 -03:00
parent 6a4d386736
commit f3bdc34994
2 changed files with 10 additions and 4 deletions

View file

@ -13,7 +13,7 @@ class Dejavu():
self.config = config self.config = config
# create components # create components
self.converter = Converter() self.converter = Converter(config)
self.fingerprinter = Fingerprinter(self.config) self.fingerprinter = Fingerprinter(self.config)
self.fingerprinter.db.setup() self.fingerprinter.db.setup()

View file

@ -9,8 +9,12 @@ class Converter():
WAV, WAV,
MP3] MP3]
def __init__(self): def __init__(self, config):
pass self.config = config
if self.config.has_section("input") and self.config.has_option("input", "lenght"):
self.max_input_len = int(self.config.get("input", "lenght"))
else:
self.max_input_len = None
def ensure_folder(self, extension): def ensure_folder(self, extension):
if not os.path.exists(extension): if not os.path.exists(extension):
@ -35,7 +39,6 @@ class Converter():
# start conversion # start conversion
self.ensure_folder(output_folder) self.ensure_folder(output_folder)
print "-> Now converting: %s from %s format to %s format..." % (song_name, from_format, to_format) print "-> Now converting: %s from %s format to %s format..." % (song_name, from_format, to_format)
# MP3 --> WAV # MP3 --> WAV
if from_format == Converter.MP3 and to_format == Converter.WAV: if from_format == Converter.MP3 and to_format == Converter.WAV:
@ -44,6 +47,9 @@ class Converter():
print "-> Already converted, skipping..." print "-> Already converted, skipping..."
else: else:
mp3file = AudioSegment.from_mp3(orig_path) mp3file = AudioSegment.from_mp3(orig_path)
if 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) mp3file.export(newpath, format=Converter.WAV)
# unsupported # unsupported