34 lines
968 B
Python
34 lines
968 B
Python
import pyinotify
|
|
import os
|
|
|
|
class EventHandler(pyinotify.ProcessEvent):
|
|
def process_IN_CREATE(self, event):
|
|
print(f'New file: {event.pathname}')
|
|
return event.pathname
|
|
|
|
def apply_filter(self, audio_file):
|
|
# TODO: return True if audio file is valid, based on name, extension, and other criteria
|
|
if os.path.isdir(audio_file):
|
|
return False
|
|
return True
|
|
|
|
class Picker:
|
|
|
|
directory = None
|
|
dispatcher = None
|
|
notifier = None
|
|
|
|
def __init__(self, directory, dispatcher):
|
|
self.directory = directory
|
|
self.dispatcher = dispatcher
|
|
|
|
def observe(self):
|
|
wm = pyinotify.WatchManager()
|
|
self.notifier = pyinotify.Notifier(wm, EventHandler())
|
|
wm.add_watch(self.directory, pyinotify.IN_CREATE, self.dispatcher.process_audio_file)
|
|
|
|
print(f'Watching {self.directory} for changes...')
|
|
self.notifier.loop()
|
|
|
|
def halt(self):
|
|
self.notifier.stop() |