Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added objects #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='spotipy',
version='2.18.0',
version='2.18.1',
description='A light weight Python library for the Spotify Web API',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
62 changes: 60 additions & 2 deletions spotipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import urllib3

from spotipy.exceptions import SpotifyException
from spotipy.objects import *

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -438,15 +439,14 @@ def album_tracks(self, album_id, limit=50, offset=0, market=None):
trid = self._get_id("album", album_id)
return self._get(
"albums/" + trid + "/tracks/", limit=limit, offset=offset, market=market
)
)['items']

def albums(self, albums):
""" returns a list of albums given the album IDs, URIs, or URLs

Parameters:
- albums - a list of album IDs, URIs or URLs
"""

tlist = [self._get_id("album", a) for a in albums]
return self._get("albums/?ids=" + ",".join(tlist))

Expand Down Expand Up @@ -548,6 +548,64 @@ def search(self, q, limit=10, offset=0, type="track", market=None):
"search", q=q, limit=limit, offset=offset, type=type, market=market
)

def search_artists(self, q, limit=10, offset=0, market=None):
""" searches for an artist

Parameters:
- q - the search query (see how to write a query in the
official documentation https://developer.spotify.com/documentation/web-api/reference/search/) # noqa
- limit - the number of items to return (min = 1, default = 10, max = 50). The limit is applied
within each type, not on the total response.
- offset - the index of the first item to return

- market - An ISO 3166-1 alpha-2 country code or the string
from_token.
"""
results = self._get(
"search", q=q, limit=limit, offset=offset, type="artist", market=market
)['artists']['items']
for item in results:
yield Artist(self, item)

def search_albums(self, q, limit=10, offset=0, market=None):
""" searches for an album

Parameters:
- q - the search query (see how to write a query in the
official documentation https://developer.spotify.com/documentation/web-api/reference/search/) # noqa
- limit - the number of items to return (min = 1, default = 10, max = 50). The limit is applied
within each type, not on the total response.
- offset - the index of the first item to return

- market - An ISO 3166-1 alpha-2 country code or the string
from_token.
"""
results = self._get(
"search", q=q, limit=limit, offset=offset, type="album", market=market
)['albums']['items']
for item in results:
yield Album(self, item)

def search_tracks(self, q, limit=10, offset=0, market=None):
""" searches for an artist

Parameters:
- q - the search query (see how to write a query in the
official documentation https://developer.spotify.com/documentation/web-api/reference/search/) # noqa
- limit - the number of items to return (min = 1, default = 10, max = 50). The limit is applied
within each type, not on the total response.
- offset - the index of the first item to return

- market - An ISO 3166-1 alpha-2 country code or the string
from_token.
"""
results = self._get(
"search", q=q, limit=limit, offset=offset, type="track", market=market
)['tracks']['items']
for item in results:
yield Track(self, item)


def search_markets(self, q, limit=10, offset=0, type="track", markets=None, total=None):
""" (experimental) Searches multiple markets for an item

Expand Down
Loading