How to use the tekore._client.base.SpotifyBase function in tekore

To help you get started, we’ve selected a few tekore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felix-hilden / spotipy / tekore / _client / api / browse / __init__.py View on Github external
from typing import List, Tuple

from .validate import validate_attributes
from ...base import SpotifyBase
from ...decor import send_and_process, maximise_limit, scopes
from ...process import single, top_item, multiple
from tekore.model import (
    SimplePlaylistPaging,
    SimpleAlbumPaging,
    CategoryPaging,
    Category,
    Recommendations
)


class SpotifyBrowse(SpotifyBase):
    """Browse API endpoints."""

    @scopes()
    @send_and_process(multiple(
        top_item('message'),
        single(SimplePlaylistPaging, from_item='playlists')
    ))
    @maximise_limit(50)
    def featured_playlists(
            self,
            country: str = None,
            locale: str = None,
            timestamp: str = None,
            limit: int = 20,
            offset: int = 0
    ) -> Tuple[str, SimplePlaylistPaging]:
github felix-hilden / spotipy / tekore / _client / api / playlist / view.py View on Github external
def parse_additional_types(as_tracks):
    """Determine `additional_types` argument content."""
    types = {'track', 'episode'}
    if as_tracks is True:
        types = set()
    elif as_tracks is False:
        pass
    else:
        types = types.difference(as_tracks)

    return ','.join(types) if types else None


class SpotifyPlaylistView(SpotifyBase):
    """Playlist API endpoints for viewing playlists."""

    @scopes(optional=[scope.playlist_read_private, scope.playlist_read_collaborative])
    @send_and_process(single(SimplePlaylistPaging))
    @maximise_limit(50)
    def followed_playlists(
            self,
            limit: int = 20,
            offset: int = 0
    ) -> SimplePlaylistPaging:
        """
        Get a list of the playlists owned or followed by the current user.

        Parameters
        ----------
        limit
github felix-hilden / spotipy / tekore / _client / api / search.py View on Github external
paging_type = {
    'artists': FullArtistOffsetPaging,
    'albums': SimpleAlbumPaging,
    'episodes': SimpleEpisodePaging,
    'playlists': SimplePlaylistPaging,
    'shows': SimpleShowPaging,
    'tracks': FullTrackPaging,
}


def search_result(json: dict):
    """Unpack search result dicts into respective paging type constructors."""
    return tuple(paging_type[key](**json[key]) for key in json.keys())


class SpotifySearch(SpotifyBase):
    """Search API endpoints."""

    @scopes()
    @send_and_process(search_result)
    @maximise_limit(50)
    def search(
            self,
            query: str,
            types: tuple = ('track',),
            market: str = None,
            include_external: str = None,
            limit: int = 20,
            offset: int = 0
    ) -> tuple:
        """
        Search for an item.
github felix-hilden / spotipy / tekore / _client / api / artist.py View on Github external
from typing import List, Union

from ..base import SpotifyBase
from ..decor import send_and_process, maximise_limit, scopes
from ..process import single, model_list
from ..chunked import chunked, join_lists
from tekore.model import (
    FullArtist,
    SimpleAlbumPaging,
    FullTrack,
    AlbumGroup,
    ModelList,
)


class SpotifyArtist(SpotifyBase):
    """Artist API endpoints."""

    @scopes()
    @send_and_process(single(FullArtist))
    def artist(self, artist_id: str) -> FullArtist:
        """
        Get information for an artist.

        Parameters
        ----------
        artist_id
            artist ID
        """
        return self._get('artists/' + artist_id)

    @scopes()
github felix-hilden / spotipy / tekore / _client / api / playlist / items.py View on Github external
from typing import List, Tuple

from tekore._auth import scope
from ...base import SpotifyBase
from ...decor import send_and_process, scopes
from ...process import top_item, nothing
from ...chunked import chunked, return_last


