From 2459fceed139cdbe8e01177aa54e92296af6060b Mon Sep 17 00:00:00 2001 From: Boris Date: Sat, 23 Apr 2022 18:59:19 +0300 Subject: [PATCH 1/4] add plain-txt output format and change line break character from \r\n to \n --- spotify-backup.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/spotify-backup.py b/spotify-backup.py index ce7f7cc..bce1fb1 100755 --- a/spotify-backup.py +++ b/spotify-backup.py @@ -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\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'], - release_date=track['track']['album']['release_date'] - )) - f.write('\r\n') + 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'] + 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) From e63f3e4663d65c3166e3126be5bd2e527238c754 Mon Sep 17 00:00:00 2001 From: Boris Date: Sat, 23 Apr 2022 19:17:53 +0300 Subject: [PATCH 2/4] remove newline after playlist name --- spotify-backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotify-backup.py b/spotify-backup.py index bce1fb1..ef25b4b 100755 --- a/spotify-backup.py +++ b/spotify-backup.py @@ -192,7 +192,7 @@ def main(): else: f.write('Playlists:\n\n') for playlist in playlists: - f.write(playlist['name'] + '\n\n') + f.write(playlist['name'] + '\n') for track in playlist['tracks']: if track['track'] is None: continue From aa0dee1ba4b8780ef5d7ecd03eb8ee9d7e529ba8 Mon Sep 17 00:00:00 2001 From: Boris Date: Sat, 23 Apr 2022 19:18:21 +0300 Subject: [PATCH 3/4] update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d905bb4..e5a5159 100644 --- a/README.md +++ b/README.md @@ -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 artists only, in the format of `TITLE - ARTIST`. 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 From a74e194ad8a81902bf1147116144180aa7914102 Mon Sep 17 00:00:00 2001 From: Boris Date: Sat, 23 Apr 2022 19:40:54 +0300 Subject: [PATCH 4/4] clarify output format in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5a5159..5f3225e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 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. For ease of import into other music streaming services, you can choose to output titles and artists only, in the format of `TITLE - ARTIST`. +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 ` - <artist name>`. You can run the script from the command line: