Skip to content

Commit

Permalink
sync/utils_compat
Browse files Browse the repository at this point in the history
port playlist fixes OpenVoiceOS/ovos-utils#256
  • Loading branch information
JarbasAl committed Jun 21, 2024
1 parent ed6e4a8 commit 85dbf3f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions ovos_workshop/backwards_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down

0 comments on commit 85dbf3f

Please sign in to comment.