2019-12-27 18:14:51 +09:00
|
|
|
|
from typing import TYPE_CHECKING, Optional, List
|
|
|
|
|
|
2020-01-26 21:19:22 +09:00
|
|
|
|
from yandex_music import YandexMusicObject
|
|
|
|
|
|
2019-12-27 18:14:51 +09:00
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from yandex_music import Client
|
|
|
|
|
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
|
|
|
|
|
class MixLink(YandexMusicObject):
|
2020-03-22 08:59:18 +09:00
|
|
|
|
"""Класс, представляющий ссылку (кликабельный блок) на подборку.
|
|
|
|
|
|
|
|
|
|
Note:
|
|
|
|
|
В цветах может как оказаться HEX (`#6c65a9`), так и какой-нибудь `transparent`.
|
|
|
|
|
|
|
|
|
|
Ссылка со схемой отличается от просто ссылки наличием `yandexmusic://` в начале.
|
2020-01-26 23:50:54 +09:00
|
|
|
|
|
|
|
|
|
Attributes:
|
2020-03-22 08:59:18 +09:00
|
|
|
|
title (:obj:`str`): Заголовок ссылки.
|
|
|
|
|
url (:obj:`str`): Ссылка на подборку.
|
|
|
|
|
url_scheme (:obj:`str`): Ссылка со схемой на подборку.
|
|
|
|
|
text_color (:obj:`str`): Цвет текста (HEX).
|
|
|
|
|
background_color (:obj:`str`): Цвет заднего фона.
|
|
|
|
|
background_image_uri (:obj:`str`): Ссылка на изображение заднего фона.
|
|
|
|
|
cover_white (:obj:`str`): Ссылка на изображение с обложкой TODO.
|
2020-03-22 08:04:39 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`): Клиент Yandex Music.
|
2020-01-26 23:50:54 +09:00
|
|
|
|
|
|
|
|
|
Args:
|
2020-03-22 08:59:18 +09:00
|
|
|
|
title (:obj:`str`): Заголовок ссылки.
|
|
|
|
|
url (:obj:`str`): Ссылка на подборку.
|
|
|
|
|
url_scheme (:obj:`str`): Ссылка со схемой на подборку.
|
|
|
|
|
text_color (:obj:`str`): Цвет текста (HEX).
|
|
|
|
|
background_color (:obj:`str`): Цвет заднего фона.
|
|
|
|
|
background_image_uri (:obj:`str`): Ссылка на изображение заднего фона.
|
|
|
|
|
cover_white (:obj:`str`): Ссылка на изображение с обложкой TODO.
|
Удаление избыточной информации (#247)
Классы: Account, AutoRenewable, PassportPhone, Permissions, Plus, Price,
Product, Status, Subscription, UserSettings, Album, Label,
TrackPosition, Playlist
У всех классов изменено описание атрибута client
2020-03-22 04:49:20 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
2020-01-26 23:50:54 +09:00
|
|
|
|
**kwargs: Произвольные ключевые аргументы полученные от API.
|
|
|
|
|
"""
|
|
|
|
|
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
def __init__(self,
|
2019-12-28 22:25:09 +09:00
|
|
|
|
title: str,
|
|
|
|
|
url: str,
|
|
|
|
|
url_scheme: str,
|
|
|
|
|
text_color: str,
|
|
|
|
|
background_color: str,
|
|
|
|
|
background_image_uri: str,
|
|
|
|
|
cover_white: str,
|
2019-12-27 18:14:51 +09:00
|
|
|
|
client: Optional['Client'] = None,
|
|
|
|
|
**kwargs) -> None:
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
self.title = title
|
|
|
|
|
self.url = url
|
|
|
|
|
self.url_scheme = url_scheme
|
|
|
|
|
self.text_color = text_color
|
|
|
|
|
self.background_color = background_color
|
|
|
|
|
self.background_image_uri = background_image_uri
|
|
|
|
|
self.cover_white = cover_white
|
|
|
|
|
|
|
|
|
|
self.client = client
|
2019-11-08 06:37:53 +09:00
|
|
|
|
self._id_attrs = (self.url, self.title, self.url_scheme, self.text_color,
|
|
|
|
|
self.background_color, self.background_image_uri, self.cover_white)
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
|
2020-05-16 04:14:44 +09:00
|
|
|
|
super().handle_unknown_kwargs(self, **kwargs)
|
|
|
|
|
|
Добавлены тайп хинты для Block, BlockEntity, Char, CharItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShortOld, AlbumsLikes, ArtistsLikes, PlaylistsLikes, CaseForms, MadeFor, PlayCounter, PlaylistAbsence, PlaylistId, User
2019-12-27 22:40:26 +09:00
|
|
|
|
def download_background_image(self, filename: str, size: str = '200x200') -> None:
|
2019-08-18 23:44:46 +09:00
|
|
|
|
"""Загрузка заднего фона.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
filename (:obj:`str`): Путь для сохранения файла с названием и расширением.
|
|
|
|
|
size (:obj:`str`, optional): Размер заднего фона.
|
|
|
|
|
"""
|
|
|
|
|
self.client.request.download(f'https://{self.background_image_uri.replace("%%", size)}', filename)
|
|
|
|
|
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
@classmethod
|
Добавлены тайп хинты для Block, BlockEntity, Char, CharItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShortOld, AlbumsLikes, ArtistsLikes, PlaylistsLikes, CaseForms, MadeFor, PlayCounter, PlaylistAbsence, PlaylistId, User
2019-12-27 22:40:26 +09:00
|
|
|
|
def de_json(cls, data: dict, client: 'Client') -> Optional['MixLink']:
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""Десериализация объекта.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
Удаление избыточной информации (#247)
Классы: Account, AutoRenewable, PassportPhone, Permissions, Plus, Price,
Product, Status, Subscription, UserSettings, Album, Label,
TrackPosition, Playlist
У всех классов изменено описание атрибута client
2020-03-22 04:49:20 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
|
|
|
|
|
Returns:
|
2020-03-22 08:59:18 +09:00
|
|
|
|
:obj:`yandex_music.MixLink`: Блок-ссылка на подборку.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
if not data:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
data = super(MixLink, cls).de_json(data, client)
|
|
|
|
|
|
|
|
|
|
return cls(client=client, **data)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
Добавлены тайп хинты для Block, BlockEntity, Char, CharItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShortOld, AlbumsLikes, ArtistsLikes, PlaylistsLikes, CaseForms, MadeFor, PlayCounter, PlaylistAbsence, PlaylistId, User
2019-12-27 22:40:26 +09:00
|
|
|
|
def de_list(cls, data: dict, client: 'Client') -> List['MixLink']:
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""Десериализация списка объектов.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`list`): Список словарей с полями и значениями десериализуемого объекта.
|
Удаление избыточной информации (#247)
Классы: Account, AutoRenewable, PassportPhone, Permissions, Plus, Price,
Product, Status, Subscription, UserSettings, Album, Label,
TrackPosition, Playlist
У всех классов изменено описание атрибута client
2020-03-22 04:49:20 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
|
|
|
|
|
Returns:
|
2020-03-22 08:59:18 +09:00
|
|
|
|
:obj:`list` из :obj:`yandex_music.MixLink`: Блоки-ссылки на подборки.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""
|
New supported objects: Landing, Block, BlockEntity, Chart, ChartItem, MixLink, PersonalPlaylistsData, PlayContext, PlayContextsData, Promotion, TrackId, TrackShorOld (YEAH!)
The following method are wrapped:
- /landing3
Added the ability to download covers
The following field are optional: Playlist.tags
Now, when parsing json, the "client" key is replaced with "client_"
2019-05-25 02:10:39 +09:00
|
|
|
|
if not data:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
mix_links = list()
|
|
|
|
|
for mix_link in data:
|
|
|
|
|
mix_links.append(cls.de_json(mix_link, client))
|
|
|
|
|
|
|
|
|
|
return mix_links
|
2019-08-18 23:44:46 +09:00
|
|
|
|
|
|
|
|
|
# camelCase псевдонимы
|
|
|
|
|
|
2019-10-19 17:55:45 +09:00
|
|
|
|
#: Псевдоним для :attr:`download_background_image`
|
2019-08-18 23:44:46 +09:00
|
|
|
|
downloadBackgroundImage = download_background_image
|