Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion spotify-backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ def __init__(self, access_token):
self.access_token = access_token


def maybe_delete(d, k):
if k in d:
del d[k]


def scrub_cruft(obj):
if isinstance(obj, dict):
maybe_delete(obj, "available_markets")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use obj.pop("available_markets", None) here instead.

for _, v in obj.items():
scrub_cruft(v)
elif isinstance(obj, list):
for v in obj:
scrub_cruft(v)


def main():
# Parse arguments.
parser = argparse.ArgumentParser(description='Exports your Spotify playlists. By default, opens a browser window '
Expand Down Expand Up @@ -175,13 +190,16 @@ def main():
logging.info('Loading playlist: {name} ({tracks[total]} songs)'.format(**playlist))
playlist['tracks'] = spotify.list(playlist['tracks']['href'], {'limit': 100})
playlists += playlist_data

logging.info(f"Scrubbing cruft...")
scrub_cruft(playlists)

# Write the file.
logging.info('Writing files...')
with open(args.file, 'w', encoding='utf-8') as f:
# JSON file.
if args.format == 'json':
json.dump(playlists, f)
json.dump(playlists, f, indent=2)

# Tab-separated file.
else:
Expand Down