Skip to content

Commit

Permalink
sync/utils_compat (#215)
Browse files Browse the repository at this point in the history
* sync/utils_compat

port playlist fixes OpenVoiceOS/ovos-utils#256

* OpenVoiceOS/ovos-utils#257
  • Loading branch information
JarbasAl authored Jun 21, 2024
1 parent ed6e4a8 commit c8089ae
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions ovos_workshop/backwards_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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
Expand All @@ -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"""
Expand Down

0 comments on commit c8089ae

Please sign in to comment.