From eb8d5ee1d79318302b48ae76b5c68f1746c7dc8e Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Sun, 8 Apr 2012 20:14:13 -0400 Subject: [PATCH] CC-3470: Smarter way for pypo to recover when it should be playing something. -check file integrity before adding to library. --- .../airtimefilemonitor/mediamonitorcommon.py | 14 +++++++++++++ .../airtimefilemonitor/workerprocess.py | 20 +++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index 8a250db47..ed226f011 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -3,6 +3,7 @@ import grp import pwd import logging import stat +import subprocess from subprocess import Popen, PIPE from airtimemetadata import AirtimeMetadata @@ -289,3 +290,16 @@ class MediaMonitorCommon: self.logger.warn("File %s, has invalid metadata", pathname) return filepath + +def test_file_playability(pathname): + """ + Test if the file can be played by Liquidsoap. Return "True" if Liquidsoap + can play it, or if Liquidsoap is not found. + """ + liquidsoap_found = subprocess.call("which liquidsoap", shell=True) + if liquidsoap_found == 0: + return_code = subprocess.call("liquidsoap -c 'output.dummy(single(\"%s\"))'" % pathname, shell=True) + else: + return_code = 0 + + return (return_code == 0) diff --git a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py index 434c79907..65f751ab3 100644 --- a/python_apps/media-monitor/airtimefilemonitor/workerprocess.py +++ b/python_apps/media-monitor/airtimefilemonitor/workerprocess.py @@ -1,12 +1,20 @@ +from mediaconfig import AirtimeMediaConfig +import mediamonitorcommon + class MediaMonitorWorkerProcess: #this function is run in its own process, and continuously #checks the queue for any new file events. def process_file_events(self, queue, notifier): - while True: - event = queue.get() - notifier.logger.info("received event %s", event) - notifier.update_airtime(event) - - \ No newline at end of file + try: + event = queue.get() + if event['mode'] == AirtimeMediaConfig.MODE_CREATE: + filepath = event['filepath'] + if mediamonitorcommon.test_file_playability(filepath): + notifier.logger.info("received event %s", event) + notifier.update_airtime(event) + else: + notifier.logger.warn("Liquidsoap integrity check for file at %s failed. Not adding to media library.", filepath) + except Exception, e: + notifier.logger.error(e)