VisibilityHandler #3
|
@ -1,7 +1,6 @@
|
|||
import multiprocessing as mp
|
||||
|
||||
from .audio import AudioHandler
|
||||
from .handler import Handler
|
||||
from .metadata import MetadataHandler
|
||||
from .poster import PosterHandler
|
||||
from .slides import SlidesHandler
|
||||
|
@ -9,6 +8,7 @@ from .subtitles_whisper_hack import SubtitlesWhisperHandler
|
|||
from .subtitles_import import SubtitlesImportHandler
|
||||
from .thumbnail import ThumbnailHandler
|
||||
from .transcode import TranscodeHandler
|
||||
from .visibility import VisibilityHandler
|
||||
from ..ldap import Ldap
|
||||
from ..utils import get_section
|
||||
|
||||
|
@ -20,6 +20,7 @@ allHandlers = [AudioHandler,
|
|||
SubtitlesWhisperHandler,
|
||||
ThumbnailHandler,
|
||||
TranscodeHandler,
|
||||
VisibilityHandler,
|
||||
]
|
||||
|
||||
def init_handlers(collector, worker, config):
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
from .handler import Handler
|
||||
from ..exceptions import ValidationException
|
||||
|
||||
|
||||
@Handler.register
|
||||
class VisibilityHandler(Handler):
|
||||
"""
|
||||
This class handles visibility settings for streams.
|
||||
"""
|
||||
@classmethod
|
||||
def wants(cls, jobspec, existing_package):
|
||||
"""
|
||||
Return True if this handler wants to process this jobspec.
|
||||
Raises an exception if the job is wanted but doesn't pass validation.
|
||||
|
||||
In order for a job to be wanted, the field 'sources' must exist and
|
||||
at least one of the source items must contain a 'enabled' field.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def _validate(cls, jobspec, existing_package):
|
||||
"""
|
||||
Return True if the job is valid for this handler.
|
||||
|
||||
A job is valid as long as at least one of the package's source items
|
||||
"""
|
||||
pass
|
||||
|
||||
def _handle(self, jobspec, existing_package, tempdir):
|
||||
pass
|
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
|
||||
from os import path, remove, rename
|
||||
from shutil import rmtree
|
||||
|
||||
import ffmpeg
|
||||
|
||||
|
@ -169,7 +168,7 @@ class TranscodeHandler(Handler):
|
|||
"""
|
||||
super()._validate(jobspec, existing_package)
|
||||
if 'upload_dir' not in jobspec:
|
||||
raise ValidationException(f"upload_dir missing")
|
||||
raise ValidationException("upload_dir missing")
|
||||
for name, source in jobspec['sources'].items():
|
||||
if not path.isfile(path.join(jobspec['upload_dir'],
|
||||
source['video'])):
|
||||
|
@ -228,8 +227,10 @@ class TranscodeHandler(Handler):
|
|||
else:
|
||||
# Initialize a new source
|
||||
# set playAudio to False by default so we don't conflict
|
||||
# with the audio handler
|
||||
sources[name] = {'playAudio': False}
|
||||
# with the audio handler, set enabled to True so we don't
|
||||
# conflict with the visibility handler
|
||||
sources[name] = {'playAudio': False,
|
||||
'enabled': True}
|
||||
|
||||
# Save new source videos
|
||||
sources[name]['video'] = variants
|
||||
|
|
57
pipeline/handlers/visibility.py
Normal file
57
pipeline/handlers/visibility.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import copy
|
||||
from pathlib import Path
|
||||
|
||||
from .handler import Handler
|
||||
from ..exceptions import ValidationException
|
||||
from ..package import Package
|
||||
|
||||
@Handler.register
|
||||
class VisibilityHandler(Handler):
|
||||
"""
|
||||
This class handles visibility settings for streams.
|
||||
"""
|
||||
@classmethod
|
||||
def wants(cls, jobspec: dict, existing_package: Package) -> bool | ValidationException:
|
||||
"""
|
||||
Return True if this handler wants to process this jobspec.
|
||||
Raises an exception if the job is wanted but doesn't pass validation.
|
||||
|
||||
In order for a job to be wanted, the field 'sources' must exist and
|
||||
at least one of the source items must contain a 'enabled' field.
|
||||
|
||||
"""
|
||||
if 'sources' in jobspec and any('enabled' in source for source in jobspec['sources'].values()):
|
||||
return cls._validate(jobspec, existing_package)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def _validate(cls, jobspec: dict, existing_package: Package) -> bool | ValidationException:
|
||||
"""
|
||||
Return True if the job is valid for this handler.
|
||||
|
||||
A job is valid as long as at least one of the package's source items
|
||||
has its 'enabled' field set to True.
|
||||
"""
|
||||
sources = copy.deepcopy(existing_package.get('sources', {}))
|
||||
for name, source in jobspec['sources'].items():
|
||||
if name not in sources:
|
||||
sources[name] = {}
|
||||
if 'enabled' in source:
|
||||
sources[name]['enabled'] = source['enabled']
|
||||
for source in sources.values():
|
||||
if 'enabled' in source:
|
||||
return True
|
||||
raise ValidationException("No enabled sources")
|
||||
|
||||
def _handle(self, jobspec: dict, existing_package: Package, tempdir: Path) -> callable:
|
||||
"""
|
||||
"""
|
||||
def apply_func(package: Package) -> None:
|
||||
sources = package.get('sources', {})
|
||||
for name, source in jobspec['sources'].items():
|
||||
if name not in sources:
|
||||
sources[name] = {}
|
||||
if 'enabled' in source:
|
||||
sources[name]['enabled'] = source['enabled']
|
||||
|
||||
return apply_func
|
|
@ -1,4 +1,3 @@
|
|||
from os import chdir, path
|
||||
from types import FunctionType
|
||||
|
||||
|
||||
|
@ -23,6 +22,7 @@ canonical_jobspec = {
|
|||
'source': str}},
|
||||
'sources': {str: {'poster': str,
|
||||
'playAudio': bool,
|
||||
'enabled': bool,
|
||||
'video': str}},
|
||||
'slides': str,
|
||||
'notification_url': str,
|
||||
|
|
Loading…
Reference in New Issue
Block a user