Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 654215c

Browse files
authored
Merge pull request #278 from chillymosh/fix/playlist-extras
Track.extras (userData) for Playlist
2 parents 7dbccf1 + 110fbfa commit 654215c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

wavelink/tracks.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,54 @@ def track_extras(self, **attrs: object) -> None:
584584
for name, value in attrs.items():
585585
setattr(track, name, value)
586586

587+
@property
588+
def extras(self) -> ExtrasNamespace:
589+
"""Property returning a :class:`~wavelink.ExtrasNamespace` of extras for this :class:`Playlist`.
590+
591+
You can set this property with a :class:`dict` of valid :class:`str` keys to any valid ``JSON`` value,
592+
or a :class:`~wavelink.ExtrasNamespace`.
593+
594+
If a dict is passed, it will be converted into an :class:`~wavelink.ExtrasNamespace`,
595+
which can be converted back to a dict with dict(...). Additionally, you can also use list or tuple on
596+
:class:`~wavelink.ExtrasNamespace`.
597+
598+
The extras dict will be sent to Lavalink as the ``userData`` field for each track in the playlist.
599+
600+
601+
.. warning::
602+
603+
This is only available when using Lavalink 4+ (**Non BETA**) versions.
604+
605+
606+
Examples
607+
--------
608+
609+
.. code:: python
610+
611+
playlist: wavelink.Search = wavelink.Playable.search("QUERY")
612+
playlist.extras = {"requester_id": 1234567890}
613+
614+
# later...
615+
print(playlist.extras.requester_id)
616+
# or
617+
print(dict(playlist.extras)["requester_id"])
618+
619+
620+
.. versionadded:: 3.2.0
621+
"""
622+
return self._extras
623+
624+
@extras.setter
625+
def extras(self, __value: ExtrasNamespace | dict[str, Any]) -> None:
626+
if isinstance(__value, ExtrasNamespace):
627+
self._extras = __value
628+
else:
629+
self._extras = ExtrasNamespace(__value)
630+
631+
for track in self.tracks:
632+
for name, value in dict(self._extras).items():
633+
setattr(track, name, value)
634+
587635

588636
class PlaylistInfo:
589637
"""The wavelink PlaylistInfo container class.

0 commit comments

Comments
 (0)