Merge branch '2.3.x' into devel
This commit is contained in:
commit
3497a3730c
3 changed files with 91 additions and 6 deletions
85
python_apps/pypo/media/update/silananalyzer.py
Normal file
85
python_apps/pypo/media/update/silananalyzer.py
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
import time
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class SilanAnalyzer(Thread):
|
||||||
|
"""
|
||||||
|
The purpose of the class is to query the server for a list of files which
|
||||||
|
do not have a Silan value calculated. This class will iterate over the
|
||||||
|
list calculate the values, update the server and repeat the process until
|
||||||
|
the server reports there are no files left.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start_silan(apc, logger):
|
||||||
|
me = SilanAnalyzer(apc, logger)
|
||||||
|
me.start()
|
||||||
|
me.join()
|
||||||
|
|
||||||
|
def __init__(self, apc, logger):
|
||||||
|
Thread.__init__(self)
|
||||||
|
self.api_client = apc
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
while True:
|
||||||
|
# keep getting few rows at a time for current music_dir (stor
|
||||||
|
# or watched folder).
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
# return a list of pairs where the first value is the
|
||||||
|
# file's database row id and the second value is the
|
||||||
|
# filepath
|
||||||
|
files = self.api_client.get_files_without_silan_value()
|
||||||
|
total_files = len(files)
|
||||||
|
if total_files == 0: return
|
||||||
|
processed_data = []
|
||||||
|
for f in files:
|
||||||
|
full_path = f['fp']
|
||||||
|
# silence detect(set default queue in and out)
|
||||||
|
try:
|
||||||
|
command = ['silan', '-b', '-f', 'JSON', full_path]
|
||||||
|
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
|
||||||
|
out = proc.communicate()[0].strip('\r\n')
|
||||||
|
info = json.loads(out)
|
||||||
|
data = {}
|
||||||
|
data['cuein'] = str('{0:f}'.format(info['sound'][0][0]))
|
||||||
|
data['cueout'] = str('{0:f}'.format(info['sound'][-1][1]))
|
||||||
|
processed_data.append((f['id'], data))
|
||||||
|
total += 1
|
||||||
|
if total % 5 == 0:
|
||||||
|
self.logger.info("Total %s / %s files has been processed.." % (total, total_files))
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.error(e)
|
||||||
|
self.logger.error(traceback.format_exc())
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.api_client.update_cue_values_by_silan(processed_data)
|
||||||
|
except Exception ,e:
|
||||||
|
self.logger.error(e)
|
||||||
|
self.logger.error(traceback.format_exc())
|
||||||
|
|
||||||
|
self.logger.info("Processed: %d songs" % total)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.logger.info("Running Silan analyzer")
|
||||||
|
self.main()
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.error('Silan Analyzer Exception: %s', traceback.format_exc())
|
||||||
|
self.logger.error(e)
|
||||||
|
self.logger.info("Sleeping for 5...")
|
||||||
|
time.sleep(60 * 5)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from api_clients import api_client
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
api_client = api_client.AirtimeApiClient()
|
||||||
|
SilanAnalyzer.start_silan(api_client, logging)
|
||||||
|
|
|
@ -25,6 +25,7 @@ from listenerstat import ListenerStat
|
||||||
from pypomessagehandler import PypoMessageHandler
|
from pypomessagehandler import PypoMessageHandler
|
||||||
|
|
||||||
from media.update.replaygainupdater import ReplayGainUpdater
|
from media.update.replaygainupdater import ReplayGainUpdater
|
||||||
|
from media.update.silananalyzer import SilanAnalyzer
|
||||||
|
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
@ -126,21 +127,21 @@ def keyboardInterruptHandler(signum, frame):
|
||||||
|
|
||||||
def liquidsoap_running_test(telnet_lock, host, port, logger):
|
def liquidsoap_running_test(telnet_lock, host, port, logger):
|
||||||
logger.debug("Checking to see if Liquidsoap is running")
|
logger.debug("Checking to see if Liquidsoap is running")
|
||||||
success = True
|
|
||||||
try:
|
try:
|
||||||
telnet_lock.acquire()
|
telnet_lock.acquire()
|
||||||
tn = telnetlib.Telnet(host, port)
|
tn = telnetlib.Telnet(host, port)
|
||||||
msg = "version\n"
|
msg = "version\n"
|
||||||
tn.write(msg)
|
tn.write(msg)
|
||||||
tn.write("exit\n")
|
tn.write("exit\n")
|
||||||
logger.info("Found: %s", tn.read_all())
|
response = tn.read_all()
|
||||||
|
logger.info("Found: %s", response)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
success = False
|
return False
|
||||||
finally:
|
finally:
|
||||||
telnet_lock.release()
|
telnet_lock.release()
|
||||||
|
|
||||||
return success
|
return "Liquidsoap" in response
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -178,6 +179,7 @@ if __name__ == '__main__':
|
||||||
api_client = api_client.AirtimeApiClient()
|
api_client = api_client.AirtimeApiClient()
|
||||||
|
|
||||||
ReplayGainUpdater.start_reply_gain(api_client)
|
ReplayGainUpdater.start_reply_gain(api_client)
|
||||||
|
SilanAnalyzer.start_silan(api_client, logger)
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
while not success:
|
while not success:
|
||||||
|
|
|
@ -3,8 +3,6 @@ from api_clients import api_client as apc
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import shutil
|
|
||||||
import commands
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue