def de_json(cls, data, client): """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client` представляющий клиент Yandex Music. Returns: :obj:`yandex_music.BriefInfo`: Объект класса :class:`yandex_music.BriefInfo`. """ if not data: return None data = super(BriefInfo, cls).de_json(data, client) from yandex_music import Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl data['artist'] = Artist.de_json(data.get('artist'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['albums'] = Album.de_list(data.get('albums'), client) data['also_albums'] = Album.de_list(data.get('also_albums'), client) data['all_covers'] = Cover.de_list(data.get('all_covers'), client) data['playlist_ids'] = PlaylistId.de_list(data.get('playlist_ids'), client) data['videos'] = Video.de_list(data.get('videos'), client) data['tracks_in_chart'] = Chart.de_list(data.get('tracks_in_chart'), client) data['vinyls'] = Vinyl.de_list(data.get('vinyls'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['BriefInfo']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.BriefInfo`: Информация об артисте. """ if not data: return None data = super(BriefInfo, cls).de_json(data, client) from yandex_music import Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl, Playlist data['playlists'] = Playlist.de_list(data.get('playlists'), client) data['artist'] = Artist.de_json(data.get('artist'), client) data['similar_artists'] = Artist.de_list(data.get('similar_artists'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['albums'] = Album.de_list(data.get('albums'), client) data['also_albums'] = Album.de_list(data.get('also_albums'), client) data['last_releases'] = Album.de_list(data.get('last_releases'), client) data['all_covers'] = Cover.de_list(data.get('all_covers'), client) data['playlist_ids'] = PlaylistId.de_list(data.get('playlist_ids'), client) data['videos'] = Video.de_list(data.get('videos'), client) data['tracks_in_chart'] = Chart.de_list(data.get('tracks_in_chart'), client) data['vinyls'] = Vinyl.de_list(data.get('vinyls'), client) return cls(client=client, **data)
def test_equality(self, artist, label): a = Album(self.id) b = Album(10) c = Album(self.id) assert a != b assert hash(a) != hash(b) assert a is not b assert a == c
def test_equality(self, artist, label): a = Album(self.id, self.title, self.track_count, [artist], [label], self.available, self.available_for_premium_users) b = Album(10, '', 99, [artist], [label], self.available, self.available_for_premium_users) c = Album(self.id, self.title, self.track_count, [artist], [label], self.available, self.available_for_premium_users) assert a != b assert hash(a) != hash(b) assert a is not b assert a == c
def de_json(cls, data: dict, client: 'Client') -> Optional['Track']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Track`: Трек. """ if not data: return None data = super(Track, cls).de_json(data, client) from yandex_music import Normalization, Major, Album, Artist, User, MetaData, PoetryLoverMatch data['albums'] = Album.de_list(data.get('albums'), client) data['artists'] = Artist.de_list(data.get('artists'), client) data['normalization'] = Normalization.de_json( data.get('normalization'), client) data['major'] = Major.de_json(data.get('major'), client) data['substituted'] = Track.de_json(data.get('substituted'), client) data['matched_track'] = Track.de_json(data.get('matched_track'), client) data['user_info'] = User.de_json(data.get('user_info'), client) data['meta_data'] = MetaData.de_json(data.get('meta_data'), client) data['poetry_lover_matches'] = PoetryLoverMatch.de_list( data.get('poetry_lover_matches'), client) return cls(client=client, **data)
def test_de_json_all(self, client, artist, label, track_position, track): json_dict = { 'id_': self.id, 'error': self.error, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': [label.to_dict()], 'available': self.available, 'available_for_premium_users': self.available_for_premium_users, 'version': self.version, 'content_warning': self.content_warning, 'regions': self.regions, 'original_release_year': self.original_release_year, 'genre': self.genre, 'buy': self.buy, 'og_image': self.og_image, 'recent': self.recent, 'very_important': self.very_important, 'available_for_mobile': self.available_for_mobile, 'available_partially': self.available_partially, 'bests': self.bests, 'prerolls': self.prerolls, 'volumes': [[track.to_dict()]], 'year': self.year, 'release_date': self.release_date, 'type_': self.type, 'track_position': track_position.to_dict() } album = Album.de_json(json_dict, client) assert album.id == self.id assert album.error == self.error assert album.title == self.title assert album.version == self.version assert album.cover_uri == self.cover_uri assert album.track_count == self.track_count assert album.artists == [artist] assert album.labels == [label] assert album.available == self.available assert album.available_for_premium_users == self.available_for_premium_users assert album.content_warning == self.content_warning assert album.original_release_year == self.original_release_year assert album.genre == self.genre assert album.og_image == self.og_image assert album.buy == self.buy assert album.recent == self.recent assert album.very_important == self.very_important assert album.available_for_mobile == self.available_for_mobile assert album.available_partially == self.available_partially assert album.bests == self.bests assert album.prerolls == self.prerolls assert album.volumes == [[track]] assert album.year == self.year assert album.release_date == self.release_date assert album.type == self.type assert album.track_position == track_position assert album.regions == self.regions
def get(self, artists, volumes): return Album(TestAlbum.id, TestAlbum.error, TestAlbum.title, TestAlbum.track_count, artists, [label], TestAlbum.available, TestAlbum.available_for_premium_users, TestAlbum.version, TestAlbum.cover_uri, TestAlbum.content_warning, TestAlbum.original_release_year, TestAlbum.genre, TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent, TestAlbum.very_important, TestAlbum.available_for_mobile, TestAlbum.available_partially, TestAlbum.bests, TestAlbum.prerolls, volumes, TestAlbum.year, TestAlbum.release_date, TestAlbum.type, track_position, TestAlbum.regions)
def de_json(cls, data, client): if not data: return None data = super(AlbumSearchResult, cls).de_json(data, client) from yandex_music import Album data['results'] = Album.de_list(data.get('results'), client) return cls(client=client, **data)
def de_json(cls, data, client): if not data: return None data = super(AlbumsLikes, cls).de_json(data, client) from yandex_music import Album data['album'] = Album.de_json(data.get('album'), client) return cls(client=client, **data)
def de_json(cls, data, client): if not data: return None data = super(AlbumEvent, cls).de_json(data, client) from yandex_music import Album, Track data['album'] = Album.de_json(data.get('album'), client) data['tracks'] = Track.de_list(data.get('tracks'), client) return cls(client=client, **data)
def de_json(cls, data, client): if not data: return None data = super(Track, cls).de_json(data, client) from yandex_music import Normalization, Major, Album, Artist data['albums'] = Album.de_list(data.get('albums'), client) data['artists'] = Artist.de_list(data.get('artists'), client) data['normalization'] = Normalization.de_json( data.get('normalization'), client) data['major'] = Major.de_json(data.get('major'), client) return cls(client=client, **data)
def test_de_json_required(self, client, artist, label): json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': [label.to_dict()], 'available': self.available, 'available_for_premium_users': self.available_for_premium_users} album = Album.de_json(json_dict, client) assert album.id == self.id assert album.title == self.title assert album.cover_uri == self.cover_uri assert album.track_count == self.track_count assert album.artists == [artist] assert album.labels == [label] assert album.available == self.available assert album.available_for_premium_users == self.available_for_premium_users
def get(self, artists, volumes, albums=None, deprecation=None): return Album( TestAlbum.id, TestAlbum.error, TestAlbum.title, TestAlbum.track_count, artists, [label], TestAlbum.available, TestAlbum.available_for_premium_users, TestAlbum.version, TestAlbum.cover_uri, TestAlbum.content_warning, TestAlbum.original_release_year, TestAlbum.genre, TestAlbum.text_color, TestAlbum.short_description, TestAlbum.description, TestAlbum.is_premiere, TestAlbum.is_banner, TestAlbum.meta_type, TestAlbum.storage_dir, TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent, TestAlbum.very_important, TestAlbum.available_for_mobile, TestAlbum.available_partially, TestAlbum.bests, albums, TestAlbum.prerolls, volumes, TestAlbum.year, TestAlbum.release_date, TestAlbum.type, track_position, TestAlbum.regions, TestAlbum.available_as_rbt, TestAlbum.lyrics_available, TestAlbum.remember_position, albums, TestAlbum.duration_ms, TestAlbum.explicit, TestAlbum.start_date, TestAlbum.likes_count, deprecation, TestAlbum.available_regions, )
def de_json(cls, data: dict, client: 'Client') -> Optional['ArtistAlbums']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.ArtistAlbums`: Список альбомов артиста. """ if not data: return None data = super(ArtistAlbums, cls).de_json(data, client) from yandex_music import Album, Pager data['albums'] = Album.de_list(data.get('albums'), client) data['pager'] = Pager.de_json(data.get('pager'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['AlbumEvent']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.AlbumEvent`: Альбом в событии фида. """ if not data: return None data = super(AlbumEvent, cls).de_json(data, client) from yandex_music import Album, Track data['album'] = Album.de_json(data.get('album'), client) data['tracks'] = Track.de_list(data.get('tracks'), client) return cls(client=client, **data)
def de_json(cls, data, client): """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client`, представляющий клиент Yandex Music. Returns: :obj:`yandex_music.ArtistAlbums`: Объект класса :class:`yandex_music.ArtistAlbums`. """ if not data: return None data = super(ArtistAlbums, cls).de_json(data, client) from yandex_music import Album, Pager data['albums'] = Album.de_list(data.get('albums'), client) data['pager'] = Pager.de_json(data.get('pager'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Track']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Track`: Трек. """ if not data: return None data = super(Track, cls).de_json(data, client) from yandex_music import Normalization, Major, Album, Artist data['albums'] = Album.de_list(data.get('albums'), client) data['artists'] = Artist.de_list(data.get('artists'), client) data['normalization'] = Normalization.de_json( data.get('normalization'), client) data['major'] = Major.de_json(data.get('major'), client) return cls(client=client, **data)
def albums_with_tracks(self, album_id: str or int, timeout=None, *args, **kwargs): """Получение альбома по его уникальному идентификатору вместе с треками. Args: album_id (:obj:`str` | :obj:`int`): Уникальный идентификатор альбома. timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания ответа от сервера вместо указанного при создании пула. **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос). Returns: :obj:`list` из :obj:`yandex_music.Album`: Объект класса :class:`yandex_music.Album` представляющий альбом, иначе :obj:`None`. Raises: :class:`yandex_music.YandexMusicError` """ url = f'{self.base_url}/albums/{album_id}/with-tracks' result = self._request.get(url, timeout=timeout, *args, **kwargs) return Album.de_json(result, self)
def de_json(cls, data, client): """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client`, представляющий клиент Yandex Music. Returns: :obj:`yandex_music.Track`: Объект класса :class:`yandex_music.Track`. """ if not data: return None data = super(Track, cls).de_json(data, client) from yandex_music import Normalization, Major, Album, Artist data['albums'] = Album.de_list(data.get('albums'), client) data['artists'] = Artist.de_list(data.get('artists'), client) data['normalization'] = Normalization.de_json( data.get('normalization'), client) data['major'] = Major.de_json(data.get('major'), client) return cls(client=client, **data)
def test_de_json_required(self, client): json_dict = {'id_': self.id} album = Album.de_json(json_dict, client)
def test_de_list_none(self, client): assert Album.de_list({}, client) == []
def test_de_json_none(self, client): assert Album.de_json({}, client) is None
def test_de_json_all(self, client, artist, label, track_position, track, album_without_nested_albums, deprecation): labels = [label] if type(label) == str else [label.to_dict()] json_dict = { 'id_': self.id, 'error': self.error, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': labels, 'available': self.available, 'available_for_premium_users': self.available_for_premium_users, 'version': self.version, 'content_warning': self.content_warning, 'regions': self.regions, 'original_release_year': self.original_release_year, 'genre': self.genre, 'buy': self.buy, 'og_image': self.og_image, 'recent': self.recent, 'very_important': self.very_important, 'available_for_mobile': self.available_for_mobile, 'available_partially': self.available_partially, 'bests': self.bests, 'prerolls': self.prerolls, 'volumes': [[track.to_dict()]], 'year': self.year, 'release_date': self.release_date, 'type_': self.type, 'track_position': track_position.to_dict(), 'meta_type': self.meta_type, 'storage_dir': self.storage_dir, 'is_banner': self.is_banner, 'duplicates': [album_without_nested_albums.to_dict()], 'is_premiere': self.is_premiere, 'short_description': self.short_description, 'description': self.description, 'text_color': self.text_color, 'available_as_rbt': self.available_as_rbt, 'lyrics_available': self.lyrics_available, 'remember_position': self.remember_position, 'albums': [album_without_nested_albums.to_dict()], 'duration_ms': self.duration_ms, 'explicit': self.explicit, 'start_date': self.start_date, 'likes_count': self.likes_count, 'deprecation': deprecation.to_dict(), 'available_regions': self.available_regions, } album = Album.de_json(json_dict, client) assert album.id == self.id assert album.error == self.error assert album.title == self.title assert album.version == self.version assert album.cover_uri == self.cover_uri assert album.track_count == self.track_count assert album.artists == [artist] assert album.labels == [label] assert album.available == self.available assert album.available_for_premium_users == self.available_for_premium_users assert album.content_warning == self.content_warning assert album.original_release_year == self.original_release_year assert album.genre == self.genre assert album.text_color == self.text_color assert album.short_description == self.short_description assert album.description == self.description assert album.is_premiere == self.is_premiere assert album.is_banner == self.is_banner assert album.meta_type == self.meta_type assert album.storage_dir == self.storage_dir assert album.og_image == self.og_image assert album.buy == self.buy assert album.recent == self.recent assert album.very_important == self.very_important assert album.available_for_mobile == self.available_for_mobile assert album.available_partially == self.available_partially assert album.bests == self.bests assert album.duplicates == [album_without_nested_albums] assert album.prerolls == self.prerolls assert album.volumes == [[track]] assert album.year == self.year assert album.release_date == self.release_date assert album.type == self.type assert album.track_position == track_position assert album.regions == self.regions assert album.available_as_rbt == self.available_as_rbt assert album.lyrics_available == self.lyrics_available assert album.remember_position == self.remember_position assert album.duration_ms == self.duration_ms assert album.explicit == self.explicit assert album.start_date == self.start_date assert album.likes_count == self.likes_count assert album.deprecation == deprecation assert album.available_regions == self.available_regions