CC-3470: Smarter way for pypo to recover when it should be playing something.

-check file integrity before adding to library.
This commit is contained in:
Martin Konecny 2012-04-08 20:14:13 -04:00
parent b9e840552b
commit eb8d5ee1d7
2 changed files with 28 additions and 6 deletions

View File

@ -3,6 +3,7 @@ import grp
import pwd import pwd
import logging import logging
import stat import stat
import subprocess
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from airtimemetadata import AirtimeMetadata from airtimemetadata import AirtimeMetadata
@ -289,3 +290,16 @@ class MediaMonitorCommon:
self.logger.warn("File %s, has invalid metadata", pathname) self.logger.warn("File %s, has invalid metadata", pathname)
return filepath 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)

View File

@ -1,12 +1,20 @@
from mediaconfig import AirtimeMediaConfig
import mediamonitorcommon
class MediaMonitorWorkerProcess: class MediaMonitorWorkerProcess:
#this function is run in its own process, and continuously #this function is run in its own process, and continuously
#checks the queue for any new file events. #checks the queue for any new file events.
def process_file_events(self, queue, notifier): def process_file_events(self, queue, notifier):
while True: while True:
event = queue.get() try:
notifier.logger.info("received event %s", event) event = queue.get()
notifier.update_airtime(event) 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)