class SpotifyPlaylistItems(SpotifyBase):
    """Playlist API endpoints for manipulating playlist items."""

    @scopes([scope.playlist_modify_public], [scope.playlist_modify_private])
    @chunked('uris', 2, 100, return_last, reverse='position', reverse_pos=3)
    @send_and_process(top_item('snapshot_id'))
    def playlist_add(
            self,
            playlist_id: str,
            uris: list,
            position: int = None
    ) -> str:
        """
        Add items.

        Parameters
        ----------
github felix-hilden / spotipy / tekore / _client / api / player / modify.py View on Github external
def offset_to_dict(offset: Union[int, str]):
    """
    Parse playback start offset to an appropriate payload member.

    If offset is an integer, it is an index to a track position.
    If it is a string, it is a URI of a specific track.
    """
    if isinstance(offset, int):
        return {'position': offset}
    elif isinstance(offset, str):
        return {'uri': to_uri('track', offset)}


class SpotifyPlayerModify(SpotifyBase):
    """Player API endpoints that modify state."""

    @scopes([scope.user_modify_playback_state])
    @send_and_process(nothing)
    def playback_transfer(self, device_id: str, force_play: bool = False) -> None:
        """
        Transfer playback to another device.

        Parameters
        ----------
        device_id
            device to transfer playback to
        force_play
            true: play after transfer, false: keep current state
        """
        data = {
github felix-hilden / spotipy / tekore / _client / api / follow.py View on Github external
from typing import List

from ..base import SpotifyBase
from ..decor import send_and_process, maximise_limit, scopes
from ..process import single, nothing
from ..chunked import chunked, join_lists, return_none
from tekore._auth import scope
from tekore.model import FullArtistCursorPaging


class SpotifyFollow(SpotifyBase):
    """Follow API endpoints."""

    @scopes(optional=[scope.playlist_read_private])
    @chunked('user_ids', 2, 5, join_lists)
    @send_and_process(nothing)
    def playlist_is_following(self, playlist_id: str, user_ids: list) -> List[bool]:
        """
        Check if users are following a playlist.

        Parameters
        ----------
        playlist_id
            playlist ID
        user_ids
            list of user IDs, max 5 without chunking
github felix-hilden / spotipy / tekore / _client / api / player / view.py View on Github external
from ...process import single, model_list
from ...decor import send_and_process, maximise_limit, scopes
from ...base import SpotifyBase
from tekore._auth import scope
from tekore.model import (
    ModelList,
    CurrentlyPlayingContext,
    CurrentlyPlaying,
    PlayHistoryPaging,
    Device
)


class SpotifyPlayerView(SpotifyBase):
    """Player API endpoints that view state."""

    @scopes([scope.user_read_playback_state])
    @send_and_process(single(CurrentlyPlayingContext))
    def playback(
            self,
            market: str = None,
            tracks_only: bool = False
    ) -> CurrentlyPlayingContext:
        """
        Get information about user's current playback.

        Parameters
        ----------
        market
            an ISO 3166-1 alpha-2 country code or 'from_token'
github felix-hilden / spotipy / tekore / _client / api / show.py View on Github external
from ..base import SpotifyBase
from ..decor import send_and_process, maximise_limit, scopes
from ..process import single, model_list
from ..chunked import chunked, join_lists
from tekore._auth import scope
from tekore.model import FullShow, SimpleEpisodePaging, ModelList


class SpotifyShow(SpotifyBase):
    """Show API endpoints."""

    @scopes(optional=[scope.user_read_playback_position])
    @send_and_process(single(FullShow))
    def show(
            self,
            show_id: str,
            market: str = None
    ) -> FullShow:
        """
        Get information for a show.

        The user-read-playback-position scope allows
        episode resume points to be returned.

        Parameters
github felix-hilden / spotipy / tekore / _client / api / episode.py View on Github external
from ..base import SpotifyBase
from ..decor import send_and_process, scopes
from ..process import single, model_list
from ..chunked import chunked, join_lists
from tekore.model import FullEpisode, ModelList


class SpotifyEpisode(SpotifyBase):
    """Episode API endpoints."""

    @scopes()
    @send_and_process(single(FullEpisode))
    def episode(
            self,
            episode_id: str,
            market: str = None
    ) -> FullEpisode:
        """
        Get information for an episode.

        Parameters
        ----------
        episode_id
            episode ID