Beispiel #1
0
    def users_playlists_name(self, kind: str or int, name: str, user_id: str = None, timeout=None, *args, **kwargs):
        """Изменение названия плейлиста.

        Args:
            kind (:obj:`str` | :obj:`int`): Уникальный идентификатор плейлиста.
            name (:obj:`str`): Новое название.
            user_id: (:obj:`int`, optional): Уникальный идентификатор пользователя владеющим плейлистом.
            timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания
                ответа от сервера вместо указанного при создании пула.
            **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос).

        Returns:
            :obj:`yandex_music.Playlist`: Объекта класса :class:`yandex_music.Playlist`
            представляющий изменённый плейлист, иначе :obj:`None`.

        Raises:
            :class:`yandex_music.YandexMusicError`
        """

        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/{kind}/name'

        result = self._request.post(url, {'value': name}, timeout=timeout, *args, **kwargs)

        return Playlist.de_json(result, self)
Beispiel #2
0
    def users_playlists_create(self, title: str, visibility: str = 'public', user_id: str = None,
                               timeout=None, *args, **kwargs):
        """Создание плейлиста.

        Args:
            title (:obj:`str`): Название.
            visibility (:obj:`str`, optional): Модификатор доступа.
            user_id: (:obj:`int`, optional): Уникальный идентификатор пользователя владеющим плейлистом.
            timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания
                ответа от сервера вместо указанного при создании пула.
            **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос).

        Returns:
            :obj:`yandex_music.Playlist`: Объекта класса :class:`yandex_music.Playlist`
            представляющий созданный плейлист, иначе :obj:`None`.

        Raises:
            :class:`yandex_music.YandexMusicError`
        """

        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/create'

        data = {
            'title': title,
            'visibility': visibility
        }

        result = self._request.post(url, data, timeout=timeout, *args, **kwargs)

        return Playlist.de_json(result, self)
Beispiel #3
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(PlaylistsLikes, cls).de_json(data, client)
        from yandex_music import Playlist
        data['playlist'] = Playlist.de_json(data.get('playlist'), client)

        return cls(client=client, **data)
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(GeneratedPlaylist, cls).de_json(data, client)
        from yandex_music import Playlist
        data['data'] = Playlist.de_json(data.get('data'), client)

        return cls(client=client, **data)
Beispiel #5
0
    def test_de_json_required(self, client, user, cover, made_for, play_counter, playlist_absence):
        json_dict = {
            'owner': user.to_dict(),
            'cover': cover.to_dict(),
            'made_for': made_for.to_dict(),
            'play_counter': play_counter.to_dict(),
            'playlist_absence': playlist_absence.to_dict(),
        }
        playlist = Playlist.de_json(json_dict, client)

        assert playlist.owner == user
        assert playlist.cover == cover
        assert playlist.made_for == made_for
        assert playlist.play_counter == play_counter
        assert playlist.playlist_absence == playlist_absence
Beispiel #6
0
	def de_json(cls, data, client):
		"""Десериализация объекта.

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

		Returns:
			:obj:`yandex_music.ChartInfo`: Чарт.
		"""
		if not data:
			return None

		data = super(ChartInfo, cls).de_json(data, client)
		data['chart'] = Playlist.de_json(data.get('chart'), client)
		data['menu'] = ChartInfoMenu.de_json(data.get('menu'), client)

		return cls(client=client, **data)
Beispiel #7
0
    def users_playlists_name(self,
                             kind: str or int,
                             name: str,
                             user_id: str = None,
                             timeout=None,
                             *args,
                             **kwargs):
        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/{kind}/name'

        result = self._request.post(url, {'value': name},
                                    timeout=timeout,
                                    *args,
                                    **kwargs)

        return Playlist.de_json(result, self)
