fix folder watch #69, jump to next file when current file is deleted

This commit is contained in:
Jonathan Baecker 2020-10-15 10:44:11 +02:00
parent 7b9b654de5
commit 66234077a4
5 changed files with 20 additions and 7 deletions

View File

@ -26,13 +26,13 @@ from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer from watchdog.observers import Observer
from .filters import build_filtergraph 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 # folder watcher
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class MediaStore: class MediaStore:
""" """
fill media list for playing fill media list for playing
@ -85,8 +85,14 @@ class MediaWatcher:
def __init__(self, media): def __init__(self, media):
self._media = media self._media = media
print(_storage.extensions)
self.extensions = ['*{}'.format(ext) for ext in _storage.extensions]
print(self.extensions)
self.event_handler = PatternMatchingEventHandler( self.event_handler = PatternMatchingEventHandler(
patterns=_storage.extensions) patterns=self.extensions)
self.event_handler.on_created = self.on_created self.event_handler.on_created = self.on_created
self.event_handler.on_moved = self.on_moved self.event_handler.on_moved = self.on_moved
self.event_handler.on_deleted = self.on_deleted self.event_handler.on_deleted = self.on_deleted
@ -121,6 +127,9 @@ class MediaWatcher:
messenger.info( messenger.info(
'Remove file from media list: "{}"'.format(event.src_path)) 'Remove file from media list: "{}"'.format(event.src_path))
if _current.clip == event.src_path:
_ff.decoder.terminate()
def stop(self): def stop(self):
self.observer.stop() self.observer.stop()
self.observer.join() self.observer.join()

View File

@ -4,7 +4,7 @@ from threading import Thread
from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher
from ffplayout.playlist import GetSourceFromPlaylist 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, ffmpeg_stderr_reader, messenger, pre_audio_codec,
stdin_args, terminate_processes) stdin_args, terminate_processes)
@ -64,6 +64,7 @@ def output():
else: else:
current_file = src_cmd[3] current_file = src_cmd[3]
_current.clip = current_file
messenger.info('Play: "{}"'.format(current_file)) messenger.info('Play: "{}"'.format(current_file))
with Popen([ with Popen([

View File

@ -6,7 +6,7 @@ from threading import Thread
from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher
from ffplayout.playlist import GetSourceFromPlaylist 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, ffmpeg_stderr_reader, get_date, messenger,
stdin_args, terminate_processes) stdin_args, terminate_processes)
@ -61,6 +61,7 @@ def output():
else: else:
current_file = src_cmd[3] current_file = src_cmd[3]
_current.clip = current_file
messenger.info('Play: "{}"'.format(current_file)) messenger.info('Play: "{}"'.format(current_file))
cmd = [ cmd = [
'ffmpeg', '-v', _log.ff_level.lower(), '-hide_banner', 'ffmpeg', '-v', _log.ff_level.lower(), '-hide_banner',

View File

@ -4,8 +4,8 @@ from threading import Thread
from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher
from ffplayout.playlist import GetSourceFromPlaylist from ffplayout.playlist import GetSourceFromPlaylist
from ffplayout.utils import (_ff, _log, _playlist, _playout, _pre, _text, from ffplayout.utils import (_current, _ff, _log, _playlist, _playout, _pre,
ffmpeg_stderr_reader, get_date, messenger, _text, ffmpeg_stderr_reader, get_date, messenger,
pre_audio_codec, stdin_args, terminate_processes) pre_audio_codec, stdin_args, terminate_processes)
_WINDOWS = os.name == 'nt' _WINDOWS = os.name == 'nt'
@ -72,6 +72,7 @@ def output():
else: else:
current_file = src_cmd[3] current_file = src_cmd[3]
_current.clip = current_file
messenger.info('Play: "{}"'.format(current_file)) messenger.info('Play: "{}"'.format(current_file))
with Popen([ with Popen([

View File

@ -122,6 +122,7 @@ _playout = SimpleNamespace()
_init = SimpleNamespace(load=True) _init = SimpleNamespace(load=True)
_ff = SimpleNamespace(decoder=None, encoder=None) _ff = SimpleNamespace(decoder=None, encoder=None)
_current = SimpleNamespace(clip=None)
_global = SimpleNamespace(time_delta=0) _global = SimpleNamespace(time_delta=0)