From 1c1b84c1fa03fbce2901e7d126e6e730817cb183 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Mon, 7 Jul 2014 17:25:19 +0200 Subject: [PATCH] Added support for related artists --- CHANGES.txt | 2 +- README.md | 6 ++++++ examples/show_related.py | 26 ++++++++++++++++++++++++++ spotipy/__init__.py | 7 +++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 examples/show_related.py diff --git a/CHANGES.txt b/CHANGES.txt index 5b438d0..efec693 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,5 +2,5 @@ v1.40, June 12, 2014 -- Initial public release. v1.42, June 19, 2014 -- Removed dependency on simplejson v1.43, June 27, 2014 -- Fixed JSON handling issue v1.44, July 3, 2014 -- Added show_tracks.py exampole -v1.45, July 7, 2014 -- Don't used cache auth codes when scope changes +v1.45, July 7, 2014 -- Support for related artists endpoint. Don't used cache auth codes when scope changes diff --git a/README.md b/README.md index 95e9a9c..af045d3 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,9 @@ at [paul@echonest.com](mailto:paul@echonest.com). Or just send me a pull request - 1.4.1 - 06/17/2014 - Updates to match released API - 1.4.2 - 06/21/2014 - Added support for retrieving starred playlists + - v1.40, June 12, 2014 -- Initial public release. + - v1.42, June 19, 2014 -- Removed dependency on simplejson + - v1.43, June 27, 2014 -- Fixed JSON handling issue + - v1.44, July 3, 2014 -- Added show_tracks.py example + - v1.45, July 7, 2014 -- Support for related artists endpoint. Don't used cache auth codes when scope changes + diff --git a/examples/show_related.py b/examples/show_related.py new file mode 100644 index 0000000..4818877 --- /dev/null +++ b/examples/show_related.py @@ -0,0 +1,26 @@ + +# shows related artists for the given seed artist + +import spotipy +import sys +import pprint + +if len(sys.argv) > 1: + artist_name = sys.argv[1] +else: + artist_name = 'weezer' + +sp = spotipy.Spotify() +result = sp.search(q='artist:' + artist_name, type='artist') +try: + name = result['artists']['items'][0]['name'] + uri = result['artists']['items'][0]['uri'] + + related = sp.artist_related_artists(uri) + print 'related artists for', name + for artist in related['artists']: + print ' ', artist['name'] +except: + raise + print "usage show_related.py [artist-name]" + diff --git a/spotipy/__init__.py b/spotipy/__init__.py index 65c6102..f944304 100644 --- a/spotipy/__init__.py +++ b/spotipy/__init__.py @@ -167,6 +167,13 @@ class Spotify(object): trid = self._get_id('artist', artist_id) return self.get('artists/' + trid + '/top-tracks', country=country) + def artist_related_artists(self, artist_id): + ''' Get Spotify catalog information about artists similar to an identified artist. Similarity is based + on analysis of the Spotify community’s listening history. + ''' + trid = self._get_id('artist', artist_id) + return self.get('artists/' + trid + '/related-artists') + def album(self, album_id): ''' returns a single album given the album's ID, URN or URL '''