spotDL / spotify-downloader

Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
https://spotdl.readthedocs.io/en/latest/
MIT License
17.59k stars 1.61k forks source link

Track number should be prefixed with zeros #1628

Closed lukaszb closed 2 years ago

lukaszb commented 2 years ago

Requested Feature

If someone uses track_number at the output param they might expect tracks to be sorted lexically. This is not the case if there are at least 10 tracks at the album (because 10 would land before 2).

Current behaviour

If I use track_number at output I can get something like this:

$ tree
(...)
└── Paradox Interactive
    └── Stellaris (Original Game Soundtrack)
        ├── 1-Stellaris Suite- Creation and Beyond.mp3
        ├── 10-Infinite Being.mp3
        ├── 11-Pillars of Creation.mp3
        ├── 12-Distant Nebula.mp3
        ├── 13-Sigmatauri.mp3
        ├── 14-Journey Beyond the Galaxy.mp3
        ├── 15-Riding the Solar Wind.mp3
        ├── 16-The Birth of a Star.mp3
        ├── 17-Luminescence.mp3
        ├── 18-Faster Than Light (Instrumental).mp3
        ├── 2-Deep Space Travels.mp3
        ├── 3-To the End of the Galaxy.mp3
        ├── 4-In Search of Life.mp3
        ├── 5-Spatial Lullaby.mp3
        ├── 6-Gravitational Constant.mp3
        ├── 7-Alpha Centauri.mp3
        ├── 8-Genesis.mp3
        └── 9-The Celestial City.mp3

And I expect to get something like:

├── Paradox Interactive
│   └── Stellaris (Original Game Soundtrack)
│       ├── 01-Stellaris Suite- Creation and Beyond.mp3
│       ├── 02-Deep Space Travels.mp3
│       ├── 03-To the End of the Galaxy.mp3
│       ├── 04-In Search of Life.mp3
│       ├── 05-Spatial Lullaby.mp3
│       ├── 06-Gravitational Constant.mp3
│       ├── 07-Alpha Centauri.mp3
│       ├── 08-Genesis.mp3
│       ├── 09-The Celestial City.mp3
│       ├── 10-Infinite Being.mp3
│       ├── 11-Pillars of Creation.mp3
│       ├── 12-Distant Nebula.mp3
│       ├── 13-Sigmatauri.mp3
│       ├── 14-Journey Beyond the Galaxy.mp3
│       ├── 15-Riding the Solar Wind.mp3
│       ├── 16-The Birth of a Star.mp3
│       ├── 17-Luminescence.mp3
│       └── 18-Faster Than Light (Instrumental).mp3

Because if I download whole album I probably do care about order of the tracks. And lexical sorting is probably most commonly used as a default one (i.e. at car mp3 players).

Possible implementation

At spotdl.utils.formatter.format_query instead of song.track_number we can use this:

    track_number_length = (song.tracks_count // 10) + 1
    track_number_template = "{track_number:>0%d}" % track_number_length
    track_number = track_number_template.format(track_number=song.track_number)
asmol82 commented 2 years ago

Agreed. ;) I myself wanted to write about this feature, but I thought it was timely.

xnetcat commented 2 years ago

I don't have time right now to add this, if someone is interested feel free to open a PR

lukaszb commented 2 years ago

Sure, will do 👍 , just wanted to make sure it's something "acceptable".

xnetcat commented 2 years ago

added in https://github.com/spotDL/spotify-downloader/commit/5dadb8bf4e65fc02df9f0321379e47c7de57ebe3