From 689b8030bbe0d007cb260977d03301401b66c17d Mon Sep 17 00:00:00 2001 From: mariocynicys Date: Thu, 9 Sep 2021 17:29:44 +0200 Subject: [PATCH] fix: Report clear error if an input track does not exist (#94) Probing with 'stream=index' should return the track_num if it existed, and an empty string if the input did not exist. Fixes #89 --- streamer/autodetect.py | 7 +++++++ streamer/input_configuration.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/streamer/autodetect.py b/streamer/autodetect.py index 0c32233..f774f98 100644 --- a/streamer/autodetect.py +++ b/streamer/autodetect.py @@ -80,6 +80,13 @@ def _probe(input: Input, field: str) -> Optional[str]: return output_string +def is_present(input: Input) -> bool: + """Returns true if the stream for this input is indeed found. + + If we can't probe this input type, assume it is present.""" + + return bool(_probe(input, 'stream=index') or + input.input_type in TYPES_WE_CANT_PROBE) def get_language(input: Input) -> Optional[str]: """Returns the autodetected the language of the input.""" diff --git a/streamer/input_configuration.py b/streamer/input_configuration.py index a6db412..bb81899 100644 --- a/streamer/input_configuration.py +++ b/streamer/input_configuration.py @@ -21,6 +21,21 @@ from typing import List, Dict, Any, Optional +class InputNotFound(configuration.ConfigError): + """An error raised when an input stream is not found.""" + + def __init__(self, input): + super().__init__(input.__class__, 'track_num', + getattr(input.__class__, 'track_num')) + self.input = input + + def __str__(self): + return ('In {}, {} track #{} was' + ' not found in "{}"').format(self.class_name, + self.input.media_type.value, + self.input.track_num, + self.input.name) + class InputType(enum.Enum): FILE = 'file' """A track from a file. Usable only with VOD.""" @@ -195,6 +210,9 @@ def __init__(self, *args) -> None: # modules. from . import autodetect + if not autodetect.is_present(self): + raise InputNotFound(self) + def require_field(name: str) -> None: """Raise MissingRequiredField if the named field is still missing.""" if getattr(self, name) is None: