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

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

        Returns:
            :obj:`yandex_music.Artist`: Исполнитель.
        """
        if not data:
            return None

        data = super(Artist, cls).de_json(data, client)
        from yandex_music import Cover, Ratings, Counts, Link, Track, Description

        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['ratings'] = Ratings.de_json(data.get('ratings'), client)
        data['counts'] = Counts.de_json(data.get('counts'), client)
        data['links'] = Link.de_list(data.get('links'), client)
        data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client)
        data['description'] = Description.de_json(data.get('description'), client)

        # Мне очень интересно увидеть как в яндухе на клиентах солвят свой бэковский костыль, пригласите на экскурсию
        if data.get('decomposed'):
            data['decomposed'] = [
                Artist.de_json(part, client) if isinstance(part, dict) else part for part in data['decomposed']
            ]

        return cls(client=client, **data)
Exemplo n.º 3
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.º 4
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.Playlist`: Объект класса :class:`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
        data['owner'] = User.de_json(data.get('owner'), client)
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['made_for'] = MadeFor.de_json(data.get('made_for'), client)
        data['tracks'] = TrackShort.de_list(data.get('tracks'), client)
        data['play_counter'] = PlayCounter.de_json(data.get('play_counter'),
                                                   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.º 5
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['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.º 6
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Artist']:
        """Десериализация объекта.

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

        Returns:
            :obj:`yandex_music.Artist`: Исполнитель.
        """
        if not data:
            return None

        data = super(Artist, cls).de_json(data, client)
        from yandex_music import Cover, Ratings, Counts, Link, Track, Description
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['ratings'] = Ratings.de_json(data.get('ratings'), client)
        data['counts'] = Counts.de_json(data.get('counts'), client)
        data['links'] = Link.de_list(data.get('links'), client)
        data['popular_tracks'] = Track.de_list(data.get('popular_tracks'),
                                               client)
        data['description'] = Description.de_json(data.get('description'),
                                                  client)
        # TODO add "decomposed" deserialization

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

        data = super(Playlist, cls).de_json(data, client)
        from yandex_music import User, MadeFor, Cover, PlayCounter, TrackShort
        data['owner'] = User.de_json(data.get('owner'), client)
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['made_for'] = MadeFor.de_json(data.get('made_for'), client)
        data['tracks'] = TrackShort.de_list(data.get('tracks'), client)
        data['play_counter'] = PlayCounter.de_json(data.get('play_counter'), client)

        return cls(client=client, **data)
Exemplo n.º 8
0
def cover():
    return Cover(
        TestCover.type,
        TestCover.uri,
        TestCover.items_uri,
        TestCover.dir,
        TestCover.version,
        TestCover.custom,
        TestCover.is_custom,
        TestCover.copyright_name,
        TestCover.copyright_cline,
        TestCover.prefix,
        TestCover.error,
    )
Exemplo n.º 9
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(Artist, cls).de_json(data, client)
        from yandex_music import Cover, Ratings, Counts, Link, Track
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['ratings'] = Ratings.de_json(data.get('ratings'), client)
        data['counts'] = Counts.de_json(data.get('counts'), client)
        data['links'] = Link.de_list(data.get('links'), client)
        data['popular_tracks'] = Track.de_list(data.get('popular_tracks'),
                                               client)
        # TODO add "decomposed" deserialization

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

        data = super(Playlist, cls).de_json(data, client)
        from yandex_music import User, MadeFor, Cover, PlayCounter, TrackShort, PlaylistAbsence
        data['owner'] = User.de_json(data.get('owner'), client)
        data['cover'] = Cover.de_json(data.get('cover'), client)
        data['made_for'] = MadeFor.de_json(data.get('made_for'), client)
        data['tracks'] = TrackShort.de_list(data.get('tracks'), client)
        data['play_counter'] = PlayCounter.de_json(data.get('play_counter'), 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.º 11
0
    def de_json(cls, data: dict,
                client: 'Client') -> Optional['OpenGraphData']:
        """Десериализация объекта.

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

        Returns:
            :obj:`yandex_music.OpenGraphData`: Данные для Open Graph.
        """
        if not data:
            return None

        data = super(OpenGraphData, cls).de_json(data, client)
        from yandex_music import Cover

        data['image'] = Cover.de_json(data.get('image'), client)

        return cls(client=client, **data)
Exemplo n.º 12
0
    def test_de_json_all(self, client):
        json_dict = {
            'type': self.type,
            'uri': self.uri,
            'items_uri': self.items_uri,
            'dir': self.dir,
            'version': self.version,
            'custom': self.custom,
            'prefix': self.prefix,
            'error': self.error
        }
        cover = Cover.de_json(json_dict, client)

        assert cover.type == self.type
        assert cover.uri == self.uri
        assert cover.items_uri == self.items_uri
        assert cover.dir == self.dir
        assert cover.version == self.version
        assert cover.custom == self.custom
        assert cover.prefix == self.prefix
        assert cover.error == self.error
Exemplo n.º 13
0
    def test_equality(self, images):
        a = Cover(self.type, self.uri, self.items_uri)

        assert a != images
        assert hash(a) != hash(images)
        assert a is not images
Exemplo n.º 14
0
 def test_de_json_required(self, client):
     json_dict = {}
     cover = Cover.de_json(json_dict, client)
Exemplo n.º 15
0
 def test_de_list_none(self, client):
     assert Cover.de_list({}, client) == []
Exemplo n.º 16
0
def cover():
    return Cover(TestCover.type, TestCover.uri, TestCover.items_uri, TestCover.dir,
                 TestCover.version, TestCover.custom, TestCover.prefix, TestCover.error)
Exemplo n.º 17
0
 def test_de_json_none(self, client):
     assert Cover.de_json({}, client) is None