Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def de_json(cls, data, client, type_=None):
        """Десериализация объекта.

		Args:
			data (:obj:`dict`): Поля и значения десериализуемого объекта.
			type_ (:obj:`str`, optional): Тип объекта с отметкой "мне нравится".
			client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client`, представляющий клиент
				Yandex Music.

		Returns:
			:obj:`yandex_music.Like`: Объект класса :class:`yandex_music.Like`.
		"""
        if not data:
            return None

        data = super(Like, cls).de_json(data, client)

        if type_ == 'artist':
            if 'artist' not in data:
                temp_data = data.copy()
                data.clear()
                data[type_] = Artist.de_json(temp_data, client)
            else:
                data[type_] = Artist.de_json(data.get('artist'), client)
        else:
            data[type_] = de_list[type_](data.get(type_), client)

        data['type_'] = type_

        return cls(client=client, **data)
Exemplo n.º 3
0
    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['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['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)
Exemplo n.º 4
0
    def test_equality(self, cover):
        a = Artist(self.id)
        b = Artist(10)
        c = Artist(self.id)

        assert a != b
        assert hash(a) != hash(b)
        assert a is not b

        assert a == c
    def test_equality(self, cover):
        a = Artist(self.id, self.name, cover)
        b = Artist(self.id, '', None)
        c = Artist(self.id, self.name, cover)

        assert a != b
        assert hash(a) != hash(b)
        assert a is not b

        assert a == c
Exemplo n.º 6
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['ArtistEvent']:
        if not data:
            return None

        data = super(ArtistEvent, cls).de_json(data, client)
        from yandex_music import Artist, Track
        data['artist'] = Artist.de_json(data.get('artist'), client)
        data['tracks'] = Track.de_list(data.get('tracks'), client)
        data['similar_to_artists_from_history'] = Artist.de_list(
            data.get('similar_to_artists_from_history'), client)

        return cls(client=client, **data)
Exemplo n.º 7
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(ArtistsLikes, cls).de_json(data, client)
        from yandex_music import Artist
        if 'artist' not in data:
            temp_data = data.copy()
            data.clear()
            data['artist'] = Artist.de_json(temp_data, client)
        else:
            data['artist'] = Artist.de_json(data.get('artist'), client)

        return cls(client=client, **data)
    def test_de_json_required(self, client, cover):
        json_dict = {'id': self.id, 'name': self.name, 'cover': cover.to_dict()}
        artist = Artist.de_json(json_dict, client)

        assert artist.id == self.id
        assert artist.name == self.name
        assert artist.cover == cover
Exemplo n.º 9
0
 def get(self, popular_tracks, decomposed=None):
     return Artist(
         TestArtist.id,
         TestArtist.error,
         TestArtist.reason,
         TestArtist.name,
         cover,
         TestArtist.various,
         TestArtist.composer,
         TestArtist.genres,
         TestArtist.og_image,
         TestArtist.op_image,
         TestArtist.no_pictures_from_search,
         counts,
         TestArtist.available,
         ratings,
         [link],
         TestArtist.tickets_available,
         TestArtist.likes_count,
         popular_tracks,
         TestArtist.regions,
         decomposed,
         TestArtist.full_names,
         TestArtist.hand_made_description,
         description,
         TestArtist.countries,
         TestArtist.en_wikipedia_link,
         TestArtist.db_aliases,
         TestArtist.aliases,
         TestArtist.init_date,
         TestArtist.end_date,
         TestArtist.ya_money_id,
     )
