Suggested monitor/watchdog Suggestions from JayZed

This commit is contained in:
McCloudS
2024-03-20 08:01:52 -06:00
committed by GitHub
parent 86177975c1
commit 9551bc900d

View File

@@ -63,7 +63,7 @@ if transcribe_device == "gpu":
transcribe_device = "cuda" transcribe_device = "cuda"
if monitor: if monitor:
from watchdog.observers import Observer from watchdog.observers.polling import PollingObserver as Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
app = FastAPI() app = FastAPI()
@@ -606,7 +606,7 @@ def get_jellyfin_admin(users):
def has_audio(file_path): def has_audio(file_path):
try: try:
container = av.open(file_path) with av.open(file_path) as container
return any(stream.type == 'audio' for stream in container.streams) return any(stream.type == 'audio' for stream in container.streams)
except (av.AVError, UnicodeDecodeError): except (av.AVError, UnicodeDecodeError):
return False return False
@@ -618,15 +618,20 @@ def path_mapping(fullpath):
return fullpath return fullpath
if monitor: if monitor:
# Define a handler class that will process new files # Define a handler class that will process new files
class NewFileHandler(FileSystemEventHandler): class NewFileHandler(FileSystemEventHandler):
def on_modified(self, event): def create_subtitle(self, event):
# Only process if it's a file # Only process if it's a file
if not event.is_directory: if not event.is_directory:
file_path = event.src_path file_path = event.src_path
if has_audio(file_path)
# Call the gen_subtitles function # Call the gen_subtitles function
logging.info(f"File: {path_mapping(file_path)} was added") logging.info(f"File: {path_mapping(file_path)} was added")
gen_subtitles(path_mapping(file_path), transcribe_or_translate, False) gen_subtitles(path_mapping(file_path), transcribe_or_translate, False)
def on_created(self, event):
self.create_subtitle(event)
def on_modified(self, event):
self.create_subtitle(event)
def transcribe_existing(transcribe_folders, forceLanguage=None): def transcribe_existing(transcribe_folders, forceLanguage=None):
transcribe_folders = transcribe_folders.split("|") transcribe_folders = transcribe_folders.split("|")