2019-12-28 22:25:09 +09:00
|
|
|
|
from typing import TYPE_CHECKING, Optional, List, Union
|
Добавлены тайп хинты в соответствии с документацией для следуюшщих классов: YandexMusicObject, Cover, Captcha, DownloadInfo, Experiments, Icon, InvocationInfo, Pager, PermissionAlerts, PromoCodeStatus, Settings, TrackShort, TracksList, Video #120
2019-12-24 16:17:04 +09:00
|
|
|
|
|
2020-01-26 21:19:22 +09:00
|
|
|
|
from yandex_music import YandexMusicObject
|
2021-09-19 22:47:19 +09:00
|
|
|
|
from yandex_music.utils import model
|
2020-01-26 21:19:22 +09:00
|
|
|
|
|
Добавлены тайп хинты в соответствии с документацией для следуюшщих классов: YandexMusicObject, Cover, Captcha, DownloadInfo, Experiments, Icon, InvocationInfo, Pager, PermissionAlerts, PromoCodeStatus, Settings, TrackShort, TracksList, Video #120
2019-12-24 16:17:04 +09:00
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from yandex_music import Client
|
|
|
|
|
|
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
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
@model
|
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 Video(YandexMusicObject):
|
2020-03-22 07:32:38 +09:00
|
|
|
|
"""Класс, представляющий видео.
|
|
|
|
|
|
2021-02-03 21:28:10 +09:00
|
|
|
|
Attributes:
|
|
|
|
|
title (:obj:`str`): Название видео.
|
|
|
|
|
cover (:obj:`str`, optional): Ссылка на изображение.
|
|
|
|
|
embed_url (:obj:`str`, optional): Ссылка на видео.
|
|
|
|
|
provider (:obj:`str`, optional): Провайдер видео.
|
|
|
|
|
provider_video_id (:obj:`int` | :obj:`str`, optional): Идентификатор видео.
|
|
|
|
|
youtube_url (:obj:`str`, optional): Ссылка на видео Youtube.
|
|
|
|
|
thumbnail_url (:obj:`str`, optional): Ссылка на изображение.
|
|
|
|
|
duration (:obj:`int`, optional): Длительность видео в секундах.
|
|
|
|
|
text (:obj:`str`, optional): Текст.
|
|
|
|
|
html_auto_play_video_player (:obj:`str`, optional): HTML тег для встраивания в разметку страницы.
|
|
|
|
|
regions (:obj:`list` из :obj:`str`, optional): Регион TODO.
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
"""
|
2020-01-26 23:50:54 +09:00
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
title: str
|
|
|
|
|
cover: Optional[str] = None
|
|
|
|
|
embed_url: Optional[str] = None
|
|
|
|
|
provider: Optional[str] = None
|
|
|
|
|
provider_video_id: Optional[Union[int, str]] = None
|
|
|
|
|
youtube_url: Optional[str] = None
|
|
|
|
|
thumbnail_url: Optional[str] = None
|
|
|
|
|
duration: Optional[int] = None
|
|
|
|
|
text: Optional[str] = None
|
|
|
|
|
html_auto_play_video_player: Optional[str] = None
|
|
|
|
|
regions: Optional[List[str]] = None
|
|
|
|
|
client: Optional['Client'] = None
|
|
|
|
|
|
|
|
|
|
def __post_init__(self):
|
2019-11-08 04:52:26 +09:00
|
|
|
|
self._id_attrs = (self.provider_video_id, self.youtube_url, self.title)
|
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
|
|
|
|
|
|
|
|
|
@classmethod
|
Добавлены тайп хинты в соответствии с документацией для следуюшщих классов: YandexMusicObject, Cover, Captcha, DownloadInfo, Experiments, Icon, InvocationInfo, Pager, PermissionAlerts, PromoCodeStatus, Settings, TrackShort, TracksList, Video #120
2019-12-24 16:17:04 +09:00
|
|
|
|
def de_json(cls, data: dict, client: 'Client') -> Optional['Video']:
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""Десериализация объекта.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
2020-03-22 07:32:38 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`): Клиент Yandex Music.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
|
|
|
|
|
Returns:
|
2020-03-22 07:32:38 +09:00
|
|
|
|
:obj:`yandex_music.Video`: Видео.
|
2020-01-26 22:17:09 +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
|
|
|
|
if not data:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
data = super(Video, cls).de_json(data, client)
|
|
|
|
|
|
|
|
|
|
return cls(client=client, **data)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
Добавлены тайп хинты в соответствии с документацией для следуюшщих классов: YandexMusicObject, Cover, Captcha, DownloadInfo, Experiments, Icon, InvocationInfo, Pager, PermissionAlerts, PromoCodeStatus, Settings, TrackShort, TracksList, Video #120
2019-12-24 16:17:04 +09:00
|
|
|
|
def de_list(cls, data: dict, client: 'Client') -> List['Video']:
|
2020-01-26 22:17:09 +09:00
|
|
|
|
"""Десериализация списка объектов.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`list`): Список словарей с полями и значениями десериализуемого объекта.
|
2020-03-22 07:32:38 +09:00
|
|
|
|
client (:obj:`yandex_music.Client`): Клиент Yandex Music.
|
2020-01-26 22:17:09 +09:00
|
|
|
|
|
|
|
|
|
Returns:
|
2020-03-22 07:32:38 +09:00
|
|
|
|
:obj:`list` из :obj:`yandex_music.Video`: Видео.
|
2020-01-26 22:17:09 +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
|
|
|
|
if not data:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
videos = list()
|
|
|
|
|
for video in data:
|
|
|
|
|
videos.append(cls.de_json(video, client))
|
|
|
|
|
|
|
|
|
|
return videos
|