Python spotipy.oauth2.SpotifyClientCredentials() Examples

The following are 8 code examples of spotipy.oauth2.SpotifyClientCredentials(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module spotipy.oauth2 , or try the search function .
Example #1
Source File: musictools.py    From MusicTools with MIT License 7 votes vote down vote up
def get_metadata(file_name, client_id, client_secret):
    """
    Tries finding metadata through Spotify
    """

    song_name = improve_name(file_name)  # Remove useless words from title
    client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)

    spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
    results = spotify.search(song_name, limit=1)

    results = results['tracks']['items'][0]  # Find top result
    album = results['album']['name']  # Parse json dictionary
    artist = results['album']['artists'][0]['name']
    song_title = results['name']
    album_art = results['album']['images'][0]['url']

    return artist, album, song_title, album_art 
Example #2
Source File: songdata.py    From Jamais-Vu with MIT License 5 votes vote down vote up
def __init__(self):
        self.client_credentials_manager = SpotifyClientCredentials()
        self.spotify = spotipy.Spotify(client_credentials_manager=self.client_credentials_manager) 
Example #3
Source File: songdata.py    From Jamais-Vu with MIT License 5 votes vote down vote up
def getMainArtistGenre(self):
        uri = self.trackdata["artists"][0]["uri"]
        client_credentials_manager = SpotifyClientCredentials()
        spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
        artistdata = spotify.artist(uri)
        try:
            return artistdata["genres"][0]
        except IndexError:
            return None 
Example #4
Source File: spotify.py    From spotify-downloader with MIT License 5 votes vote down vote up
def _generate_token(self, client_id, client_secret):
        credentials = oauth2.SpotifyClientCredentials(
            client_secret=client_secret,
        )
        token = credentials.get_access_token()
        return token 
Example #5
Source File: spotify.py    From spotify-downloader with MIT License 5 votes vote down vote up
def __init__(self, client_id=None, client_secret=None):
        global masterclient
        # `spotipy.Spotify` makes use of `self._session` and would
        # result in an error. The below line is a workaround.
        self._session = None

        credentials_provided = client_id is not None \
                           and client_secret is not None
        valid_input = credentials_provided or masterclient is not None

        if not valid_input:
            raise SpotifyAuthorizationError(
                "You must pass in client_id and client_secret to this method "
                "when authenticating for the first time."
            )

        if masterclient:
            logger.debug("Reading cached master Spotify credentials.")
            # Use cached client instead of authorizing again
            # and thus wasting time.
            self.__dict__.update(masterclient.__dict__)
        else:
            logger.debug("Setting master Spotify credentials.")
            credential_manager = oauth2.SpotifyClientCredentials(
                client_id=client_id,
                client_secret=client_secret
            )
            super().__init__(client_credentials_manager=credential_manager)
            # Cache current client
            masterclient = self 
Example #6
Source File: pytifylib.py    From Pytify with MIT License 5 votes vote down vote up
def getCredentials(self):
        try:
            return spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
        except spotipy.oauth2.SpotifyOauthError:
            print('Did not find Spotify credentials.')

            print('Please visit https://github.com/bjarneo/pytify#credentials for more information.')

            sys.exit(1)

    # query 
Example #7
Source File: spotify_plugs.py    From pbl with MIT License 5 votes vote down vote up
def _get_spotify():
    spotify = engine.getEnv('spotify')
    if spotify == None:
        auth_token = engine.getEnv('spotify_auth_token')
        if auth_token:
            spotify = spotipy.Spotify(auth=auth_token)
        else:
            spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
        spotify.trace_out = True
        engine.setEnv('spotify', spotify)
    return spotify 
Example #8
Source File: test_oauth.py    From spotipy with MIT License 5 votes vote down vote up
def test_spotify_client_credentials_get_access_token(self):
        oauth = SpotifyClientCredentials(client_id='ID', client_secret='SECRET')
        with self.assertRaises(SpotifyOauthError) as error:
            oauth.get_access_token()
        self.assertEqual(error.exception.error, 'invalid_client')