Beispiel #8
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['GeneratedPlaylist']:
        """Десериализация объекта.

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

        Returns:
            :obj:`yandex_music.GeneratedPlaylist`: Автоматически сгенерированный плейлист.
        """
        if not data:
            return None

        data = super(GeneratedPlaylist, cls).de_json(data, client)
        from yandex_music import Playlist

        data['data'] = Playlist.de_json(data.get('data'), 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.GeneratedPlaylist`: Объект класса :class:`yandex_music.GeneratedPlaylist`.
        """
        if not data:
            return None

        data = super(GeneratedPlaylist, cls).de_json(data, client)
        from yandex_music import Playlist
        data['data'] = Playlist.de_json(data.get('data'), client)

        return cls(client=client, **data)
Beispiel #10
0
    def users_playlists_create(self,
                               title: str,
                               visibility: str = 'public',
                               user_id: str = None,
                               timeout=None,
                               *args,
                               **kwargs):
        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/create'

        data = {'title': title, 'visibility': visibility}

        result = self._request.post(url,
                                    data,
                                    timeout=timeout,
                                    *args,
                                    **kwargs)

        return Playlist.de_json(result, self)
Beispiel #11
0
    def users_playlists_change(self,
                               kind: str or int,
                               diff: str,
                               revision: int = 1,
                               user_id: str = None,
                               timeout=None,
                               *args,
                               **kwargs):
        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/{kind}/change'

        data = {'kind': kind, 'revision': revision, 'diff': diff}

        result = self._request.post(url,
                                    data,
                                    timeout=timeout,
                                    *args,
                                    **kwargs)

        return Playlist.de_json(result, self)
    def test_de_json_required(self, client, user, cover, made_for,
                              play_counter):
        json_dict = {
            'owner': user.to_dict(),
            'uid': self.uid,
            'kind': self.kind,
            'title': self.title,
            'track_count': self.track_count,
            'cover': cover.to_dict(),
            'made_for': made_for.to_dict(),
            'play_counter': play_counter.to_dict()
        }
        playlist = Playlist.de_json(json_dict, client)

        assert playlist.owner == user
        assert playlist.uid == self.uid
        assert playlist.kind == self.kind
        assert playlist.title == self.title
        assert playlist.track_count == self.track_count
        assert playlist.cover == cover
        assert playlist.made_for == made_for
        assert playlist.play_counter == play_counter
Beispiel #13
0
    def users_playlists_change(self, kind: str or int, diff: str, revision: int = 1, user_id: str = None,
                               timeout=None, *args, **kwargs):
        """Изменение плейлиста.

        Для получения отличий есть вспомогательный класс :class:`from yandex_music.utils.difference.Difference`.
        Так же существуют уже готовые методы-обёртки над операциями.

        Args:
            kind (:obj:`str` | :obj:`int`): Уникальный идентификатор плейлиста.
            revision (:obj:`int`): TODO.
            diff (:obj:`str`): JSON представления отличий старого и нового плейлиста.
            user_id: (:obj:`int`, optional): Уникальный идентификатор пользователя владеющим плейлистом.
            timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания
                ответа от сервера вместо указанного при создании пула.
            **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос).

        Returns:
            :obj:`yandex_music.Playlist`: Объекта класса :class:`yandex_music.Playlist`
            представляющий изменённый плейлист, иначе :obj:`None`.

        Raises:
            :class:`yandex_music.YandexMusicError`
        """

        if user_id is None:
            user_id = self.account.uid

        url = f'{self.base_url}/users/{user_id}/playlists/{kind}/change'

        data = {
            'kind': kind,
            'revision': revision,
            'diff': diff
        }

        result = self._request.post(url, data, timeout=timeout, *args, **kwargs)

        return Playlist.de_json(result, self)
Beispiel #14
0
    def test_de_json_all(
        self,
        client,
        user,
        cover,
        made_for,
        track_short,
        play_counter,
        playlist_absence,
        playlist_without_nested_playlists,
        artist,
        track_id,
        contest,
        open_graph_data,
        brand,
    ):
        json_dict = {
            'owner': user.to_dict(),
            'uid': self.uid,
            'kind': self.kind,
            'title': self.title,
            'track_count': self.track_count,
            'cover': cover.to_dict(),
            'made_for': made_for.to_dict(),
            'play_counter': play_counter.to_dict(),
            'playlist_absence': playlist_absence.to_dict(),
            'tags': self.tags,
            'revision': self.revision,
            'snapshot': self.snapshot,
            'visibility': self.visibility,
            'collective': self.collective,
            'created': self.created,
            'modified': self.modified,
            'available': self.available,
            'is_banner': self.is_banner,
            'is_premiere': self.is_premiere,
            'duration_ms': self.duration_ms,
            'og_image': self.og_image,
            'tracks': [track_short.to_dict()],
            'prerolls': self.prerolls,
            'likes_count': self.likes_count,
            'generated_playlist_type': self.generated_playlist_type,
            'url_part': self.url_part,
            'animated_cover_uri': self.animated_cover_uri,
            'ever_played': self.ever_played,
            'description': self.description,
            'description_formatted': self.description_formatted,
            'is_for_from': self.is_for_from,
            'regions': self.regions,
            'og_title': self.og_title,
            'image': self.image,
            'id_for_from': self.id_for_from,
            'background_color': self.background_color,
            'text_color': self.text_color,
            'cover_without_text': cover.to_dict(),
            'coauthors': self.coauthors,
            'similar_playlists': [playlist_without_nested_playlists.to_dict()],
            'last_owner_playlists': [playlist_without_nested_playlists.to_dict()],
            'og_description': self.og_description,
            'top_artist': [artist.to_dict()],
            'recent_tracks': [track_id.to_dict()],
            'metrika_id': self.metrika_id,
            'contest': contest.to_dict(),
            'dummy_description': self.dummy_description,
            'dummy_page_description': self.dummy_page_description,
            'dummy_cover': cover.to_dict(),
            'dummy_rollover_cover': cover.to_dict(),
            'og_data': open_graph_data.to_dict(),
            'branding': brand.to_dict(),
            'playlist_uuid': self.playlist_uuid,
            'type_': self.type,
            'ready': self.ready,
        }
        playlist = Playlist.de_json(json_dict, client)

        assert playlist.owner == user
        assert playlist.uid == self.uid
        assert playlist.kind == self.kind
        assert playlist.title == self.title
        assert playlist.track_count == self.track_count
        assert playlist.cover == cover
        assert playlist.made_for == made_for
        assert playlist.play_counter == play_counter
        assert playlist.playlist_absence == playlist_absence
        assert playlist.tags == self.tags
        assert playlist.revision == self.revision
        assert playlist.snapshot == self.snapshot
        assert playlist.visibility == self.visibility
        assert playlist.collective == self.collective
        assert playlist.url_part == self.url_part
        assert playlist.created == self.created
        assert playlist.modified == self.modified
        assert playlist.available == self.available
        assert playlist.is_banner == self.is_banner
        assert playlist.is_premiere == self.is_premiere
        assert playlist.duration_ms == self.duration_ms
        assert playlist.og_image == self.og_image
        assert playlist.og_title == self.og_title
        assert playlist.og_description == self.og_description
        assert playlist.image == self.image
        assert playlist.cover_without_text == cover
        assert playlist.contest == contest
        assert playlist.background_color == self.background_color
        assert playlist.text_color == self.text_color
        assert playlist.id_for_from == self.id_for_from
        assert playlist.dummy_description == self.dummy_description
        assert playlist.dummy_page_description == self.dummy_page_description
        assert playlist.dummy_cover == cover
        assert playlist.dummy_rollover_cover == cover
        assert playlist.og_data == open_graph_data
        assert playlist.branding == brand
        assert playlist.metrika_id == self.metrika_id
        assert playlist.coauthors == self.coauthors
        assert playlist.top_artist == [artist]
        assert playlist.recent_tracks == [track_id]
        assert playlist.tracks == [track_short]
        assert playlist.prerolls == self.prerolls
        assert playlist.likes_count == self.likes_count
        assert playlist.similar_playlists == [playlist_without_nested_playlists]
        assert playlist.last_owner_playlists == [playlist_without_nested_playlists]
        assert playlist.generated_playlist_type == self.generated_playlist_type
        assert playlist.animated_cover_uri == self.animated_cover_uri
        assert playlist.ever_played == self.ever_played
        assert playlist.description == self.description
        assert playlist.description_formatted == self.description_formatted
        assert playlist.playlist_uuid == self.playlist_uuid
        assert playlist.type == self.type
        assert playlist.ready == self.ready
        assert playlist.is_for_from == self.is_for_from
        assert playlist.regions == self.regions
Beispiel #15
0
 def test_de_json_none(self, client):
     assert Playlist.de_json({}, client) is None
    def test_de_json_all(self, client, user, cover, made_for, track_short,
                         play_counter, playlist_absence):
        json_dict = {
            'owner': user.to_dict(),
            'uid': self.uid,
            'kind': self.kind,
            'title': self.title,
            'track_count': self.track_count,
            'cover': cover.to_dict(),
            'made_for': made_for.to_dict(),
            'play_counter': play_counter.to_dict(),
            'playlist_absence': playlist_absence.to_dict(),
            'tags': self.tags,
            'revision': self.revision,
            'snapshot': self.snapshot,
            'visibility': self.visibility,
            'collective': self.collective,
            'created': self.created,
            'modified': self.modified,
            'available': self.available,
            'is_banner': self.is_banner,
            'is_premiere': self.is_premiere,
            'duration_ms': self.duration_ms,
            'og_image': self.og_image,
            'tracks': [track_short.to_dict()],
            'prerolls': self.prerolls,
            'likes_count': self.likes_count,
            'generated_playlist_type': self.generated_playlist_type,
            'animated_cover_uri': self.animated_cover_uri,
            'ever_played': self.ever_played,
            'description': self.description,
            'description_formatted': self.description_formatted,
            'is_for_from': self.is_for_from,
            'regions': self.regions
        }
        playlist = Playlist.de_json(json_dict, client)

        assert playlist.owner == user
        assert playlist.uid == self.uid
        assert playlist.kind == self.kind
        assert playlist.title == self.title
        assert playlist.track_count == self.track_count
        assert playlist.cover == cover
        assert playlist.made_for == made_for
        assert playlist.play_counter == play_counter
        assert playlist.playlist_absence == playlist_absence
        assert playlist.tags == self.tags
        assert playlist.revision == self.revision
        assert playlist.snapshot == self.snapshot
        assert playlist.visibility == self.visibility
        assert playlist.collective == self.collective
        assert playlist.created == self.created
        assert playlist.modified == self.modified
        assert playlist.available == self.available
        assert playlist.is_banner == self.is_banner
        assert playlist.is_premiere == self.is_premiere
        assert playlist.duration_ms == self.duration_ms
        assert playlist.og_image == self.og_image
        assert playlist.tracks == [track_short]
        assert playlist.prerolls == self.prerolls
        assert playlist.likes_count == self.likes_count
        assert playlist.generated_playlist_type == self.generated_playlist_type
        assert playlist.animated_cover_uri == self.animated_cover_uri
        assert playlist.ever_played == self.ever_played
        assert playlist.description == self.description
        assert playlist.description_formatted == self.description_formatted
        assert playlist.is_for_from == self.is_for_from
        assert playlist.regions == self.regions