Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bad_tracks = ['spotify:track:bad']
input = self.four_tracks + bad_tracks
results = spotify.audio_features(input)
self.assertTrue(len(results) == len(input))
for track in results[:-1]:
if track != None:
assert('speechiness' in track)
self.assertTrue(results[-1] == None)
def test_recommendations(self):
results = spotify.recommendations(seed_tracks=self.four_tracks, min_danceability=0, max_loudness=0, target_popularity=50)
self.assertTrue(len(results['tracks']) == 20)
if __name__ == '__main__':
client_credentials_manager = SpotifyClientCredentials()
spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
spotify.trace = False
unittest.main()
def get_playlist_tracks():
client_credentials_manager = SpotifyClientCredentials(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
username = PLAYLIST_URI.split(':')[2]
playlist_id = PLAYLIST_URI.split(':')[4]
offset = 0
items = []
while True:
res = sp.user_playlist_tracks(username, playlist_id, offset=offset)
items = items + res['items']
if res['next'] is not None:
offset = offset + 100
else:
break
tracks = []
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)
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
from time import time
import pandas as pd
import os
client_credentials_manager = SpotifyClientCredentials(
client_id=os.getenv("SPOTIFY_CLIENT_ID"),
client_secret=os.getenv("SPOTIFY_CLIENT_SECRET"),
)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
sp.trace = True
alltracks = pd.read_csv("../data/trackids_new_2.csv", sep=";", header=0)
tracklist = alltracks[alltracks["TrackID"] != "Not Found"]
tracklist = tracklist["TrackID"].tolist()
print(len(tracklist))
chunks = [tracklist[x : x + 49] for x in range(0, len(tracklist), 49)]
start = time()
with open("../data/audiofeatures3.csv", "w") as out:
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
import spotipy
import pprint
import yaml
with open('/home/pi/GassistPi/src/config.yaml','r') as conf:
configuration = yaml.load(conf)
#Spotify Declarations
#Register with spotify for a developer account to get client-id and client-secret
if configuration['Spotify']['client_id']!= 'ENTER YOUR SPOTIFY CLIENT ID HERE' and configuration['Spotify']['client_secret']!='ENTER YOUR SPOTIFY CLIENT SECRET HERE':
client_id = configuration['Spotify']['client_id']
client_secret = configuration['Spotify']['client_secret']
username=configuration['Spotify']['username']
credentials = oauth2.SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
spotify_token = credentials.get_access_token()
#Import VLC player
vlcplayer=mediaplayer.vlcplayer()
#Google Music Declarations
song_ids=[]
track_ids=[]
#Login with default kodi/kodi credentials
#kodi = Kodi("http://localhost:8080/jsonrpc")
def generate_token():
""" Generate the token. """
credentials = oauth2.SpotifyClientCredentials(
client_id=const.args.spotify_client_id,
client_secret=const.args.spotify_client_secret,
)
token = credentials.get_access_token()
return token