Skip to content

Commit

Permalink
fix: Report clear error if an input track does not exist (#94)
Browse files Browse the repository at this point in the history
Probing with 'stream=index' should return the track_num if it existed, and an empty string if the input did not exist.

Fixes #89
  • Loading branch information
mariocynicys committed Sep 9, 2021
1 parent c54e181 commit 689b803
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions streamer/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
18 changes: 18 additions & 0 deletions streamer/input_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 689b803

Please sign in to comment.