From 66234077a402a6d435646381ee0c655b7b07c795 Mon Sep 17 00:00:00 2001 From: Jonathan Baecker Date: Thu, 15 Oct 2020 10:44:11 +0200 Subject: [PATCH] fix folder watch #69, jump to next file when current file is deleted --- ffplayout/folder.py | 15 ++++++++++++--- ffplayout/output/desktop.py | 3 ++- ffplayout/output/hls.py | 3 ++- ffplayout/output/stream.py | 5 +++-- ffplayout/utils.py | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ffplayout/folder.py b/ffplayout/folder.py index b98d1992..83a08e4f 100644 --- a/ffplayout/folder.py +++ b/ffplayout/folder.py @@ -26,13 +26,13 @@ from watchdog.events import PatternMatchingEventHandler from watchdog.observers import Observer from .filters import build_filtergraph -from .utils import MediaProbe, _storage, messenger, stdin_args - +from .utils import MediaProbe, _current, _ff, _storage, messenger, stdin_args # ------------------------------------------------------------------------------ # folder watcher # ------------------------------------------------------------------------------ + class MediaStore: """ fill media list for playing @@ -85,8 +85,14 @@ class MediaWatcher: def __init__(self, media): self._media = media + print(_storage.extensions) + + self.extensions = ['*{}'.format(ext) for ext in _storage.extensions] + + print(self.extensions) + self.event_handler = PatternMatchingEventHandler( - patterns=_storage.extensions) + patterns=self.extensions) self.event_handler.on_created = self.on_created self.event_handler.on_moved = self.on_moved self.event_handler.on_deleted = self.on_deleted @@ -121,6 +127,9 @@ class MediaWatcher: messenger.info( 'Remove file from media list: "{}"'.format(event.src_path)) + if _current.clip == event.src_path: + _ff.decoder.terminate() + def stop(self): self.observer.stop() self.observer.join() diff --git a/ffplayout/output/desktop.py b/ffplayout/output/desktop.py index efdc7f34..0a2a393a 100644 --- a/ffplayout/output/desktop.py +++ b/ffplayout/output/desktop.py @@ -4,7 +4,7 @@ from threading import Thread from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.playlist import GetSourceFromPlaylist -from ffplayout.utils import (_ff, _log, _playlist, _pre, _text, +from ffplayout.utils import (_current, _ff, _log, _playlist, _pre, _text, ffmpeg_stderr_reader, messenger, pre_audio_codec, stdin_args, terminate_processes) @@ -64,6 +64,7 @@ def output(): else: current_file = src_cmd[3] + _current.clip = current_file messenger.info('Play: "{}"'.format(current_file)) with Popen([ diff --git a/ffplayout/output/hls.py b/ffplayout/output/hls.py index 25ec4b04..1ea7a69c 100644 --- a/ffplayout/output/hls.py +++ b/ffplayout/output/hls.py @@ -6,7 +6,7 @@ from threading import Thread from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.playlist import GetSourceFromPlaylist -from ffplayout.utils import (_ff, _log, _playlist, _playout, +from ffplayout.utils import (_current, _ff, _log, _playlist, _playout, ffmpeg_stderr_reader, get_date, messenger, stdin_args, terminate_processes) @@ -61,6 +61,7 @@ def output(): else: current_file = src_cmd[3] + _current.clip = current_file messenger.info('Play: "{}"'.format(current_file)) cmd = [ 'ffmpeg', '-v', _log.ff_level.lower(), '-hide_banner', diff --git a/ffplayout/output/stream.py b/ffplayout/output/stream.py index 551bcb03..49bf9de3 100644 --- a/ffplayout/output/stream.py +++ b/ffplayout/output/stream.py @@ -4,8 +4,8 @@ from threading import Thread from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.playlist import GetSourceFromPlaylist -from ffplayout.utils import (_ff, _log, _playlist, _playout, _pre, _text, - ffmpeg_stderr_reader, get_date, messenger, +from ffplayout.utils import (_current, _ff, _log, _playlist, _playout, _pre, + _text, ffmpeg_stderr_reader, get_date, messenger, pre_audio_codec, stdin_args, terminate_processes) _WINDOWS = os.name == 'nt' @@ -72,6 +72,7 @@ def output(): else: current_file = src_cmd[3] + _current.clip = current_file messenger.info('Play: "{}"'.format(current_file)) with Popen([ diff --git a/ffplayout/utils.py b/ffplayout/utils.py index cc3323b2..2d6dc457 100644 --- a/ffplayout/utils.py +++ b/ffplayout/utils.py @@ -122,6 +122,7 @@ _playout = SimpleNamespace() _init = SimpleNamespace(load=True) _ff = SimpleNamespace(decoder=None, encoder=None) +_current = SimpleNamespace(clip=None) _global = SimpleNamespace(time_delta=0)