mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
Removed the `client_credentials_manager` and `oauth_manager` parameters because they are redundant. Replaced the `set_auth` and `auth_manager` properties with standard attributes. Removed the following deprecated methods from `Spotify`: * `playlist_tracks` * `user_playlist` * `user_playlist_tracks` * `user_playlist_change_details` * `user_playlist_unfollow` * `user_playlist_add_tracks` * `user_playlist_replace_tracks` * `user_playlist_reorder_tracks` * `user_playlist_remove_all_occurrences_of_tracks` * `user_playlist_remove_specific_occurrences_of_tracks` * `user_playlist_follow_playlist` * `user_playlist_is_following` Removed the deprecated `as_dict` parameter from the `get_access_token` method of `SpotifyOAuth` and `SpotifyPKCE`. Removed the deprecated `get_cached_token` and `_save_token_info` methods of `SpotifyOAuth` and `SpotifyPKCE`. Removed `SpotifyImplicitGrant`. Removed `prompt_for_user_token`.
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import argparse
|
|
import logging
|
|
|
|
import spotipy
|
|
from spotipy.oauth2 import SpotifyClientCredentials
|
|
|
|
|
|
logger = logging.getLogger('examples.artist_recommendations')
|
|
logging.basicConfig(level='INFO')
|
|
|
|
auth_manager = SpotifyClientCredentials()
|
|
sp = spotipy.Spotify(auth_manager=auth_manager)
|
|
|
|
|
|
def get_args():
|
|
parser = argparse.ArgumentParser(description='Recommendations for the '
|
|
'given artist')
|
|
parser.add_argument('-a', '--artist', required=True, help='Name of Artist')
|
|
return parser.parse_args()
|
|
|
|
|
|
def get_artist(name):
|
|
results = sp.search(q='artist:' + name, type='artist')
|
|
items = results['artists']['items']
|
|
if len(items) > 0:
|
|
return items[0]
|
|
else:
|
|
return None
|
|
|
|
|
|
def show_recommendations_for_artist(artist):
|
|
results = sp.recommendations(seed_artists=[artist['id']])
|
|
for track in results['tracks']:
|
|
logger.info('Recommendation: %s - %s', track['name'],
|
|
track['artists'][0]['name'])
|
|
|
|
|
|
def main():
|
|
args = get_args()
|
|
artist = get_artist(args.artist)
|
|
if artist:
|
|
show_recommendations_for_artist(artist)
|
|
else:
|
|
logger.error("Can't find that artist", args.artist)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|