added playlist export
This commit is contained in:
parent
920f2e4ed7
commit
ce560396aa
22
main.py
22
main.py
@ -6,15 +6,27 @@ if __name__ == '__main__':
|
||||
|
||||
user = userclass.User()
|
||||
|
||||
playlists = playlist.getPlaylists(user)
|
||||
#playlists = playlist.getPlaylists(user)
|
||||
|
||||
#for playlister in playlists:
|
||||
#print(playlister['name'])
|
||||
|
||||
print(playlists[0])
|
||||
#print(playlists[0])
|
||||
#print(len(playlists))
|
||||
|
||||
print(user.username)
|
||||
#print(user.username)
|
||||
|
||||
moreplaylists = playlist.getUserPlaylists(user)
|
||||
print(len(moreplaylists))
|
||||
#moreplaylists = playlist.getUserPlaylists(user)
|
||||
#print(len(moreplaylists))
|
||||
|
||||
#tracks = playlist.getPlaylistTracks(user, '000Eh2vXzYGgrEFlgcWZj3')
|
||||
|
||||
#print(tracks[0])
|
||||
|
||||
#print(len(tracks))
|
||||
|
||||
import spotframework.io.csv as csvwrite
|
||||
|
||||
csvwrite.exportPlaylist(user, '000Eh2vXzYGgrEFlgcWZj3')
|
||||
|
||||
print(user.access_token)
|
||||
|
60
out.csv
Normal file
60
out.csv
Normal file
@ -0,0 +1,60 @@
|
||||
name,artist,album,album artist,added,spotify id,added by
|
||||
Senses - DJ Q Remix,"My Nu Leng, Iyamah, DJ Q",Senses (DJ Q Remix),My Nu Leng,2019-02-01T11:31:35Z,1qBxCLvpRJ5bG2i1Y0x8hD,sarsoo
|
||||
M.O.D,"Holy Goof, Notion",Globes,Holy Goof,2019-02-01T11:57:09Z,49vPDBFvOB9RKQNtzeLDay,sarsoo
|
||||
Only Us - VIP,"Francois & Louis Benton, Riddim Commission, Asha",Globes,Holy Goof,2019-02-01T11:57:09Z,6fPoorVRF5PyhSw6G7Yg1W,sarsoo
|
||||
Shutdown - VIP,"Holy Goof, Chris Lorenzo",Globes,Holy Goof,2019-02-01T11:57:09Z,6axdwbHCgU8nDBqDr9zOi4,sarsoo
|
||||
Time,"Notion, Cecelia",Globes,Holy Goof,2019-02-01T11:57:09Z,2IemEFiwZ3hoTmiGYlotG4,sarsoo
|
||||
Let You Go,"Holy Goof, TS7",Globes,Holy Goof,2019-02-01T11:57:09Z,7M5Y2qx08PuUBNH6TyhbF9,sarsoo
|
||||
Flows,Skue-K,Globes,Holy Goof,2019-02-01T11:57:09Z,1sN1DfP5uRzyWJi8b6fl0j,sarsoo
|
||||
What 2 Say,"Holy Goof, FineArt",Globes,Holy Goof,2019-02-01T11:57:09Z,6hDMIFH7o679EYUsuWFKOH,sarsoo
|
||||
About To Get Hype,"Pelikann, Barely Royal, Purple Velvet Curtains",Globes,Holy Goof,2019-02-01T11:57:09Z,3KvlsQNvQ8BLwJI7rkZCJp,sarsoo
|
||||
The Force,"Holy Goof, Skepsis, Inja",Globes,Holy Goof,2019-02-01T11:57:09Z,1ncjDgvOzlKXAx6RJSuWCQ,sarsoo
|
||||
I Believe,FooR,Globes,Holy Goof,2019-02-01T11:57:09Z,1kPSrfIC22Ns3nBVXVdgUy,sarsoo
|
||||
Supersonic,Livsey,Globes,Holy Goof,2019-02-01T11:57:09Z,6D4rvRXWyakmNxIPQLPnwI,sarsoo
|
||||
Gully,"Holy Goof, My Nu Leng, Takura",Globes,Holy Goof,2019-02-01T11:57:09Z,3jKucb0CVbI66ilDMcDwiI,sarsoo
|
||||
Show Me How,Bushbaby,Globes,Holy Goof,2019-02-01T11:57:09Z,4gkKcAyrh61Hfcpj81mtH6,sarsoo
|
||||
Take Me Away,XX92,Globes,Holy Goof,2019-02-01T11:57:09Z,6Mx8OezYdRyxXHXhO3j1M0,sarsoo
|
||||
Edge,"Shapes, Prima",Globes,Holy Goof,2019-02-01T11:57:09Z,0mzFgjWXLxgn9guxkLUu7f,sarsoo
|
||||
Countdown,"DJ Q, Jamie Duggan",Globes,Holy Goof,2019-02-01T11:57:09Z,5hkRkPXBLgstXExcsxUBDd,sarsoo
|
||||
Evidence,"NuBass, Dread MC",Globes,Holy Goof,2019-02-01T11:57:09Z,2fSjvd4JqvqsPhKjnP21Yn,sarsoo
|
||||
No Warning,Taiki Nulight,Globes,Holy Goof,2019-02-01T11:57:09Z,6LuNP7oYy3LPslUgHtkLFj,sarsoo
|
||||
Spicy Noodles,Flava D,Globes,Holy Goof,2019-02-01T11:57:09Z,4N42f3TrE3gFSaEXPHr9Zp,sarsoo
|
||||
Stubborn,Freddie Martin,Globes,Holy Goof,2019-02-01T11:57:09Z,3gj3J1HRil2MSi32qtMoaP,sarsoo
|
||||
Go Hard,XX92,Globes,Holy Goof,2019-02-01T11:57:09Z,49UcKfLR5XYUcVJ46RMo1G,sarsoo
|
||||
Vulpix,YAKO,Globes,Holy Goof,2019-02-01T11:57:09Z,7bUjqwgOQo1xlvouS0prY8,sarsoo
|
||||
Pack Rack,Dommix,Globes,Holy Goof,2019-02-01T11:57:09Z,6QWGVEHzVsD4CO2lkcUz97,sarsoo
|
||||
Back Again,"Jauz, Holy Goof",Globes,Holy Goof,2019-02-01T11:57:09Z,2A0BiNS9v0RAeRR6QPY3Or,sarsoo
|
||||
Jumpin on a Jet,Future,Future Hndrxx Presents: The WIZRD,Future,2019-02-01T16:11:42Z,1I3ZAmPmbFV78oNKnibOiW,sarsoo
|
||||
Hilary $wank,Joey Bada$$,Summer Knights,Joey Bada$$,2019-02-15T10:38:21Z,6XMJJGQ6gksbWOEzF2UpVO,sarsoo
|
||||
My Yout (feat. Maverick Sabre),"Joey Bada$$, Maverick Sabre",Summer Knights,Joey Bada$$,2019-02-15T10:43:48Z,3uOM0nNQiWDP1oUnjCSax3,sarsoo
|
||||
Sit n' Prey (feat. Dessy & T'nah Apex),"Joey Bada$$, Dessy, T'nah Apex",Summer Knights,Joey Bada$$,2019-02-15T10:43:48Z,0F1DQ2uVP823zh96gm6AUI,sarsoo
|
||||
95 Till Infinity,Joey Bada$$,Summer Knights,Joey Bada$$,2019-02-15T10:58:42Z,7GTQgSPs8BYbn3YbmS78N8,sarsoo
|
||||
#LongLiveSteelo (feat. T'nah Apex),"Joey Bada$$, T'nah Apex",Summer Knights,Joey Bada$$,2019-02-15T10:58:42Z,2jwQCbqmKxk2lsIFRLXNT4,sarsoo
|
||||
My Jeep (feat. Flatbush Zombies & The Underachievers),"Joey Bada$$, Meechie Darko, Issa Gold, Chuck Strangers",Summer Knights,Joey Bada$$,2019-02-15T10:58:42Z,3O220xHBIQsN1mhqzpEPSJ,sarsoo
|
||||
My Yout (feat. Collie Buddz),"Joey Bada$$, Collie Buddz",Summer Knights,Joey Bada$$,2019-02-15T10:58:42Z,5USzBvFBG43xcj0bY5mWmJ,sarsoo
|
||||
Save The Children,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,7gvJadQt9vhgVHG7O1L2sc,sarsoo
|
||||
Greenbax (Introlude),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,0wmY92RjMZNGu54vEUmcUT,sarsoo
|
||||
Paper Trail$,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,5jNrszQHRIVKmS9Ptb63pe,sarsoo
|
||||
Piece of Mind,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,79eDnbSBUXoSaoRPqUhTur,sarsoo
|
||||
Big Dusty,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,12Gtheom5qK2Hjo1qTCNkx,sarsoo
|
||||
Hazeus View,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,5wrM3MbU9xNuSZGbmRm9B7,sarsoo
|
||||
Like Me (feat. BJ The Chicago Kid),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,7c5EpKbPpL86QVaP8yla8e,sarsoo
|
||||
Belly of the Beast (feat. Chronixx),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,7lGRaop0gCoVMeY9fSZIkR,sarsoo
|
||||
No. 99,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,1Ora7FZJR5xWId7upB1dlo,sarsoo
|
||||
Christ Conscious,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,2w9Qq5cflc8Z6BraiDCyes,sarsoo
|
||||
On & On (feat. Maverick Sabre & Dyemond Lewis),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,3nndHObJ5j5wpSKhTVODDG,sarsoo
|
||||
Escape 120 (feat. Raury),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,28j9YL5SeBl2EXFU1G1WEn,sarsoo
|
||||
Black Beetles,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,7gZC4WIaFSGg38tvKD2jlA,sarsoo
|
||||
O.C.B.,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,14MrWN36U9DSjKo7pOCQiN,sarsoo
|
||||
Curry Chicken,Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,4v3MF3UyP6ZilmkDDhWmS9,sarsoo
|
||||
Run Up On Ya (feat. Action Bronson & Elle Varner) (Bonus),Joey Bada$$,B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,3eJKAy9ZJaZLGS8EJlihXy,sarsoo
|
||||
Teach Me,"Joey Bada$$, Kiesza",B4.DA.$$,Joey Bada$$,2019-02-15T11:35:01Z,2qMjIHWyYgnEtcmoZc3R0u,sarsoo
|
||||
Caterpillar - Drumsound & Bassline Smith Remix,"Black Sun Empire, State of Mind, Drumsound & Bassline Smith",The Wrong Room Remixed,Black Sun Empire,2019-02-19T08:54:36Z,5Ycplzm1BPZYMQs9iMxNsB,sarsoo
|
||||
One Drink,"DLMT, Paraleven",One Drink,"DLMT, Paraleven",2019-02-19T09:22:02Z,7Fo51x6cURFo9jCzcv7WOL,sarsoo
|
||||
What's Up Danger - Black Caviar Remix,"Blackway, Black Caviar",What's Up Danger (Black Caviar Remix),"Blackway, Black Caviar",2019-02-19T09:28:44Z,0fOxkxw7FKXuzNs64bsmyb,sarsoo
|
||||
Flat Tummy Tea,"Freddie Gibbs, Madlib",Flat Tummy Tea,"Freddie Gibbs, Madlib",2019-02-20T09:47:09Z,6eF5uKCQV2d0bhblAxLujV,sarsoo
|
||||
Rampage Anthem VIP,"SASASAS, Macky Gee, DJ Phantasy, MC Shabba D, Stormin MC, MC Skibadee, Harry Shotta",Rampage Anthem VIP,"SASASAS, Macky Gee, DJ Phantasy",2019-02-22T08:55:29Z,0m9BpxJvsHlPTyQta201uF,sarsoo
|
||||
How Did I Get Here (feat. J. Cole),"Offset, J. Cole",FATHER OF 4,Offset,2019-02-22T15:39:36Z,32iPykTXUNZ9oGyACGUybq,sarsoo
|
||||
Tats On My Face,Offset,FATHER OF 4,Offset,2019-02-22T15:47:29Z,4TzXqUIcdpAmre24puQ6Uu,sarsoo
|
||||
Made Men,Offset,FATHER OF 4,Offset,2019-02-22T15:49:47Z,7vkL4wrBEmzr1wsiWRd1zO,sarsoo
|
||||
Astral Projection,Enrico Sangiuliano,Astral Projection,Enrico Sangiuliano,2019-02-26T11:02:48Z,32nw9Qc5rYjsPWGLy14Yh5,sarsoo
|
|
0
spotframework/io/__init__.py
Normal file
0
spotframework/io/__init__.py
Normal file
36
spotframework/io/csv.py
Normal file
36
spotframework/io/csv.py
Normal file
@ -0,0 +1,36 @@
|
||||
import csv
|
||||
import spotframework.net.playlist as playlistpull
|
||||
|
||||
headers = ['name', 'artist', 'album', 'album artist', 'added', 'spotify id', 'added by']
|
||||
|
||||
def exportPlaylist(user, playlistid):
|
||||
|
||||
playlist = playlistpull.getPlaylistTracks(user, playlistid)
|
||||
|
||||
with open('out.csv', 'w') as fileobj:
|
||||
|
||||
writer = csv.DictWriter(fileobj, fieldnames = headers)
|
||||
writer.writeheader()
|
||||
|
||||
for track in playlist:
|
||||
|
||||
trackdict = {
|
||||
'name':track['track']['name'],
|
||||
'album':track['track']['album']['name'],
|
||||
'added':track['added_at'],
|
||||
'spotify id':track['track']['id'],
|
||||
'added by':track['added_by']['id']}
|
||||
|
||||
alart = []
|
||||
for albumartist in track['track']['album']['artists']:
|
||||
alart.append(albumartist['name'])
|
||||
|
||||
trackdict['album artist'] = ', '.join(alart)
|
||||
|
||||
art = []
|
||||
for artist in track['track']['artists']:
|
||||
art.append(artist['name'])
|
||||
|
||||
trackdict['artist'] = ', '.join(art)
|
||||
|
||||
writer.writerow(trackdict)
|
@ -44,3 +44,32 @@ def getUserPlaylists(user):
|
||||
|
||||
return returnlist
|
||||
|
||||
def getPlaylistTracks(user, playlistid, offset = 0):
|
||||
|
||||
headers = {'Authorization': 'Bearer ' + user.access_token}
|
||||
|
||||
tracks = []
|
||||
|
||||
params = {'offset': offset, 'limit': limit}
|
||||
req = requests.get(const.api_url + 'playlists/{}/tracks'.format(playlistid), params = params, headers = headers)
|
||||
|
||||
#print(req.text)
|
||||
|
||||
if req.status_code == 200:
|
||||
|
||||
print(req.text)
|
||||
resp = req.json()
|
||||
|
||||
tracks += resp['items']
|
||||
|
||||
if resp['next']:
|
||||
tracks += getPlaylistTracks(user, playlistid, offset + limit)
|
||||
|
||||
#print(req.text)
|
||||
|
||||
return tracks
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user