mirror of
https://github.com/Xevion/spotify-explicit.git
synced 2025-12-06 01:16:25 -06:00
refactoring for pull/processing abstraction
This commit is contained in:
21
pull.py
21
pull.py
@@ -9,7 +9,9 @@ import spotipy.util as util
|
||||
|
||||
def main():
|
||||
# Get Authorization
|
||||
logging.info('Authorizing with Spotify (may require User interaction).')
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.info('Authorizing with Spotify via Spotipy')
|
||||
logging.warning('May require User Interaction to authenticate properly!')
|
||||
token = util.prompt_for_user_token(
|
||||
username=auth.username,
|
||||
scope=auth.scope,
|
||||
@@ -18,23 +20,22 @@ def main():
|
||||
redirect_uri=auth.redirect_uri
|
||||
)
|
||||
sp = spotipy.Spotify(auth=token)
|
||||
logging.info('Authorized with Spotify.')
|
||||
logging.info('Authorized with Spotify via Spotipy')
|
||||
|
||||
root = sys.path[0]
|
||||
curoffset, curlimit = 900, 50
|
||||
curoffset, curlimit = 0, 50
|
||||
# Start grabbing tracks (long running)
|
||||
while curoffset >= 0:
|
||||
logging.debug('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)
|
||||
received = len(response['items'])
|
||||
logging.debug('Received tracks {} to {}'.format(curoffset, curoffset + received))
|
||||
logging.info('Received tracks {} to {}'.format(curoffset, curoffset + received))
|
||||
filename = f'saved-tracks-{curoffset}-{curoffset + received}.json'
|
||||
filepath = os.path.join(root, 'tracks', filename)
|
||||
with open(filepath, 'w+') as file:
|
||||
json.dump(response, file)
|
||||
curoffset += curlimit
|
||||
logging.debug('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:
|
||||
logging.info('Done requesting/saving tracks after {} tracks.'.format())
|
||||
|
||||
main()
|
||||
logging.info('Done requesting/saving tracks after {} tracks.'.format(curoffset + received))
|
||||
break
|
||||
curoffset += curlimit
|
||||
Reference in New Issue
Block a user