diff --git a/python_apps/pytag-fs/MediaMonitor.cfg b/python_apps/pytag-fs/MediaMonitor.cfg new file mode 100644 index 000000000..e4610b720 --- /dev/null +++ b/python_apps/pytag-fs/MediaMonitor.cfg @@ -0,0 +1,29 @@ +api_client = "airtime" + +# Hostname +base_url = 'localhost' +base_port = 80 + +# where the binary files live +bin_dir = '/usr/lib/airtime/media-monitor' + +# base path to store recordered shows at +base_recorded_files = '/var/tmp/airtime/show-recorder/' + +# where the logging files live +log_dir = '/var/log/airtime/show-recorder' + +# Value needed to access the API +api_key = 'AAA' + +# Path to the base of the API +api_base = 'api' + +# URL to get the version number of the server API +version_url = 'version/api_key/%%api_key%%' + +# URL to get the schedule of shows set to record +show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%' + +# URL to upload the recorded show's file to Airtime +upload_file_url = 'upload-recorded/format/json/api_key/%%api_key%%' diff --git a/python_apps/pytag-fs/MediaMonitor.py b/python_apps/pytag-fs/MediaMonitor.py new file mode 100644 index 000000000..2bdf148aa --- /dev/null +++ b/python_apps/pytag-fs/MediaMonitor.py @@ -0,0 +1,52 @@ +import os +import pyinotify +from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent + +# configure logging +try: + logging.config.fileConfig("logging.cfg") +except Exception, e: + print 'Error configuring logging: ', e + sys.exit() + +# loading config file +try: + config = ConfigObj('/etc/airtime/recorder.cfg') +except Exception, e: + print 'Error loading config file: ', e + sys.exit() + +# watched events +mask = pyinotify.ALL_EVENTS + +wm = WatchManager() +wdd = wm.add_watch('/srv/airtime/stor', mask, rec=True) + +class PTmp(ProcessEvent): + def process_IN_CREATE(self, event): + if event.dir : + global wm + wdd = wm.add_watch(event.pathname, mask, rec=True) + #print wdd.keys() + + print "%s: %s" % (event.maskname, os.path.join(event.path, event.name)) + + def process_IN_MODIFY(self, event): + if not event.dir : + print event.path + + print "%s: %s" % (event.maskname, os.path.join(event.path, event.name)) + + def process_default(self, event): + print "%s: %s" % (event.maskname, os.path.join(event.path, event.name)) + +if __name__ == '__main__': + + try: + notifier = Notifier(wm, PTmp(), read_freq=2, timeout=1) + notifier.coalesce_events() + notifier.loop() + except KeyboardInterrupt: + notifier.stop() + + diff --git a/python_apps/pytag-fs/logging.cfg b/python_apps/pytag-fs/logging.cfg new file mode 100644 index 000000000..251fce8d7 --- /dev/null +++ b/python_apps/pytag-fs/logging.cfg @@ -0,0 +1,22 @@ +[loggers] +keys=root + +[handlers] +keys=consoleHandler + +[formatters] +keys=simpleFormatter + +[logger_root] +level=DEBUG +handlers=consoleHandler + +[handler_consoleHandler] +class=StreamHandler +level=DEBUG +formatter=simpleFormatter +args=(sys.stdout,) + +[formatter_simpleFormatter] +format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s +datefmt=