Gamaliel Espinoza Macedo 6 anni fa
parent
commit
3de02bd767
1 ha cambiato i file con 21 aggiunte e 3 eliminazioni
  1. 21 3
      ondemand/service.py

+ 21 - 3
ondemand/service.py

@@ -116,7 +116,15 @@ def process_queue_with_threads():
             if not t:
             if not t:
                 try:
                 try:
                     item = queue.get(False)
                     item = queue.get(False)
-                    thread = Thread(target=process_segment, args=(item,))
+                    station = item['station']
+                    date = dateutil.parser.parse(item['date'])
+
+                    thread = Thread(target=process_segment,
+                        args=(item,),
+                        kwargs={
+                            'audios': [f for f in iterate_audios(date, station)]
+                        }
+                    )
                     threads[index] = thread
                     threads[index] = thread
                     thread.start()
                     thread.start()
                 except Empty:
                 except Empty:
@@ -132,7 +140,7 @@ def process_queue_with_threads():
     log.info('Finished thread processing')
     log.info('Finished thread processing')
     loop.add_callback(feed_queue)
     loop.add_callback(feed_queue)
 
 
-def process_segment(item):
+def process_segment(item, audios=None):
     """ Procesa una hora de audio """
     """ Procesa una hora de audio """
 
 
     station = item['station']
     station = item['station']
@@ -162,10 +170,19 @@ def process_segment(item):
     except Exception as ex:
     except Exception as ex:
         log.error('cannot fingerprint: {}'.format(ex))
         log.error('cannot fingerprint: {}'.format(ex))
 
 
+    """ Hay dos posibles escensarios al obtener los audios
+      a. Los audios vienen por el parámetro "audios" de la
+         función, siendo esta una lista.
+      b. Los audios se obtienen directamente de la base
+         de datos en modo de cursor.
+    """
+    audios_iterable = audios if audios \
+        else iterate_audios(date, station)
+
     # 2. Read the list of files from local database
     # 2. Read the list of files from local database
     audios_counter = 0
     audios_counter = 0
     results = []
     results = []
-    for path, name, ts in iterate_audios(date, station):
+    for path, name, ts in audios_iterable:
         log.info('file: {}'.format(path))
         log.info('file: {}'.format(path))
         audios_counter += os.path.isfile(path)
         audios_counter += os.path.isfile(path)
         for match in dejavu.recognize(recognizer, path, 5,
         for match in dejavu.recognize(recognizer, path, 5,
@@ -259,6 +276,7 @@ def iterate_audios(dt, station):
         mp3name = os.path.basename(mp3path)
         mp3name = os.path.basename(mp3path)
         yield (mp3path, mp3name, ts)
         yield (mp3path, mp3name, ts)
 
 
+
 def cloud_download(ad_key=None):
 def cloud_download(ad_key=None):
     """ Given an ad key, the file is downloaded to
     """ Given an ad key, the file is downloaded to
     the system temporal folder to be processed """
     the system temporal folder to be processed """