pull/45/merge
Boris Frolikov 2023-03-24 04:06:14 +02:00 committed by GitHub
commit bd5f4a3bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 15 deletions

View File

@ -3,16 +3,20 @@ spotify-backup
A Python script that exports all of your Spotify playlists, useful for paranoid Spotify users like me, afraid that one day Spotify will go under and take all of our playlists with it!
To run the script, [save it from here](https://raw.githubusercontent.com/caseychu/spotify-backup/master/spotify-backup.py) and double-click it. It'll ask you for a filename and then pop open a web page so you can authorize access to the Spotify API. Then the script will load your playlists and save a tab-separated file with your playlists that you can open in Excel. You can even copy-paste the rows from Excel into a Spotify playlist.
To run the script, [save it from here](https://raw.githubusercontent.com/caseychu/spotify-backup/master/spotify-backup.py) and double-click it. It'll ask you for a filename and then pop open a web page so you can authorize access to the Spotify API. Then the script will load your playlists and save a tab-separated file with your playlists that you can open in Excel. You can even copy-paste the rows from Excel into a Spotify playlist. For ease of import into other music streaming services, you can choose to output titles and artist names only, in the format of `<title> - <artist name>`.
You can run the script from the command line:
python spotify-backup.py playlists.txt
or, to get a JSON dump, use:
To get a JSON dump, use:
python spotify-backup.py playlists.json --format=json
To output titles and artists only, use:
python spotify-backup.py playlists.txt --format=plain-txt
By default, it includes your playlists. To include your Liked Songs, you can use:
python spotify-backup.py playlists.txt --dump=liked,playlists

View File

@ -135,7 +135,7 @@ def main():
+ '`playlist-read-private` permission)')
parser.add_argument('--dump', default='playlists', choices=['liked,playlists', 'playlists,liked', 'playlists', 'liked'],
help='dump playlists or liked songs, or both (default: playlists)')
parser.add_argument('--format', default='txt', choices=['json', 'txt'], help='output format (default: txt)')
parser.add_argument('--format', default='txt', choices=['json', 'txt', 'plain-txt'], help='output format (default: txt)')
parser.add_argument('file', help='output filename', nargs='?')
args = parser.parse_args()
@ -190,22 +190,26 @@ def main():
# Tab-separated file.
else:
f.write('Playlists: \r\n\r\n')
f.write('Playlists:\n\n')
for playlist in playlists:
f.write(playlist['name'] + '\r\n')
f.write(playlist['name'] + '\n')
for track in playlist['tracks']:
if track['track'] is None:
continue
f.write('{name}\t{artists}\t{album}\t{uri}\t{release_date}\r\n'.format(
uri=track['track']['uri'],
name=track['track']['name'],
artists=', '.join([artist['name'] for artist in track['track']['artists']]),
album=track['track']['album']['name'],
uri=track['track']['uri']
name=track['track']['name']
artists=', '.join([artist['name'] for artist in track['track']['artists']])
release_date=track['track']['album']['release_date']
))
f.write('\r\n')
album=track['track']['album']['name']
if args.format == 'txt':
f.write(f'{name}\t{artists}\t{album}\t{uri}\t{release_date}\n')
else:
f.write(f'{name} - {artists}\n')
f.write('\n')
if len(liked_albums) > 0:
f.write('Liked Albums: \r\n\r\n')
f.write('Liked Albums: \n')
for album in liked_albums:
uri = album['album']['uri']
name = album['album']['name']
@ -213,7 +217,10 @@ def main():
release_date = album['album']['release_date']
album = f'{artists} - {name}'
f.write(f'{name}\t{artists}\t-\t{uri}\t{release_date}\r\n')
if args.format == 'txt':
f.write(f'{name}\t{artists}\t-\t{uri}\t{release_date}\n')
else:
f.write(f'{name} - {artists}\n')
logging.info('Wrote file: ' + args.file)