How to use the spotipy.util.prompt_for_user_token function in spotipy

To help you get started, we’ve selected a few spotipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plamere / spotipy / tests / authtests.py View on Github external
self.assertTrue(playlist['tracks']['total'] == 3)
        self.assertTrue(len(playlist['tracks']['items']) == 3)

if __name__ == '__main__':
    if len(sys.argv) > 1:
        username = sys.argv[1]
        del sys.argv[1]

        scope = 'playlist-modify-public '
        scope += 'user-library-read '
        scope += 'user-follow-read '
        scope += 'user-library-modify '
        scope += 'user-read-private '
        scope += 'user-top-read'

        token = util.prompt_for_user_token(username, scope)
        spotify = spotipy.Spotify(auth=token)
        spotify.trace = False
        unittest.main()
    else:
        print("Usage: %s username" % (sys.argv[0],))
github plamere / spotipy / examples / show_new_releases.py View on Github external
# shows artist info for a URN or URL

import spotipy
import sys
import pprint
import spotipy.util as util

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print("Whoops, need your username!")
    print("usage: python new_releases.py [username]")
    sys.exit()

token = util.prompt_for_user_token(username)

if token:
    sp = spotipy.Spotify(auth=token)

    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:
github plamere / spotipy / examples / delete_a_saved_track.py View on Github external
import pprint
import sys

import spotipy
import spotipy.util as util

scope = 'user-library-modify'

if len(sys.argv) > 2:
    username = sys.argv[1]
    tids = sys.argv[2:]
else:
    print("Usage: %s username 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_delete(tracks=tids)
    pprint.pprint(results)
else:
    print("Can't get token for", username)
github meain / stag / stag / stag.py View on Github external
def get_spotify_instace():

    access = "user-library-modify"
    redirectURL = "http://localhost/"
    token = spotipy.util.prompt_for_user_token(
        username=creds["username"],
        scope=access,
        client_id=creds["clientId"],
        client_secret=creds["clientSecret"],
        redirect_uri=redirectURL,
    )
    client_manager = SpotifyClientCredentials(creds["clientId"], creds["clientSecret"])
    sp = spotipy.Spotify(auth=token, client_credentials_manager=client_manager)
    return sp
github marioortizmanero / spotify-music-videos / spotify_videoclips / player.py View on Github external
self.position = 0
        self.is_playing = False
        self._debug = debug
        self.player = VLCWindow(
                debug = debug,
                vlc_args = vlc_args,
                fullscreen = fullscreen
        )

        # Checking that all parameters are passed
        if not username: error("You must pass your username as an argument. Run `spotify-videoclips --help` for more info.")
        if not client_id: error("You must pass your client ID as an argument. Run `spotify-videoclips --help` for more info.")
        if not client_secret: error("You must pass your client secret as an argument. Run `spotify-videoclips --help` for more info.")

        # Creation of the Spotify token
        self._token = spotipy.util.prompt_for_user_token(
                username,
                scope = 'user-read-currently-playing',
                client_id = client_id,
                client_secret = client_secret,
                redirect_uri = redirect_uri
        )
        if self._token:
            log("Authorized correctly", self._debug)
            self._spotify = spotipy.Spotify(auth = self._token)
        else:
            error("Can't get token for " + username)

        self._spotify.trace = False
        self._refresh_metadata()
github gvc14 / AlbumArtWallpaper / AlbumArtWallpaper.py View on Github external
def tokenGen():
        token = util.prompt_for_user_token(username,scope,client_id = 'Your_client_id',client_secret='Your_client_secret',
                                           redirect_uri='http://localhost:8888/callback/')
        sp = spotipy.Spotify(auth=token)
        return sp
sp = tokenGen()
github jkl1999 / RedditFy / HipHopHeads.py View on Github external
url = "https://old.reddit.com/r/indieheads/top/"
# Headers to mimic a browser visit
headers = {'User-Agent': 'Mozilla/5.0'}

# Returns a requests.models.Response object
page = requests.get(url, headers=headers)

soup = BeautifulSoup(page.text, 'html.parser')

scope = 'playlist-modify-public'
username = '99kylel'


token = util.prompt_for_user_token(username,scope,client_id='',client_secret='',redirect_uri='http://localhost/')


if token:
    sp = spotipy.Spotify(auth=token)
    sp.trace = False
        

    albumTitles = []
    trackTitles = []

    trackLinks = []

    for data in soup.find_all('p', class_='title'):
        for a in data.find_all('a'):
            
            #spotify album link
github jkl1999 / RedditFy / indieheads.py View on Github external
url = "https://old.reddit.com/r/indieheads/top/"
# Headers to mimic a browser visit
headers = {'User-Agent': 'Mozilla/5.0'}

# Returns a requests.models.Response object
page = requests.get(url, headers=headers)

soup = BeautifulSoup(page.text, 'html.parser')

scope = 'playlist-modify-public'
username = '99kylel'


token = util.prompt_for_user_token(username,scope,client_id='',client_secret='',redirect_uri='http://localhost/')


if token:
    sp = spotipy.Spotify(auth=token)
    sp.trace = False
        

    albumTitles = []
    trackTitles = []

    trackLinks = []

    for data in soup.find_all('p', class_='title'):
        for a in data.find_all('a'):
            
            #spotify album link
github kodi-community-addons / plugin.audio.spotify / resources / plugincontent.py View on Github external
if username and password:
            #wait for background service...
            if not WINDOW.getProperty("Spotify.ServiceReady"):
                #start libspotify background service
                xbmc.executebuiltin('RunScript(plugin.audio.spotify)')
                count = 0
                while not WINDOW.getProperty("Spotify.ServiceReady"):
                    logMsg("waiting for service...",True)
                    if count == 50: 
                        break
                    else:
                        xbmc.sleep(1000)
                        count += 1
            
            #check token for webapi
            self.token = util.prompt_for_user_token(username)
            error = WINDOW.getProperty("Spotify.Lasterror")
            if not self.token:
                xbmcgui.Dialog().ok(ADDON_NAME, ADDON.getLocalizedString(11019) + ': ' + error)
                return False
            elif WINDOW.getProperty("Spotify.ServiceReady") == "ready" and self.token:
                return True
            elif WINDOW.getProperty("Spotify.ServiceReady") == "noplayback" and self.token:
                return True
            else:
                errorStr = error
                try:
                    error = int(error)
                    errorStr = SpotifyError[int(error)]
                    if error == 6:
                        SAVESETTING("username","")
                        SAVESETTING("password","")