2015-12-30 21:11:27 +00:00
|
|
|
|
|
|
|
# shows acoustic features for tracks for the given artist
|
|
|
|
|
|
|
|
from __future__ import print_function # (at top of module)
|
|
|
|
from spotipy.oauth2 import SpotifyClientCredentials
|
|
|
|
import json
|
|
|
|
import spotipy
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
client_credentials_manager = SpotifyClientCredentials()
|
|
|
|
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
2016-02-20 13:54:11 +00:00
|
|
|
sp.trace=False
|
2015-12-30 21:11:27 +00:00
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
artist_name = ' '.join(sys.argv[1:])
|
|
|
|
results = sp.search(q=artist_name, limit=50)
|
|
|
|
tids = []
|
|
|
|
for i, t in enumerate(results['tracks']['items']):
|
|
|
|
print(' ', i, t['name'])
|
|
|
|
tids.append(t['uri'])
|
|
|
|
|
|
|
|
start = time.time()
|
|
|
|
features = sp.audio_features(tids)
|
|
|
|
delta = time.time() - start
|
2016-12-31 12:49:19 +00:00
|
|
|
for feature in features:
|
|
|
|
print(json.dumps(feature, indent=4))
|
|
|
|
print()
|
|
|
|
analysis = sp._get(feature['analysis_url'])
|
|
|
|
print(json.dumps(analysis, indent=4))
|
|
|
|
print()
|
2015-12-30 21:11:27 +00:00
|
|
|
print ("features retrieved in %.2f seconds" % (delta,))
|