mirror of
https://github.com/Xevion/spotify-explicit.git
synced 2025-12-13 04:13:06 -06:00
use shutil to remove old files
This commit is contained in:
8
pull.py
8
pull.py
@@ -2,6 +2,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import auth
|
import auth
|
||||||
import json
|
import json
|
||||||
|
import shutil
|
||||||
import pprint
|
import pprint
|
||||||
import spotipy
|
import spotipy
|
||||||
import logging
|
import logging
|
||||||
@@ -22,9 +23,12 @@ def main():
|
|||||||
sp = spotipy.Spotify(auth=token)
|
sp = spotipy.Spotify(auth=token)
|
||||||
logging.info('Authorized with Spotify via Spotipy')
|
logging.info('Authorized with Spotify via Spotipy')
|
||||||
|
|
||||||
|
logging.warning('Clearing all files in tracks folder for new files')
|
||||||
|
shutil.rmtree(os.path.join(sys.path[0], 'tracks'))
|
||||||
|
logging.info('Cleared folder, ready to download new track files')
|
||||||
|
|
||||||
root = sys.path[0]
|
root = sys.path[0]
|
||||||
curoffset, curlimit = 0, 50
|
curoffset, curlimit = 0, 50
|
||||||
# Start grabbing tracks (long running)
|
|
||||||
while curoffset >= 0:
|
while curoffset >= 0:
|
||||||
logging.info('Requesting tracks {} to {}'.format(curoffset, curoffset + curlimit))
|
logging.info('Requesting tracks {} to {}'.format(curoffset, curoffset + curlimit))
|
||||||
response = sp.current_user_saved_tracks(limit=curlimit, offset=curoffset)
|
response = sp.current_user_saved_tracks(limit=curlimit, offset=curoffset)
|
||||||
@@ -36,6 +40,6 @@ def main():
|
|||||||
json.dump(response, file)
|
json.dump(response, file)
|
||||||
logging.info('Saved at "{}" ({}KB)'.format(f'\\tracks\\{filename}', round(os.path.getsize(filepath) / 1024, 2)))
|
logging.info('Saved at "{}" ({}KB)'.format(f'\\tracks\\{filename}', round(os.path.getsize(filepath) / 1024, 2)))
|
||||||
if received < curlimit:
|
if received < curlimit:
|
||||||
logging.info('Done requesting/saving tracks after {} tracks.'.format(curoffset + received))
|
logging.info('Done requesting/saving tracks after {} tracks'.format(curoffset + received))
|
||||||
break
|
break
|
||||||
curoffset += curlimit
|
curoffset += curlimit
|
||||||
Reference in New Issue
Block a user