diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index e7a450219..d98688ff5 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -161,6 +161,8 @@ class Metadata(Loggable): # Forcing the unicode through try : fpath = fpath.decode("utf-8") except : pass + if not mmp.file_playable(fpath): + raise BadSongFile(fpath) try : full_mutagen = mutagen.File(fpath, easy=True) except Exception : raise BadSongFile(fpath) self.path = fpath diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index ac9fd127b..005178157 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import copy +import subprocess import os import shutil import re @@ -449,6 +450,21 @@ def owner_id(original_path): except Exception: raise return owner_id +def file_playable(pathname): + + #when there is an single apostrophe inside of a string quoted by + #apostrophes, we can only escape it by replace that apostrophe with '\''. + #This breaks the string into two, and inserts an escaped single quote in + #between them. We run the command as pypo because otherwise the target file + #is opened with write permissions, and this causes an inotify ON_CLOSE_WRITE + #event to be fired :/ + + command = ("sudo -u pypo airtime-liquidsoap -c 'output.dummy" + \ + "(audio_to_stereo(single(\"%s\")))' > /dev/null 2>&1") % \ + pathname.replace("'", "'\\''") + return_code = subprocess.call(command, shell=True) + return (return_code == 0) + if __name__ == '__main__': import doctest doctest.testmod()