Guest User

Untitled

a guest
Mar 18th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import spotipy
  3. from spotipy.oauth2 import SpotifyClientCredentials
  4.  
  5. def credintials_process():
  6. client_id = '------------------------'
  7. client_secret = '------------------------'
  8. client_credentials_manager = spotipy.oauth2.SpotifyClientCredentials(client_id, client_secret)
  9. client_credentials_manager.get_access_token()
  10. sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
  11. return sp
  12.  
  13. def get_artist_id(name=None):
  14. results = sp.search(q='artist:' + name, type='artist')
  15. for item in results['artists']['items']:
  16. print("{0}: {1}, popularity: {2}".format(item['name'], item['id'], item['popularity']))
  17. return results
  18.  
  19. # アーティストからアルバムidを取得
  20. def get_all_albums(artist_id=None):
  21. sp = credintials_process()
  22. artist_name = sp.artist(artist_id)['name']
  23. print("{0}の曲を取得します".format(artist_name))
  24.  
  25. albums = sp.artist_albums(artist_id)
  26. album_list = []
  27. for album in albums['items']:
  28. album_list.append(album['id'])
  29. return album_list
  30.  
  31. # アルバムidからtrack_nameを取得
  32. def get_all_tracks(album_id=None):
  33. sp = credintials_process()
  34. tracks = sp.album_tracks(album_id)
  35. track_list = []
  36. for track in tracks['items']:
  37. track_list.append(track['name'])
  38. return track_list
Add Comment
Please, Sign In to add comment