playlist_id.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from typing import TYPE_CHECKING, Any, List, Optional, Union
  2. from yandex_music import YandexMusicModel
  3. from yandex_music.utils import model
  4. if TYPE_CHECKING:
  5. from yandex_music import ClientType, Playlist
  6. @model
  7. class PlaylistId(YandexMusicModel):
  8. """Класс, представляющий уникальный идентификатор плейлиста.
  9. Attributes:
  10. uid (:obj:`int`): Уникальный идентификатор пользователя владеющим плейлистом.
  11. kind (:obj:`int`): Уникальный идентификатор плейлиста.
  12. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
  13. """
  14. uid: int
  15. kind: int
  16. client: Optional['ClientType'] = None
  17. def __post_init__(self) -> None:
  18. self._id_attrs = (self.uid, self.kind)
  19. @property
  20. def playlist_id(self) -> str:
  21. """Полный ID плейлиста."""
  22. return f'{self.uid}:{self.kind}'
  23. def fetch_playlist(self, *args: Any, **kwargs: Any) -> Optional[Union['Playlist', List['Playlist']]]:
  24. """Сокращение для::
  25. client.users_playlists(kind, uid, *args, **kwargs)
  26. """
  27. assert self.valid_client(self.client)
  28. return self.client.users_playlists(self.kind, self.uid, *args, **kwargs)
  29. async def fetch_playlist_async(self, *args: Any, **kwargs: Any) -> Optional[Union['Playlist', List['Playlist']]]:
  30. """Сокращение для::
  31. await client.users_playlists(kind, uid, *args, **kwargs)
  32. """
  33. assert self.valid_async_client(self.client)
  34. return await self.client.users_playlists(self.kind, self.uid, *args, **kwargs)
  35. # camelCase псевдонимы
  36. #: Псевдоним для :attr:`playlist_id`
  37. playlistId = playlist_id
  38. #: Псевдоним для :attr:`fetch_playlist`
  39. fetchPlaylist = fetch_playlist
  40. #: Псевдоним для :attr:`fetch_playlist_async`
  41. fetchPlaylistAsync = fetch_playlist_async