From 85dbf3f78363a8e9c0471cd114d8899201754490 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 21 Jun 2024 16:01:15 +0100 Subject: [PATCH 1/2] sync/utils_compat port playlist fixes https://github.com/OpenVoiceOS/ovos-utils/pull/256 --- ovos_workshop/backwards_compat.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ovos_workshop/backwards_compat.py b/ovos_workshop/backwards_compat.py index 0acc4af1..bd72354a 100644 --- a/ovos_workshop/backwards_compat.py +++ b/ovos_workshop/backwards_compat.py @@ -299,16 +299,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 +310,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""" From 5f80727ddb9084c9316e2e06b94fca422a59d852 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 21 Jun 2024 18:24:26 +0100 Subject: [PATCH 2/2] https://github.com/OpenVoiceOS/ovos-utils/pull/257 --- ovos_workshop/backwards_compat.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ovos_workshop/backwards_compat.py b/ovos_workshop/backwards_compat.py index bd72354a..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: """