Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync/utils_compat #215

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading