Добавлены тайп хинты для Suggestions, SearchResult, Search, Best, Value, StationResult, Station, Sequence, RotorSettings, Restrictions, Id, Enum, DiscreteScale, Dashboard, AdParams
2019-12-27 22:06:24 +09:00
|
|
|
from typing import TYPE_CHECKING, Optional, List, Union
|
2019-12-27 18:14:51 +09:00
|
|
|
|
2020-01-26 21:19:22 +09:00
|
|
|
from yandex_music import YandexMusicObject, Artist, Album, Track, Playlist, Video
|
|
|
|
|
2019-12-27 18:14:51 +09:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from yandex_music import Client
|
|
|
|
|
2019-11-10 03:11:43 +09:00
|
|
|
|
|
|
|
de_json_result = {
|
|
|
|
'track': Track.de_list,
|
|
|
|
'artist': Artist.de_list,
|
|
|
|
'album': Album.de_list,
|
|
|
|
'playlist': Playlist.de_list,
|
|
|
|
'video': Video.de_list,
|
|
|
|
}
|
New supported objects: Search, Suggestions, Video, Best, AlbumSearchResult, ArtistSearchResult, PlaylistSearchResult, TrackSearchResult, VideoSearchResult,
The following methods are wrapped:
- /search
- /search/suggest
The following classes received optional fields instead of required ones: Album, Artist, Playlist, Track
Added "params" arg to the GET request
Code refactoring
2019-05-18 01:20:34 +09:00
|
|
|
|
|
|
|
|
|
|
|
class SearchResult(YandexMusicObject):
|
2020-01-23 02:38:57 +09:00
|
|
|
"""Класс, представляющий результаты поиска.
|
2020-01-22 22:07:27 +09:00
|
|
|
|
2020-02-04 04:26:10 +09:00
|
|
|
Note:
|
|
|
|
Значения поля `type`: `track`, `artist`, `playlist`, `album`, `video`.
|
|
|
|
|
2020-01-26 21:19:22 +09:00
|
|
|
Attributes:
|
2020-02-04 04:26:10 +09:00
|
|
|
type (:obj:`str`): Тип результата.
|
2020-01-26 21:19:22 +09:00
|
|
|
total (:obj:`int`): Количество результатов.
|
|
|
|
per_page (:obj:`int`): Максимальное количество результатов на странице.
|
|
|
|
order (:obj:`int`): Позиция блока.
|
|
|
|
results (:obj:`list` из :obj:`yandex_music.Track` | :obj:`yandex_music.Artist` | :obj:`yandex_music.Album` \
|
|
|
|
| :obj:`yandex_music.Playlist` | :obj:`yandex_music.Video`): Результаты поиска.
|
2020-03-22 08:04:39 +09:00
|
|
|
client (:obj:`yandex_music.Client`): Клиент Yandex Music.
|
2020-01-26 21:19:22 +09:00
|
|
|
|
|
|
|
Args:
|
2020-02-04 04:26:10 +09:00
|
|
|
type_ (:obj:`str`): Тип результата.
|
2020-01-26 21:19:22 +09:00
|
|
|
total (:obj:`int`): Количество результатов.
|
|
|
|
per_page (:obj:`int`): Максимальное количество результатов на странице.
|
|
|
|
order (:obj:`int`): Позиция блока.
|
|
|
|
results (:obj:`list` из :obj:`yandex_music.Track` | :obj:`yandex_music.Artist` | :obj:`yandex_music.Album` \
|
|
|
|
| :obj:`yandex_music.Playlist` | :obj:`yandex_music.Video`): Результаты поиска.
|
Удаление избыточной информации (#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 21:19:22 +09:00
|
|
|
**kwargs: Произвольные ключевые аргументы полученные от API.
|
2020-01-22 22:07:27 +09:00
|
|
|
"""
|
2020-01-22 22:23:48 +09:00
|
|
|
|
New supported objects: Search, Suggestions, Video, Best, AlbumSearchResult, ArtistSearchResult, PlaylistSearchResult, TrackSearchResult, VideoSearchResult,
The following methods are wrapped:
- /search
- /search/suggest
The following classes received optional fields instead of required ones: Album, Artist, Playlist, Track
Added "params" arg to the GET request
Code refactoring
2019-05-18 01:20:34 +09:00
|
|
|
def __init__(self,
|
2020-02-04 04:26:10 +09:00
|
|
|
type_: str,
|
2019-12-28 22:25:09 +09:00
|
|
|
total: int,
|
|
|
|
per_page: int,
|
|
|
|
order: int,
|
Добавлены тайп хинты для Suggestions, SearchResult, Search, Best, Value, StationResult, Station, Sequence, RotorSettings, Restrictions, Id, Enum, DiscreteScale, Dashboard, AdParams
2019-12-27 22:06:24 +09:00
|
|
|
results: List[Union[Track, Artist, Album, Playlist, Video]],
|
2019-12-27 18:14:51 +09:00
|
|
|
client: Optional['Client'] = None,
|
|
|
|
**kwargs) -> None:
|
2020-02-04 04:26:10 +09:00
|
|
|
self.type = type_
|
2020-01-22 22:15:48 +09:00
|
|
|
self.total = total
|
New supported objects: Search, Suggestions, Video, Best, AlbumSearchResult, ArtistSearchResult, PlaylistSearchResult, TrackSearchResult, VideoSearchResult,
The following methods are wrapped:
- /search
- /search/suggest
The following classes received optional fields instead of required ones: Album, Artist, Playlist, Track
Added "params" arg to the GET request
Code refactoring
2019-05-18 01:20:34 +09:00
|
|
|
self.per_page = per_page
|
|
|
|
self.order = order
|
|
|
|
self.results = results
|
|
|
|
|
|
|
|
self.client = client
|
2019-11-10 03:11:43 +09:00
|
|
|
self._id_attrs = (self.total, self.per_page, self.order, self.results)
|
|
|
|
|
|
|
|
@classmethod
|
Добавлены тайп хинты для Suggestions, SearchResult, Search, Best, Value, StationResult, Station, Sequence, RotorSettings, Restrictions, Id, Enum, DiscreteScale, Dashboard, AdParams
2019-12-27 22:06:24 +09:00
|
|
|
def de_json(cls, data: dict, client: 'Client', type_: str = None) -> Optional['SearchResult']:
|
2020-01-22 22:07:27 +09:00
|
|
|
"""Десериализация объекта.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
2020-01-22 22:23:48 +09:00
|
|
|
type_ (:obj:`str`, optional): Тип результата.
|
Удаление избыточной информации (#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-22 22:07:27 +09:00
|
|
|
|
|
|
|
Returns:
|
2020-03-22 06:29:34 +09:00
|
|
|
:obj:`yandex_music.SearchResult`: Результаты поиска.
|
2020-01-22 22:07:27 +09:00
|
|
|
"""
|
2019-11-10 03:11:43 +09:00
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
data = super(SearchResult, cls).de_json(data, client)
|
2020-02-04 04:26:10 +09:00
|
|
|
data['type_'] = type_
|
2019-12-27 04:51:29 +09:00
|
|
|
data['results'] = de_json_result.get(type_)(data.get('results'), client)
|
2019-11-10 03:11:43 +09:00
|
|
|
|
|
|
|
return cls(client=client, **data)
|