This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessing Spotify Credentials.py
71 lines (41 loc) · 1.77 KB
/
Accessing Spotify Credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# coding: utf-8
# only insert where it says insert
# STEP 1: Get Spotify Client Information
# In[1]:
from sklearn.neighbors import NearestNeighbors
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt
get_ipython().run_line_magic('matplotlib', 'inline')
import numpy as np
import seaborn as sns
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
client_id = 'insert client id'
client_secret = 'insert client secret'
client_credentials_manager = SpotifyClientCredentials('insert client id', 'insert client secret')
sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)
# STEP 2: download playlists and convert into csv
# In[2]:
id_test = sp.user_playlist_tracks('insert spotify username', 'insert spotify uri')['items'][0]['track']['id']
columns = ['artist', 'track']
list(map(lambda x: columns.append(x), list(sp.audio_features(id_test)[0].keys())))
playlist_tracks = pd.DataFrame(columns = columns, index = range(0, 200))
playlist_tracks.head()
# In[3]:
playlist_ids = ['insert spotify uri', 'insert spotify uri']
row_counter = 0
for playlist_id in playlist_ids:
for track in sp.user_playlist_tracks('insert spotify username', 'insert spotify uri')['items']:
current_id = track['track']['id']
current_row = [track['track']['artists'][0]['name'], track['track']['name']]
(list(map(lambda x: current_row.append(x), list(sp.audio_features(current_id)[0].values()))))
playlist_tracks.iloc[row_counter] = current_row
row_counter += 1
playlist_tracks
# In[4]:
playlist_tracks.to_csv('file.csv', encoding='utf-8', index = False)
# In[5]:
playlist_tracks.to_csv(r'C:insert file location you want it to be stored in', index = False, header = True)
# In[ ]: