moving to not-inotify based file discovery
This commit is contained in:
parent
96e0615267
commit
5ca0805b10
|
@ -1,4 +1,4 @@
|
|||
FROM python
|
||||
FROM python:3.9.18-bookworm
|
||||
|
||||
RUN mkdir /app
|
||||
COPY notescriber /app/notescriber
|
||||
|
@ -10,3 +10,5 @@ WORKDIR /app
|
|||
|
||||
RUN pip install -r requirements.txt
|
||||
RUN /app/load_model.py
|
||||
|
||||
RUN apt update && apt install -y ffmpeg
|
||||
|
|
|
@ -20,8 +20,8 @@ class Dispatcher:
|
|||
# TODO: we need to have a way to wipe old threads, otherwise we may have a memory leak
|
||||
|
||||
def _execute_thread(self, audio_file):
|
||||
filename = os.path.basename(audio_file.pathname)
|
||||
note = self.audioProcessor.execute(audio_file.pathname)
|
||||
filename = os.path.basename(audio_file)
|
||||
note = self.audioProcessor.execute(audio_file)
|
||||
self.noteGenerator.generate_note(filename, note)
|
||||
|
||||
def halt(self):
|
||||
|
|
|
@ -1,34 +1,39 @@
|
|||
import pyinotify
|
||||
import time
|
||||
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
|
||||
observer = None
|
||||
last_file_time = None
|
||||
|
||||
def __init__(self, directory, dispatcher):
|
||||
self.directory = directory
|
||||
self.dispatcher = dispatcher
|
||||
|
||||
def identify_time_window(self, file_time):
|
||||
if self.last_file_time is None:
|
||||
self.last_file_time = time.time()
|
||||
if file_time > self.last_file_time:
|
||||
return True
|
||||
return False
|
||||
|
||||
def list_files(self):
|
||||
files = []
|
||||
for filename in os.listdir(self.directory):
|
||||
filepath = os.path.join(self.directory, filename)
|
||||
if os.path.isfile(filepath):
|
||||
files.append(filepath)
|
||||
return files
|
||||
|
||||
|
||||
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()
|
||||
while True:
|
||||
files = self.list_files()
|
||||
for file in files:
|
||||
file_time = os.path.getmtime(file)
|
||||
if self.identify_time_window(file_time):
|
||||
self.dispatcher.process_audio_file(file)
|
||||
self.last_file_time = time.time()
|
||||
time.sleep(10)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
openai-whisper==20231117
|
||||
pyinotify==0.9.6
|
||||
nextcloud_notes_api==1.0.0
|
||||
PyYaml==6.0.1
|
||||
pyasyncore==1.0.3
|
Loading…
Reference in New Issue