initial
This commit is contained in:
parent
e7848b70fe
commit
14b853ae34
4 changed files with 104 additions and 0 deletions
49
spotifyFetch.py
Normal file
49
spotifyFetch.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import common as cm
|
||||
import os
|
||||
|
||||
os.makedirs(cm.data_dir, exist_ok=True)
|
||||
|
||||
fetch_step = 50
|
||||
|
||||
playlists = []
|
||||
playlist_items = {}
|
||||
|
||||
def loadPLaylists(pl):
|
||||
pl_count = 0
|
||||
pl_total = 0
|
||||
|
||||
pl_total = cm.fetch('v1/me/playlists?limit=1')['total']
|
||||
|
||||
while pl_count < pl_total:
|
||||
res = cm.fetch(f'v1/me/playlists?limit={fetch_step}&offset={pl_count}')
|
||||
pl += res['items']
|
||||
pl_count += fetch_step
|
||||
|
||||
|
||||
cm.saveData(playlists, 'playlists')
|
||||
|
||||
|
||||
def loadPlaylistItems(playlistId, traks):
|
||||
items = cm.fetch(f'v1/playlists/{playlistId}/tracks?fields=total')['total']
|
||||
loaded = 0
|
||||
|
||||
while loaded < items:
|
||||
res = cm.fetch(f'v1/playlists/{playlistId}/tracks?limit={fetch_step}&offset={items}')
|
||||
traks += res['items']
|
||||
loaded += fetch_step
|
||||
|
||||
print(items)
|
||||
|
||||
loadPLaylists(playlists)
|
||||
print(len(playlists))
|
||||
|
||||
|
||||
for pl in playlists:
|
||||
id = pl['id']
|
||||
name = pl['name']
|
||||
playlist_items[name] = []
|
||||
|
||||
loadPlaylistItems(id, playlist_items[name])
|
||||
|
||||
cm.saveData(playlist_items, "playlistTraks")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue