mirror of
https://github.com/Xevion/spotify-explicit.git
synced 2025-12-06 01:16:25 -06:00
reworking to run from main
This commit is contained in:
8
pull.py
8
pull.py
@@ -23,11 +23,13 @@ def main():
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
logging.info('Authorized with Spotify via Spotipy')
|
||||
|
||||
tracks_folder = os.path.join(sys.path[0], 'tracks')
|
||||
logging.warning('Clearing all files in tracks folder for new files')
|
||||
shutil.rmtree(os.path.join(sys.path[0], 'tracks'))
|
||||
if os.path.exists(tracks_folder):
|
||||
shutil.rmtree(tracks_folder) # Delete folder and all contents (old track files)
|
||||
os.path.makedirs(tracks_folder) # Recreate the folder just deleted
|
||||
logging.info('Cleared folder, ready to download new track files')
|
||||
|
||||
root = sys.path[0]
|
||||
curoffset, curlimit = 0, 50
|
||||
while curoffset >= 0:
|
||||
logging.info('Requesting tracks {} to {}'.format(curoffset, curoffset + curlimit))
|
||||
@@ -35,7 +37,7 @@ def main():
|
||||
received = len(response['items'])
|
||||
logging.info('Received tracks {} to {}'.format(curoffset, curoffset + received))
|
||||
filename = f'saved-tracks-{curoffset}-{curoffset + received}.json'
|
||||
filepath = os.path.join(root, 'tracks', filename)
|
||||
filepath = os.path.join(tracks_folder, filename)
|
||||
with open(filepath, 'w+') as file:
|
||||
json.dump(response, file)
|
||||
logging.info('Saved at "{}" ({}KB)'.format(f'\\tracks\\{filename}', round(os.path.getsize(filepath) / 1024, 2)))
|
||||
|
||||
Reference in New Issue
Block a user