mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-10-12 01:10:45 +00:00
Deprecate util.prompt_for_user_token()
This commit is contained in:
1 parent
587baec9b9
commit
c7f2edf343
26 files changed
+254
-477
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
logger = logging.getLogger('examples.add_a_saved_album')
|
||||
logging.basicConfig(level='DEBUG')
|
||||
@@ -13,9 +12,6 @@ scope = 'user-library-modify'
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Creates a playlist for user')
|
||||
parser.add_argument('-u', '--username', required=False,
|
||||
default=os.environ.get('SPOTIPY_CLIENT_USERNAME'),
|
||||
help='Username id. Defaults to environment var')
|
||||
parser.add_argument('-a', '--aids', action='append',
|
||||
required=True, help='Album ids')
|
||||
return parser.parse_args()
|
||||
@@ -23,13 +19,8 @@ def get_args():
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
token = util.prompt_for_user_token(args.username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.current_user_saved_albums_add(albums=args.aids)
|
||||
else:
|
||||
logger.error("Can't get token for %s", args.username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
sp.current_user_saved_albums_add(albums=args.aids)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-library-modify'
|
||||
|
||||
@@ -14,9 +13,6 @@ logging.basicConfig(level='DEBUG')
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Add tracks to Your '
|
||||
'Collection of saved tracks')
|
||||
parser.add_argument('-u', '--username', required=False,
|
||||
default=os.environ.get('SPOTIPY_CLIENT_USERNAME'),
|
||||
help='Username id. Defaults to environment var')
|
||||
parser.add_argument('-t', '--tids', action='append',
|
||||
required=True, help='Track ids')
|
||||
return parser.parse_args()
|
||||
@@ -24,13 +20,9 @@ def get_args():
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
token = util.prompt_for_user_token(args.username, scope)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.current_user_saved_tracks_add(tracks=args.tids)
|
||||
else:
|
||||
logger.error("Can't get token for %s", args.username)
|
||||
sp.current_user_saved_tracks_add(tracks=args.tids)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
logger = logging.getLogger('examples.add_tracks_to_playlist')
|
||||
logging.basicConfig(level='DEBUG')
|
||||
@@ -12,9 +11,6 @@ scope = 'playlist-modify-public'
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Adds track to user playlist')
|
||||
parser.add_argument('-u', '--username', required=False,
|
||||
default=os.environ.get('SPOTIPY_CLIENT_USERNAME'),
|
||||
help='Username id. Defaults to environment var')
|
||||
parser.add_argument('-t', '--tids', action='append',
|
||||
required=True, help='Track ids')
|
||||
parser.add_argument('-p', '--playlist', required=True,
|
||||
@@ -24,13 +20,10 @@ def get_args():
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
token = util.prompt_for_user_token(args.username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.user_playlist_add_tracks(args.username, args.playlist, args.tids)
|
||||
else:
|
||||
logger.error("Can't get token for %s", args.username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
user_id = sp.me()['id']
|
||||
sp.user_playlist_add_tracks(user_id, args.playlist, args.tids)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
logger = logging.getLogger('examples.change_playlist_details')
|
||||
logging.basicConfig(level='DEBUG')
|
||||
@@ -13,9 +12,6 @@ scope = 'playlist-modify-public playlist-modify-private'
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Modify details of playlist')
|
||||
parser.add_argument('-u', '--username', required=False,
|
||||
default=os.environ.get('SPOTIPY_CLIENT_USERNAME'),
|
||||
help='Username id. Defaults to environment var')
|
||||
parser.add_argument('-p', '--playlist', required=True,
|
||||
help='Playlist id to alter details')
|
||||
parser.add_argument('-n', '--name', required=False,
|
||||
@@ -38,16 +34,14 @@ def get_args():
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
token = util.prompt_for_user_token(args.username, scope)
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.user_playlist_change_details(
|
||||
args.username, args.playlist, name=args.name,
|
||||
public=args.public or args.private,
|
||||
collaborative=args.collaborative or args.independent,
|
||||
description=args.description)
|
||||
else:
|
||||
logger.error("Can't get token for %s", args.username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
sp.user_playlist_change_details(
|
||||
args.username,
|
||||
args.playlist,
|
||||
name=args.name,
|
||||
public=args.public or args.private,
|
||||
collaborative=args.collaborative or args.independent,
|
||||
description=args.description)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,23 +2,16 @@ import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-library-read'
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
username = sys.argv[1]
|
||||
tids = sys.argv[2:]
|
||||
if len(sys.argv) > 1:
|
||||
tids = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username track-id ..." % (sys.argv[0],))
|
||||
print("Usage: %s track-id ..." % (sys.argv[0],))
|
||||
sys.exit()
|
||||
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.current_user_saved_tracks_contains(tracks=tids)
|
||||
results = spotipy.current_user_saved_tracks_contains(tracks=tids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Creates a playlist for a user
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
logger = logging.getLogger('examples.create_playlist')
|
||||
logging.basicConfig(level='DEBUG')
|
||||
@@ -12,9 +12,6 @@ logging.basicConfig(level='DEBUG')
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(description='Creates a playlist for user')
|
||||
parser.add_argument('-u', '--username', required=False,
|
||||
default=os.environ.get('SPOTIPY_CLIENT_USERNAME'),
|
||||
help='Username id. Defaults to environment var')
|
||||
parser.add_argument('-p', '--playlist', required=True,
|
||||
help='Name of Playlist')
|
||||
parser.add_argument('-d', '--description', required=False, default='',
|
||||
@@ -25,14 +22,9 @@ def get_args():
|
||||
def main():
|
||||
args = get_args()
|
||||
scope = "playlist-modify-public"
|
||||
token = util.prompt_for_user_token(args.username, scope)
|
||||
|
||||
if token:
|
||||
logger.info('USERNAME: %s, PLAYLIST: %s', args.username, args.playlist)
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.user_playlist_create(args.username, args.playlist)
|
||||
else:
|
||||
logger.error("Can't get token for: %s", args.username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
user_id = sp.me()['id']
|
||||
sp.user_playlist_create(user_id, args.playlist)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -4,23 +4,16 @@ import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-library-modify'
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
username = sys.argv[1]
|
||||
tids = sys.argv[2:]
|
||||
if len(sys.argv) > 1:
|
||||
tids = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username track-id ..." % (sys.argv[0],))
|
||||
print("Usage: %s track-id ..." % (sys.argv[0],))
|
||||
sys.exit()
|
||||
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
results = sp.current_user_saved_tracks_delete(tracks=tids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
@@ -1,24 +1,10 @@
|
||||
# Shows a user's playlists
|
||||
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username" % (sys.argv[0],))
|
||||
sys.exit()
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
|
||||
|
||||
scope = ''
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.current_user_playlists(limit=50)
|
||||
for i, item in enumerate(results['items']):
|
||||
print("%d %s" % (i, item['name']))
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
results = sp.current_user_playlists(limit=50)
|
||||
for i, item in enumerate(results['items']):
|
||||
print("%d %s" % (i, item['name']))
|
||||
+12
-23
@@ -1,28 +1,17 @@
|
||||
# Shows the top artists for a user
|
||||
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username" % (sys.argv[0],))
|
||||
sys.exit()
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-top-read'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
ranges = ['short_term', 'medium_term', 'long_term']
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
ranges = ['short_term', 'medium_term', 'long_term']
|
||||
for range in ranges:
|
||||
print("range:", range)
|
||||
results = sp.current_user_top_artists(time_range=range, limit=50)
|
||||
for i, item in enumerate(results['items']):
|
||||
print(i, item['name'])
|
||||
print()
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
for sp_range in ['short_term', 'medium_term', 'long_term']:
|
||||
print("range:", sp_range)
|
||||
|
||||
results = sp.current_user_top_artists(time_range=sp_range, limit=50)
|
||||
|
||||
for i, item in enumerate(results['items']):
|
||||
print(i, item['name'])
|
||||
print()
|
||||
@@ -3,7 +3,7 @@
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
@@ -12,18 +12,13 @@ else:
|
||||
sys.exit()
|
||||
|
||||
scope = 'user-top-read'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
ranges = ['short_term', 'medium_term', 'long_term']
|
||||
for range in ranges:
|
||||
print("range:", range)
|
||||
results = sp.current_user_top_tracks(time_range=range, limit=50)
|
||||
for i, item in enumerate(results['items']):
|
||||
print(i, item['name'], '//', item['artists'][0]['name'])
|
||||
print()
|
||||
ranges = ['short_term', 'medium_term', 'long_term']
|
||||
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
for sp_range in ranges:
|
||||
print("range:", sp_range)
|
||||
results = sp.current_user_top_tracks(time_range=sp_range, limit=50)
|
||||
for i, item in enumerate(results['items']):
|
||||
print(i, item['name'], '//', item['artists'][0]['name'])
|
||||
print()
|
||||
@@ -1,17 +1,16 @@
|
||||
# removes tracks from a playlist
|
||||
# Removes tracks from a playlist
|
||||
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
username = sys.argv[1]
|
||||
playlist_id = sys.argv[2]
|
||||
track_ids_and_positions = sys.argv[3:]
|
||||
if len(sys.argv) > 2:
|
||||
playlist_id = sys.argv[1]
|
||||
track_ids_and_positions = sys.argv[2:]
|
||||
track_ids = []
|
||||
for t_pos in sys.argv[3:]:
|
||||
for t_pos in sys.argv[2:]:
|
||||
tid, pos = t_pos.split(',')
|
||||
track_ids.append({"uri": tid, "positions": [int(pos)]})
|
||||
else:
|
||||
@@ -21,13 +20,10 @@ else:
|
||||
sys.exit()
|
||||
|
||||
scope = 'playlist-modify-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_remove_specific_occurrences_of_tracks(
|
||||
username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_remove_specific_occurrences_of_tracks(
|
||||
user_id, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
@@ -1,27 +1,24 @@
|
||||
# removes tracks to a playlist
|
||||
|
||||
# Removes tracks from playlist
|
||||
import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
username = sys.argv[1]
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
playlist_id = sys.argv[2]
|
||||
track_ids = sys.argv[3:]
|
||||
else:
|
||||
print("Usage: %s username playlist_id track_id ..." % (sys.argv[0],))
|
||||
print("Usage: %s playlist_id track_id ..." % (sys.argv[0]))
|
||||
sys.exit()
|
||||
|
||||
scope = 'playlist-modify-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_remove_all_occurrences_of_tracks(
|
||||
username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_remove_all_occurrences_of_tracks(
|
||||
user_id, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
@@ -4,23 +4,20 @@ import pprint
|
||||
import sys
|
||||
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
username = sys.argv[1]
|
||||
playlist_id = sys.argv[2]
|
||||
track_ids = sys.argv[3:]
|
||||
playlist_id = sys.argv[1]
|
||||
track_ids = sys.argv[2:]
|
||||
else:
|
||||
print("Usage: %s username playlist_id track_id ..." % (sys.argv[0],))
|
||||
sys.exit()
|
||||
|
||||
scope = 'playlist-modify-public'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
results = sp.user_playlist_replace_tracks(username, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
user_id = sp.me()['id']
|
||||
|
||||
results = sp.user_playlist_replace_tracks(user_id, playlist_id, track_ids)
|
||||
pprint.pprint(results)
|
||||
|
||||
@@ -1,32 +1,19 @@
|
||||
# shows artist info for a URN or URL
|
||||
|
||||
import spotipy
|
||||
import sys
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Whoops, need your username!")
|
||||
print("usage: python featured_playlists.py [username]")
|
||||
sys.exit()
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
|
||||
|
||||
token = util.prompt_for_user_token(username)
|
||||
response = sp.featured_playlists()
|
||||
print(response['message'])
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
while response:
|
||||
playlists = response['playlists']
|
||||
for i, item in enumerate(playlists['items']):
|
||||
print(playlists['offset'] + i, item['name'])
|
||||
|
||||
response = sp.featured_playlists()
|
||||
print(response['message'])
|
||||
|
||||
while response:
|
||||
playlists = response['playlists']
|
||||
for i, item in enumerate(playlists['items']):
|
||||
print(playlists['offset'] + i, item['name'])
|
||||
|
||||
if playlists['next']:
|
||||
response = sp.next(playlists)
|
||||
else:
|
||||
response = None
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
if playlists['next']:
|
||||
response = sp.next(playlists)
|
||||
else:
|
||||
response = None
|
||||
@@ -1,17 +1,10 @@
|
||||
# shows a user's saved tracks (need to be authenticated via oauth)
|
||||
# Shows a user's saved tracks (need to be authenticated via oauth)
|
||||
|
||||
import sys
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-library-read'
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username" % (sys.argv[0],))
|
||||
sys.exit()
|
||||
|
||||
|
||||
def show_tracks(results):
|
||||
for item in results['items']:
|
||||
@@ -19,14 +12,11 @@ def show_tracks(results):
|
||||
print("%32.32s %s" % (track['artists'][0]['name'], track['name']))
|
||||
|
||||
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
results = sp.current_user_saved_tracks()
|
||||
results = sp.current_user_saved_tracks()
|
||||
show_tracks(results)
|
||||
|
||||
while results['next']:
|
||||
results = sp.next(results)
|
||||
show_tracks(results)
|
||||
while results['next']:
|
||||
results = sp.next(results)
|
||||
show_tracks(results)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
@@ -1,31 +1,18 @@
|
||||
# shows artist info for a URN or URL
|
||||
|
||||
import spotipy
|
||||
import sys
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Whoops, need your username!")
|
||||
print("usage: python new_releases.py [username]")
|
||||
sys.exit()
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
|
||||
|
||||
token = util.prompt_for_user_token(username)
|
||||
response = sp.new_releases()
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
while response:
|
||||
albums = response['albums']
|
||||
for i, item in enumerate(albums['items']):
|
||||
print(albums['offset'] + i, item['name'])
|
||||
|
||||
response = sp.new_releases()
|
||||
|
||||
while response:
|
||||
albums = response['albums']
|
||||
for i, item in enumerate(albums['items']):
|
||||
print(albums['offset'] + i, item['name'])
|
||||
|
||||
if albums['next']:
|
||||
response = sp.next(albums)
|
||||
else:
|
||||
response = None
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
if albums['next']:
|
||||
response = sp.next(albums)
|
||||
else:
|
||||
response = None
|
||||
@@ -0,0 +1,11 @@
|
||||
import spotipy
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = "user-library-read"
|
||||
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
results = sp.current_user_saved_tracks()
|
||||
for idx, item in enumerate(results['items']):
|
||||
track = item['track']
|
||||
print(idx, track['artists'][0]['name'], " – ", track['name'])
|
||||
@@ -1,25 +1,10 @@
|
||||
# shows a user's playlists (need to be authenticated via oauth)
|
||||
|
||||
import sys
|
||||
# Shows a user's playlists (need to be authenticated via oauth)
|
||||
|
||||
import spotipy
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
import spotipy.util as util
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
|
||||
playlists = sp.current_user_playlists()
|
||||
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Whoops, need your username!")
|
||||
print("usage: python user_playlists.py [username]")
|
||||
sys.exit()
|
||||
|
||||
token = util.prompt_for_user_token(username)
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
playlists = sp.user_playlists(username)
|
||||
for playlist in playlists['items']:
|
||||
print(playlist['name'])
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
for playlist in playlists['items']:
|
||||
print(playlist['name'])
|
||||
@@ -1,8 +1,7 @@
|
||||
# shows a user's playlists (need to be authenticated via oauth)
|
||||
# Shows a user's playlists (need to be authenticated via oauth)
|
||||
|
||||
import sys
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
|
||||
def show_tracks(results):
|
||||
@@ -14,28 +13,21 @@ def show_tracks(results):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Whoops, need your username!")
|
||||
print("usage: python user_playlists_contents.py [username]")
|
||||
sys.exit()
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth())
|
||||
|
||||
token = util.prompt_for_user_token(username)
|
||||
playlists = sp.current_user_playlists()
|
||||
user_id = sp.me()['id']
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
playlists = sp.user_playlists(username)
|
||||
for playlist in playlists['items']:
|
||||
if playlist['owner']['id'] == username:
|
||||
print()
|
||||
print(playlist['name'])
|
||||
print(' total tracks', playlist['tracks']['total'])
|
||||
results = sp.playlist(playlist['id'], fields="tracks,next")
|
||||
tracks = results['tracks']
|
||||
for playlist in playlists['items']:
|
||||
if playlist['owner']['id'] == user_id:
|
||||
print()
|
||||
print(playlist['name'])
|
||||
print(' total tracks', playlist['tracks']['total'])
|
||||
|
||||
results = sp.playlist(playlist['id'], fields="tracks,next")
|
||||
tracks = results['tracks']
|
||||
show_tracks(tracks)
|
||||
|
||||
while tracks['next']:
|
||||
tracks = sp.next(tracks)
|
||||
show_tracks(tracks)
|
||||
while tracks['next']:
|
||||
tracks = sp.next(tracks)
|
||||
show_tracks(tracks)
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
@@ -1,28 +1,12 @@
|
||||
"""
|
||||
Deletes user saved album
|
||||
# Deletes user saved album
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import spotipy
|
||||
import spotipy.util as util
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
username = sys.argv[1]
|
||||
else:
|
||||
print("Usage: %s username" % (sys.argv[0],))
|
||||
sys.exit()
|
||||
from spotipy.oauth2 import SpotifyOAuth
|
||||
|
||||
scope = 'user-library-modify'
|
||||
token = util.prompt_for_user_token(username, scope)
|
||||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
|
||||
|
||||
if token:
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
sp.trace = False
|
||||
uris = input("input a list of album URIs, URLs or IDs: ")
|
||||
uris = list(map(str, uris.split()))
|
||||
deleted = sp.current_user_saved_albums_delete(uris)
|
||||
print("Deletion successful.")
|
||||
|
||||
else:
|
||||
print("Can't get token for", username)
|
||||
uris = input("input a list of album URIs, URLs or IDs: ")
|
||||
uris = list(map(str, uris.split()))
|
||||
deleted = sp.current_user_saved_albums_delete(uris)
|
||||
print("Deletion successful.")
|
||||
Reference in new issue
Block a user