mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
commit
9b3b61bdc4
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
# Adds tracks to a playlist
|
# Adds tracks to a playlist
|
||||||
|
|
||||||
import pprint
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
|
|||||||
@ -20,7 +20,7 @@ def show_artist_albums(artist):
|
|||||||
results = sp.next(results)
|
results = sp.next(results)
|
||||||
albums.extend(results['items'])
|
albums.extend(results['items'])
|
||||||
seen = set() # to avoid dups
|
seen = set() # to avoid dups
|
||||||
albums.sort(key=lambda album:album['name'].lower())
|
albums.sort(key=lambda album: album['name'].lower())
|
||||||
for album in albums:
|
for album in albums:
|
||||||
name = album['name']
|
name = album['name']
|
||||||
if name not in seen:
|
if name not in seen:
|
||||||
|
|||||||
@ -19,7 +19,7 @@ def get_artist(name):
|
|||||||
|
|
||||||
def show_recommendations_for_artist(artist):
|
def show_recommendations_for_artist(artist):
|
||||||
albums = []
|
albums = []
|
||||||
results = sp.recommendations(seed_artists = [artist['id']])
|
results = sp.recommendations(seed_artists=[artist['id']])
|
||||||
for track in results['tracks']:
|
for track in results['tracks']:
|
||||||
print track['name'], '-', track['artists'][0]['name']
|
print track['name'], '-', track['artists'][0]['name']
|
||||||
|
|
||||||
|
|||||||
@ -20,4 +20,4 @@ start = time.time()
|
|||||||
analysis = sp.audio_analysis(tid)
|
analysis = sp.audio_analysis(tid)
|
||||||
delta = time.time() - start
|
delta = time.time() - start
|
||||||
print(json.dumps(analysis, indent=4))
|
print(json.dumps(analysis, indent=4))
|
||||||
print ("analysis retrieved in %.2f seconds" % (delta,))
|
print("analysis retrieved in %.2f seconds" % (delta,))
|
||||||
|
|||||||
@ -33,4 +33,4 @@ for feature in features:
|
|||||||
analysis = sp._get(feature['analysis_url'])
|
analysis = sp._get(feature['analysis_url'])
|
||||||
print(json.dumps(analysis, indent=4))
|
print(json.dumps(analysis, indent=4))
|
||||||
print()
|
print()
|
||||||
print ("features retrieved in %.2f seconds" % (delta,))
|
print("features retrieved in %.2f seconds" % (delta,))
|
||||||
|
|||||||
@ -22,4 +22,4 @@ if len(sys.argv) > 1:
|
|||||||
features = sp.audio_features(tids)
|
features = sp.audio_features(tids)
|
||||||
delta = time.time() - start
|
delta = time.time() - start
|
||||||
print(json.dumps(features, indent=4))
|
print(json.dumps(features, indent=4))
|
||||||
print ("features retrieved in %.2f seconds" % (delta,))
|
print("features retrieved in %.2f seconds" % (delta,))
|
||||||
|
|||||||
@ -24,7 +24,7 @@ if len(sys.argv) > 3:
|
|||||||
description = sys.argv[6]
|
description = sys.argv[6]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print ("Usage: %s username playlist_id name [public collaborative "
|
print("Usage: %s username playlist_id name [public collaborative "
|
||||||
"description]" % (sys.argv[0]))
|
"description]" % (sys.argv[0]))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import pprint
|
import pprint
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
import spotipy.util as util
|
import spotipy.util as util
|
||||||
|
|||||||
@ -2,22 +2,19 @@
|
|||||||
|
|
||||||
from __future__ import print_function # (at top of module)
|
from __future__ import print_function # (at top of module)
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
import json
|
|
||||||
import spotipy
|
import spotipy
|
||||||
import time
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
client_credentials_manager = SpotifyClientCredentials()
|
client_credentials_manager = SpotifyClientCredentials()
|
||||||
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||||
sp.trace=True
|
sp.trace=True
|
||||||
try:
|
try:
|
||||||
print ('bad call 0')
|
print('bad call 0')
|
||||||
bad_artist_call = sp.artist('spotify:artist:12341234')
|
bad_artist_call = sp.artist('spotify:artist:12341234')
|
||||||
except spotipy.client.SpotifyException:
|
except spotipy.client.SpotifyException:
|
||||||
print ('bad call 0 exception' )
|
print('bad call 0 exception')
|
||||||
|
|
||||||
print ('bad call 1')
|
print('bad call 1')
|
||||||
bad_artist_call = sp.artist('spotify:artist:12341234')
|
bad_artist_call = sp.artist('spotify:artist:12341234')
|
||||||
print ('bad artist', bad_artist_call)
|
print('bad artist', bad_artist_call)
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
# Shows a user's playlists
|
# Shows a user's playlists
|
||||||
|
|
||||||
import pprint
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
import spotipy.util as util
|
import spotipy.util as util
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
|
|||||||
@ -10,10 +10,10 @@ if len(sys.argv) > 3:
|
|||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
playlist_id = sys.argv[2]
|
playlist_id = sys.argv[2]
|
||||||
track_ids_and_positions = sys.argv[3:]
|
track_ids_and_positions = sys.argv[3:]
|
||||||
track_ids = [ ]
|
track_ids = []
|
||||||
for t_pos in sys.argv[3:]:
|
for t_pos in sys.argv[3:]:
|
||||||
tid, pos = t_pos.split(',')
|
tid, pos = t_pos.split(',')
|
||||||
track_ids.append( { "uri" : tid, "positions": [ int(pos)] } )
|
track_ids.append({"uri": tid, "positions": [int(pos)]})
|
||||||
else:
|
else:
|
||||||
print("Usage: %s username playlist_id track_id,pos track_id,pos ..." % (sys.argv[0],))
|
print("Usage: %s username playlist_id track_id,pos track_id,pos ..." % (sys.argv[0],))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import spotipy
|
import spotipy
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
import sys
|
import sys
|
||||||
import pprint
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
urn = sys.argv[1]
|
urn = sys.argv[1]
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
import sys
|
import sys
|
||||||
import pprint
|
|
||||||
import spotipy.util as util
|
import spotipy.util as util
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
import sys
|
import sys
|
||||||
import pprint
|
|
||||||
import spotipy.util as util
|
import spotipy.util as util
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
@ -22,7 +21,7 @@ if token:
|
|||||||
while response:
|
while response:
|
||||||
albums = response['albums']
|
albums = response['albums']
|
||||||
for i, item in enumerate(albums['items']):
|
for i, item in enumerate(albums['items']):
|
||||||
print(albums['offset'] + i,item['name'])
|
print(albums['offset'] + i, item['name'])
|
||||||
|
|
||||||
if albums['next']:
|
if albums['next']:
|
||||||
response = sp.next(albums)
|
response = sp.next(albums)
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
import spotipy
|
import spotipy
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
import sys
|
import sys
|
||||||
import pprint
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
artist_name = sys.argv[1]
|
artist_name = sys.argv[1]
|
||||||
|
|||||||
@ -21,7 +21,7 @@ def find_songs_that_start_with_word(word):
|
|||||||
|
|
||||||
out = []
|
out = []
|
||||||
while offset < max_offset and len(out) < max_titles:
|
while offset < max_offset and len(out) < max_titles:
|
||||||
results = sp.search(q=word, type = 'track', limit=50, offset = offset)
|
results = sp.search(q=word, type='track', limit=50, offset=offset)
|
||||||
if len(results['tracks']['items']) == 0:
|
if len(results['tracks']['items']) == 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
# shows a user's playlists (need to be authenticated via oauth)
|
# shows a user's playlists (need to be authenticated via oauth)
|
||||||
|
|
||||||
import pprint
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import spotipy
|
import spotipy
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ if token:
|
|||||||
while tracks:
|
while tracks:
|
||||||
for item in tracks['items']:
|
for item in tracks['items']:
|
||||||
track = item['track']
|
track = item['track']
|
||||||
print(which, track['name' ], ' --', track['artists'][0]['name'])
|
print(which, track['name'], ' --', track['artists'][0]['name'])
|
||||||
which += 1
|
which += 1
|
||||||
tracks = sp.next(tracks)
|
tracks = sp.next(tracks)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user