diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py index fd34811ad..15aff6745 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemediamonitorbootstrap.py @@ -109,9 +109,9 @@ class AirtimeMediaMonitorBootstrap(): if os.path.exists(self.mmc.timestamp_file): """find files that have been modified since the last time media-monitor process started.""" time_diff_sec = time.time() - os.path.getmtime(self.mmc.timestamp_file) - command = "find '%s' -iname '*.ogg' -o -iname '*.mp3' -type f -readable -mmin -%d" % (dir, time_diff_sec/60+1) + command = self.mmc.find_command(directory=dir, extra_arguments=("-type f -readable -mmin -%d" % (time_diff_sec/60+1))) else: - command = "find '%s' -iname '*.ogg' -o -iname '*.mp3' -type f -readable" % dir + command = self.mmc.find_command(directory=dir, extra_arguments="-type f -readable -mmin -%d") self.logger.debug(command) stdout = self.mmc.exec_command(command) diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index 79e2fa9cd..b35dbe7a7 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -24,6 +24,14 @@ class MediaMonitorCommon: self.md_manager = AirtimeMetadata() self.wm = wm + + def find_command(self, directory, extra_arguments=""): + """ Builds a find command that respects supported_file_formats list + Note: Use single quotes to quote arguments """ + ext_globs = [ "-iname '*.%s'" % ext for ext in self.supported_file_formats ] + find_glob = ' -o '.join(ext_globs) + return "find '%s' %s %s" % (directory, find_glob, extra_arguments) + def is_parent_directory(self, filepath, directory): filepath = os.path.normpath(filepath) directory = os.path.normpath(directory) @@ -280,7 +288,7 @@ class MediaMonitorCommon: return stdout def scan_dir_for_new_files(self, dir): - command = 'find "%s" -iname "*.ogg" -o -iname "*.mp3" -type f -readable' % dir.replace('"', '\\"') + command = self.find_command(directory=dir, extra_arguments="-type f -readable") self.logger.debug(command) stdout = self.exec_command(command)