From c8089ae62c745f075934670082b109b970fd8206 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:29:44 +0100 Subject: [PATCH] sync/utils_compat (#215) * sync/utils_compat port playlist fixes https://github.com/OpenVoiceOS/ovos-utils/pull/256 * https://github.com/OpenVoiceOS/ovos-utils/pull/257 --- ovos_workshop/backwards_compat.py | 37 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/ovos_workshop/backwards_compat.py b/ovos_workshop/backwards_compat.py index 0acc4af1..de06d3ed 100644 --- a/ovos_workshop/backwards_compat.py +++ b/ovos_workshop/backwards_compat.py @@ -256,6 +256,22 @@ class PluginStream: image: str = "" skill_icon: str = "" + def extract_uri(self, video=True) -> str: + from ovos_plugin_manager.ocp import load_stream_extractors + xtract = load_stream_extractors() + meta = xtract.extract_stream(f"{self.extractor_id}//{self.stream}", + video=video) + return meta["uri"] + + def extract_media_entry(self, video=True) -> MediaEntry: + from ovos_plugin_manager.ocp import load_stream_extractors + xtract = load_stream_extractors() + meta = xtract.extract_stream(f"{self.extractor_id}//{self.stream}", + video=video) + kwargs = {k: v for k, v in meta.items() + if k in inspect.signature(MediaEntry).parameters} + return MediaEntry(**kwargs) + @property def infocard(self) -> dict: """ @@ -299,16 +315,7 @@ def from_dict(track: dict) -> 'PluginStream': @dataclass - class _Listdataclass(list): - """this is needed for proper **kwarg resolution - of a dataclass that is a subclass of a list""" - - def __init__(self, *args, **kwargs): - list.__init__(self, *args) - - - @dataclass - class Playlist(_Listdataclass): + class Playlist(list): title: str = "" artist: str = "" position: int = 0 @@ -319,6 +326,16 @@ class Playlist(_Listdataclass): playback: PlaybackType = PlaybackType.UNDEFINED media_type: MediaType = MediaType.GENERIC + def __init__(self, *args, **kwargs): + super().__init__() + for k, v in kwargs.items(): + if hasattr(self, k): + self.__setattr__(k, v) + if len(args) == 1 and isinstance(args[0], list): + args = args[0] + for e in args: + self.add_entry(e) + @property def length(self): """calc the length value based on all entries"""