diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..cd4ee00 --- /dev/null +++ b/dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12-slim + +# Install ffmpeg (needed for your script) +RUN apt-get update && \ + apt-get install -y ffmpeg && \ + apt-get clean && rm -rf /var/lib/apt/lists/* +RUN pip install watchdog + +# Set working directory inside container +WORKDIR /app + +# Copy your script +COPY main.py /app/main.py + +# Install any Python dependencies if needed +# RUN pip install -r requirements.txt + +# Copy watchdog script (or create inside Docker) +COPY watcher.py /app/watcher.py + +CMD ["python3", "watcher.py"] diff --git a/watcher.py b/watcher.py new file mode 100644 index 0000000..b0a17b0 --- /dev/null +++ b/watcher.py @@ -0,0 +1,29 @@ +import os +import subprocess +import time +from watchdog.observers import Observer +from watchdog.events import FileSystemEventHandler + +WATCH_DIR = "/data" # Mount your host directory here + +class NewBookHandler(FileSystemEventHandler): + def on_created(self, event): + if event.is_directory: + book_dir = event.src_path + print(f"New directory detected: {book_dir}") + # Run your main.py with the new book directory + subprocess.run(["python3", "main.py", "-da", book_dir], check=True) + +if __name__ == "__main__": + observer = Observer() + event_handler = NewBookHandler() + observer.schedule(event_handler, WATCH_DIR, recursive=True) + observer.start() + print(f"Watching for new folders in {WATCH_DIR} ...") + + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + observer.join()