From cc72bb93a160bba2011eef1266ff7fad92170ef0 Mon Sep 17 00:00:00 2001 From: Mariano Censi Date: Fri, 30 Jun 2023 08:27:31 -0300 Subject: [PATCH 1/3] Add --reverse_order flag to reverse the default playlist order --- spotify_dl/spotify_dl.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index d4e3d13..ff288b7 100755 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -76,6 +76,13 @@ def spotify_dl(): action="store_true", help="Whether to keep original playlist ordering or not.", ) + parser.add_argument( + "-R", + "--reverse_order", + default=False, + action="store_true", + help="Reverse the playlist order if --keep_playlist_order is set.", + ) parser.add_argument( "-m", "--skip_mp3", @@ -198,7 +205,7 @@ def spotify_dl(): ) url_dict["save_path"].mkdir(parents=True, exist_ok=True) log.info("Saving songs to %s directory", directory_name) - url_dict["songs"] = fetch_tracks(sp, item_type, url) + url_dict["songs"] = fetch_tracks(sp, item_type, url, args.reverse_order) url_data["urls"].append(url_dict.copy()) if args.dump_json is True: dump_json(url_dict["songs"]) From 8ff46bdc787c34f9392867908987c80795b81346 Mon Sep 17 00:00:00 2001 From: Mariano Censi Date: Fri, 30 Jun 2023 08:30:04 -0300 Subject: [PATCH 2/3] Modified the playlist_num parameter Added option to reverse the default order with the --reverse_order flag, and leading zeros in filenames for compatibility with devices that use alphabetical sorting --- spotify_dl/spotify.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spotify_dl/spotify.py b/spotify_dl/spotify.py index a3511b5..2c00ab6 100644 --- a/spotify_dl/spotify.py +++ b/spotify_dl/spotify.py @@ -4,7 +4,7 @@ from rich.progress import Progress -def fetch_tracks(sp, item_type, url): +def fetch_tracks(sp, item_type, url, reverse_order): """ Fetches tracks from the provided URL. :param sp: Spotify client @@ -73,6 +73,10 @@ def fetch_tracks(sp, item_type, url): genre = genres[0] else: genre = "" + if reverse_order: + playlist_num = str(total_songs - offset).zfill(len(str(total_songs))) + else: + playlist_num = str(offset + 1).zfill(len(str(total_songs))) songs_list.append( { "name": track_name, @@ -81,7 +85,7 @@ def fetch_tracks(sp, item_type, url): "year": track_year, "num_tracks": album_total, "num": track_num, - "playlist_num": offset + 1, + "playlist_num": playlist_num, "cover": cover, "genre": genre, "spotify_id": spotify_id, @@ -134,6 +138,10 @@ def fetch_tracks(sp, item_type, url): ][0] else: genre = "" + if reverse_order: + playlist_num = str(total_songs - offset).zfill(len(str(total_songs))) + else: + playlist_num = str(offset + 1).zfill(len(str(total_songs))) for item in items["items"]: track_name = item.get("name") track_artist = ", ".join( @@ -150,7 +158,7 @@ def fetch_tracks(sp, item_type, url): "num_tracks": album_total, "num": track_num, "track_url": None, - "playlist_num": offset + 1, + "playlist_num": playlist_num, "cover": cover, "genre": genre, "spotify_id": spotify_id, From 93d0004b8eb375f1d5298ec3aae46395787c7b89 Mon Sep 17 00:00:00 2001 From: Mariano Censi Date: Fri, 30 Jun 2023 08:39:09 -0300 Subject: [PATCH 3/3] Default reverse_order to False --- spotify_dl/spotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotify_dl/spotify.py b/spotify_dl/spotify.py index 2c00ab6..e54ab2c 100644 --- a/spotify_dl/spotify.py +++ b/spotify_dl/spotify.py @@ -4,7 +4,7 @@ from rich.progress import Progress -def fetch_tracks(sp, item_type, url, reverse_order): +def fetch_tracks(sp, item_type, url, reverse_order=False): """ Fetches tracks from the provided URL. :param sp: Spotify client