Добавлены тайп хинты для 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
|
|
|
from typing import TYPE_CHECKING, Optional, List, Union
|
2019-12-27 18:14:51 +09:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
Добавлены тайп хинты для 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
|
|
|
from yandex_music import Client, BlockEntity, PersonalPlaylistsData, PlayContextsData
|
2019-12-27 18:14:51 +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
|
|
|
from yandex_music import YandexMusicObject
|
|
|
|
|
|
|
|
|
|
|
|
class Block(YandexMusicObject):
|
|
|
|
def __init__(self,
|
2019-12-28 22:25:09 +09:00
|
|
|
id_: str,
|
|
|
|
type_: str,
|
|
|
|
type_for_from: str,
|
|
|
|
title: str,
|
Добавлены тайп хинты для 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
|
|
|
entities: List['BlockEntity'],
|
2019-12-28 22:25:09 +09:00
|
|
|
description: Optional[str] = None,
|
2019-12-28 05:23:05 +09:00
|
|
|
data: Optional[Union['PersonalPlaylistsData', 'PlayContextsData']] = None,
|
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
|
|
|
|
2019-12-27 04:51:29 +09:00
|
|
|
self.id = id_
|
|
|
|
self.type = type_
|
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.type_for_from = type_for_from
|
|
|
|
self.title = title
|
|
|
|
self.entities = entities
|
|
|
|
|
|
|
|
self.description = description
|
|
|
|
self.data = data
|
|
|
|
|
|
|
|
self.client = client
|
2019-11-10 05:59:22 +09:00
|
|
|
self._id_attrs = (self.id, self.type, self.type_for_from, self.title, self.entities)
|
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
|
|
|
|
Добавлены тайп хинты для 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 __getitem__(self, item: int) -> 'BlockEntity':
|
2019-08-18 23:44:46 +09:00
|
|
|
return self.entities[item]
|
|
|
|
|
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['Block']:
|
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(Block, cls).de_json(data, client)
|
|
|
|
from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData
|
|
|
|
data['entities'] = BlockEntity.de_list(data.get('entities'), client)
|
|
|
|
|
2019-12-27 04:51:29 +09:00
|
|
|
block_type = data.get('type_')
|
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 block_type == 'personal-playlists':
|
|
|
|
data['data'] = PersonalPlaylistsData.de_json(data.get('data'), client)
|
|
|
|
elif block_type == 'play-contexts':
|
|
|
|
data['data'] = PlayContextsData.de_json(data.get('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['Block']:
|
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 []
|
|
|
|
|
|
|
|
blocks = list()
|
|
|
|
for block in data:
|
|
|
|
blocks.append(cls.de_json(block, client))
|
|
|
|
|
|
|
|
return blocks
|