|
@@ -112,6 +112,7 @@ def feed_queue():
|
|
|
""" Errores desconocidos """
|
|
|
log.error('[feed_queue] {}'.format(ex))
|
|
|
loop.add_timeout(time.time() + 60, feed_queue)
|
|
|
+ raise ex
|
|
|
|
|
|
def process_queue():
|
|
|
""" Try to the next item in a queue and start
|
|
@@ -166,14 +167,21 @@ def process_queue_with_threads():
|
|
|
def process_segment(item, audios=None, calibration=None):
|
|
|
""" Procesa una hora de audio """
|
|
|
|
|
|
- tolerance = calibration['tolerance']
|
|
|
station = item['station']
|
|
|
+
|
|
|
+ if not calibration:
|
|
|
+ calibration = calibrations.get(station)
|
|
|
+
|
|
|
+ tolerance = calibration['tolerance']
|
|
|
date = dateutil.parser.parse(item['date'])
|
|
|
+ segment_size = calibration['segmentSize']
|
|
|
+ audio_length = 0
|
|
|
|
|
|
- log.info('[process_segment] (th: {}, tl: {}, ft: {}) {}'.format(
|
|
|
+ log.info('[process_segment] (th: {}, tl: {}, ft: {}, ss: {}) {}'.format(
|
|
|
calibration['threshold'],
|
|
|
calibration['tolerance'],
|
|
|
calibration['fallTolerance'],
|
|
|
+ calibration['segmentSize'],
|
|
|
item,
|
|
|
))
|
|
|
|
|
@@ -188,8 +196,16 @@ def process_segment(item, audios=None, calibration=None):
|
|
|
# de acuerdo a la duración total del audio.
|
|
|
try:
|
|
|
audio = mutagen.mp3.MP3(filename)
|
|
|
- segments_needed = int(round(float(audio.info.length) / float(5)))
|
|
|
+ audio_length = audio.info.length
|
|
|
+
|
|
|
+ if segment_size == 'integer':
|
|
|
+ segment_size = int(audio_length)
|
|
|
+ elif segment_size == 'ceil':
|
|
|
+ segment_size = int(math.ceil(audio_length / 5)) * 5
|
|
|
+
|
|
|
+ segments_needed = int(round(float(audio_length) / float(segment_size)))
|
|
|
segments_needed = int(round(segments_needed * tolerance))
|
|
|
+
|
|
|
except Exception as ex:
|
|
|
log.error('[process_segment] file {} is not an mp3'.format(filename))
|
|
|
log.error(str(ex))
|
|
@@ -222,7 +238,7 @@ def process_segment(item, audios=None, calibration=None):
|
|
|
.format(short_path))
|
|
|
continue
|
|
|
|
|
|
- for match in dejavu.recognize(recognizer, path, 5,
|
|
|
+ for match in dejavu.recognize(recognizer, path, segment_size,
|
|
|
ads_filter=[md5hash]):
|
|
|
try:
|
|
|
results.append({
|
|
@@ -263,7 +279,7 @@ def process_segment(item, audios=None, calibration=None):
|
|
|
)
|
|
|
log.info('[{}] API response: {}'.format(station, response))
|
|
|
except ConnectionError as ex:
|
|
|
- log.error(str(ex))
|
|
|
+ log.error('[process_segment] {}'.format(str(ex)))
|
|
|
except UserWarning as warn:
|
|
|
log.warning(str(warn))
|
|
|
|