49 lines
1 KiB
Python
49 lines
1 KiB
Python
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")
|
|
|