Exemplo n.º 10
0
    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.Album`: Объект класса :class:`yandex_music.Album`.
        """
        if not data:
            return None

        data = super(Album, cls).de_json(data, client)
        from yandex_music import Artist, Label, TrackPosition, Track
        data['artists'] = Artist.de_list(data.get('artists'), client)
        data['labels'] = Label.de_list(data.get('labels'), client)
        data['track_position'] = TrackPosition.de_json(
            data.get('track_position'), client)
        if data.get('volumes'):
            data['volumes'] = [
                Track.de_list(i, client) for i in data['volumes']
            ]

        return cls(client=client, **data)
Exemplo n.º 11
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Album']:
        """Десериализация объекта.

        Args:
            data (:obj:`dict`): Поля и значения десериализуемого объекта.
            client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.

        Returns:
            :obj:`yandex_music.Album`: Альбом.
        """
        if not data:
            return None

        data = super(Album, cls).de_json(data, client)
        from yandex_music import Artist, Label, TrackPosition, Track, Deprecation

        data['artists'] = Artist.de_list(data.get('artists'), client)
        data['labels'] = Label.de_list(data.get('labels'), client)
        data['track_position'] = TrackPosition.de_json(
            data.get('track_position'), client)
        data['duplicates'] = Album.de_list(data.get('duplicates'), client)
        data['albums'] = Album.de_list(data.get('albums'), client)
        data['deprecation'] = Deprecation.de_json(data.get('deprecation'),
                                                  client)
        if data.get('volumes'):
            data['volumes'] = [
                Track.de_list(i, client) for i in data['volumes']
            ]

        return cls(client=client, **data)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Playlist']:
        """Десериализация объекта.

        Args:
            data (:obj:`dict`): Поля и значения десериализуемого объекта.
            client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.

        Returns:
            :obj:`yandex_music.Playlist`: Плейлист.
        """
        if not data:
            return None

        data = super(Playlist, cls).de_json(data, client)
        from yandex_music import (
            User,
            MadeFor,
            Cover,
            PlayCounter,
            TrackShort,
            PlaylistAbsence,
            Artist,
            TrackId,
            Contest,
            OpenGraphData,
            Brand,
        )

        data['owner'] = User.de_json(data.get('owner'), client)
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['cover_without_text'] = Cover.de_json(
            data.get('cover_without_text'), client)
        data['made_for'] = MadeFor.de_json(data.get('made_for'), client)
        data['tracks'] = TrackShort.de_list(data.get('tracks'), client)
        data['recent_tracks'] = TrackId.de_list(data.get('recent_tracks'),
                                                client)
        data['play_counter'] = PlayCounter.de_json(data.get('play_counter'),
                                                   client)
        data['top_artist'] = Artist.de_list(data.get('top_artist'), client)
        data['contest'] = Contest.de_json(data.get('contest'), client)
        data['og_data'] = OpenGraphData.de_json(data.get('og_data'), client)
        data['dummy_cover'] = Cover.de_json(data.get('dummy_cover'), client)
        data['dummy_rollover_cover'] = Cover.de_json(
            data.get('dummy_rollover_cover'), client)
        data['branding'] = Brand.de_json(data.get('branding'), client)

        data['similar_playlists'] = Playlist.de_list(
            data.get('similar_playlists'), client)
        data['last_owner_playlists'] = Playlist.de_list(
            data.get('last_owner_playlists'), client)

        data['playlist_absence'] = PlaylistAbsence.de_json(
            data.get('playlist_absence'), client)  # на случай фикса
        if data.get('playlist_absense'):  # очепятка яндуха
            data['playlist_absence'] = PlaylistAbsence.de_json(
                data.get('playlist_absense'), client)
            data.pop('playlist_absense')

        return cls(client=client, **data)
Exemplo n.º 14
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(ArtistSearchResult, cls).de_json(data, client)
        from yandex_music import Artist
        data['results'] = Artist.de_list(data.get('results'), client)

        return cls(client=client, **data)
Exemplo n.º 15
0
    def test_de_json_all(self, client, cover, counts, ratings, link,
                         track_without_artists, description):
        json_dict = {
            'id_': self.id,
            'name': self.name,
            'various': self.various,
            'composer': self.composer,
            'cover': cover.to_dict(),
            'genres': self.genres,
            'op_image': self.op_image,
            'no_pictures_from_search': self.no_pictures_from_search,
            'counts': counts.to_dict(),
            'available': self.available,
            'ratings': ratings.to_dict(),
            'links': [link.to_dict()],
            'tickets_available': self.tickets_available,
            'likes_count': self.likes_count,
            'popular_tracks': [track_without_artists.to_dict()],
            'regions': self.regions,
            'decomposed': self.decomposed,
            'full_names': self.full_names,
            'description': description.to_dict(),
            'countries': self.countries,
            'en_wikipedia_link': self.en_wikipedia_link,
            'db_aliases': self.db_aliases,
            'aliases': self.aliases,
            'init_date': self.init_date,
            'end_date': self.end_date
        }
        artist = Artist.de_json(json_dict, client)

        assert artist.id == self.id
        assert artist.name == self.name
        assert artist.various == self.various
        assert artist.composer == self.composer
        assert artist.cover == cover
        assert artist.genres == self.genres
        assert artist.op_image == self.op_image
        assert artist.no_pictures_from_search == self.no_pictures_from_search
        assert artist.counts == counts
        assert artist.available == self.available
        assert artist.ratings == ratings
        assert artist.links == [link]
        assert artist.tickets_available == self.tickets_available
        assert artist.likes_count == self.likes_count
        assert artist.popular_tracks == [track_without_artists]
        assert artist.regions == self.regions
        assert artist.decomposed == self.decomposed
        assert artist.full_names == self.full_names
        assert artist.description == description
        assert artist.countries == self.countries
        assert artist.en_wikipedia_link == self.en_wikipedia_link
        assert artist.db_aliases == self.db_aliases
        assert artist.aliases == self.aliases
        assert artist.init_date == self.init_date
        assert artist.end_date == self.end_date
Exemplo n.º 16
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(Album, cls).de_json(data, client)
        from yandex_music import Artist, Label, TrackPosition
        data['artists'] = Artist.de_list(data.get('artists'), client)
        data['labels'] = Label.de_list(data.get('labels'), client)
        data['track_position'] = TrackPosition.de_json(data.get('track_position'), client)

        return cls(client=client, **data)
Exemplo n.º 17
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['ArtistEvent']:
        """Десериализация объекта.

        Args:
            data (:obj:`dict`): Поля и значения десериализуемого объекта.
            client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.

        Returns:
            :obj:`yandex_music.ArtistEvent`: Артист из события фида.
        """
        if not data:
            return None

        data = super(ArtistEvent, cls).de_json(data, client)
        from yandex_music import Artist, Track

        data['artist'] = Artist.de_json(data.get('artist'), client)
        data['tracks'] = Track.de_list(data.get('tracks'), client)
        data['similar_to_artists_from_history'] = Artist.de_list(data.get('similar_to_artists_from_history'), client)

        return cls(client=client, **data)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Album']:
        if not data:
            return None

        data = super(Album, cls).de_json(data, client)
        from yandex_music import Artist, Label, TrackPosition, Track
        data['artists'] = Artist.de_list(data.get('artists'), client)
        data['labels'] = Label.de_list(data.get('labels'), client)
        data['track_position'] = TrackPosition.de_json(
            data.get('track_position'), client)
        if data.get('volumes'):
            data['volumes'] = [
                Track.de_list(i, client) for i in data['volumes']
            ]

        return cls(client=client, **data)
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    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)
Exemplo n.º 22
0
 def test_de_json_none(self, client):
     assert Artist.de_json({}, client) is None
Exemplo n.º 23
0
 def test_de_list_none(self, client):
     assert Artist.de_list({}, client) == []
Exemplo n.º 24
0
    def test_de_json_required(self, client, cover):
        json_dict = {'id_': self.id}
        artist = Artist.de_json(json_dict, client)

        assert artist.id == self.id