Enhanced get_default_media_plugin to filter by video/audio plugins.

This commit is contained in:
Fabio Manganiello 2023-12-10 21:50:53 +01:00
parent 03c167d6b7
commit e6e4396e49
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 26 additions and 5 deletions

View file

@ -28,6 +28,7 @@ if not is_defined('alarm'):
snooze_interval = Column(Integer, nullable=True)
actions = Column(JSON, nullable=True)
static = Column(Boolean, nullable=False, default=False)
condition_type = Column(String, nullable=False)
__table_args__ = {'extend_existing': True}
__mapper_args__ = {

View file

@ -5,9 +5,17 @@ from platypush.context import get_plugin
from platypush.plugins.media import MediaPlugin
def get_default_media_plugin() -> MediaPlugin:
audio_plugins = [
'sound',
'music.mpd',
]
def get_default_media_plugin(video: bool = False) -> MediaPlugin:
"""
Get the default media plugin based on the current configuration.
:param video: If True then the plugin must support video playback.
"""
enabled_plugins: List[MediaPlugin] = []
@ -26,8 +34,20 @@ def get_default_media_plugin() -> MediaPlugin:
if local_plugins:
return local_plugins[0]
assert (
enabled_plugins
), f'No media plugin is enabled. Supported plugins: {MediaPlugin.supported_media_plugins}'
if enabled_plugins:
return enabled_plugins[0]
return enabled_plugins[0]
assert not video, (
'No media plugin with video support is enabled. '
f'Supported plugins: {MediaPlugin.supported_media_plugins}'
)
for plugin_name in audio_plugins:
try:
plugin = get_plugin(plugin_name)
if plugin and plugin_name in cfg and not cfg[plugin_name].get('disabled'):
return plugin
except Exception:
pass
raise AssertionError('No media plugin is enabled')