Skip to content

Commit

Permalink
Merge pull request #278 from chillymosh/fix/playlist-extras
Browse files Browse the repository at this point in the history
Track.extras (userData) for Playlist
  • Loading branch information
EvieePy authored Feb 3, 2024
2 parents 7dbccf1 + 110fbfa commit 654215c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions wavelink/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,54 @@ def track_extras(self, **attrs: object) -> None:
for name, value in attrs.items():
setattr(track, name, value)

@property
def extras(self) -> ExtrasNamespace:
"""Property returning a :class:`~wavelink.ExtrasNamespace` of extras for this :class:`Playlist`.
You can set this property with a :class:`dict` of valid :class:`str` keys to any valid ``JSON`` value,
or a :class:`~wavelink.ExtrasNamespace`.
If a dict is passed, it will be converted into an :class:`~wavelink.ExtrasNamespace`,
which can be converted back to a dict with dict(...). Additionally, you can also use list or tuple on
:class:`~wavelink.ExtrasNamespace`.
The extras dict will be sent to Lavalink as the ``userData`` field for each track in the playlist.
.. warning::
This is only available when using Lavalink 4+ (**Non BETA**) versions.
Examples
--------
.. code:: python
playlist: wavelink.Search = wavelink.Playable.search("QUERY")
playlist.extras = {"requester_id": 1234567890}
# later...
print(playlist.extras.requester_id)
# or
print(dict(playlist.extras)["requester_id"])
.. versionadded:: 3.2.0
"""
return self._extras

@extras.setter
def extras(self, __value: ExtrasNamespace | dict[str, Any]) -> None:
if isinstance(__value, ExtrasNamespace):
self._extras = __value
else:
self._extras = ExtrasNamespace(__value)

for track in self.tracks:
for name, value in dict(self._extras).items():
setattr(track, name, value)


class PlaylistInfo:
"""The wavelink PlaylistInfo container class.
Expand Down

0 comments on commit 654215c

Please sign in to comment.