From 80a8947dda6345ee427c931d86b4747b0c711edd Mon Sep 17 00:00:00 2001 From: Hellow Date: Sun, 16 Apr 2023 15:48:39 +0200 Subject: [PATCH] addet sorting options to config, yet to implement any sorting --- src/music_kraken/objects/song.py | 5 ++++- src/music_kraken/utils/config/audio.py | 28 +++++++++++++++++++++++++- src/music_kraken/utils/shared.py | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index 6f1709a..3eab9b8 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -491,7 +491,10 @@ class Artist(MainObject): :return: """ - # self.main_album_collection.sort(key=lambda _album: _album.date) + if len(self.main_album_collection) <= 0: + return + + self.main_album_collection.sort(key=lambda _album: _album.date) for i, album in enumerate(self.main_album_collection): if album.albumsort is None: diff --git a/src/music_kraken/utils/config/audio.py b/src/music_kraken/utils/config/audio.py index db6c42f..dd4d368 100644 --- a/src/music_kraken/utils/config/audio.py +++ b/src/music_kraken/utils/config/audio.py @@ -1,6 +1,14 @@ import logging -from .base_classes import SingleAttribute, FloatAttribute, StringAttribute, IntAttribute, Section, Description, EmptyLine +from .base_classes import ( + SingleAttribute, + FloatAttribute, + StringAttribute, + Section, + Description, + EmptyLine, + BoolAttribute +) # Only the formats with id3 metadata can be used # https://www.audioranger.com/audio-formats.php @@ -53,6 +61,22 @@ ID3.2: {', '.join(_sorted_id3_2_formats)} ID3.1: {', '.join(_sorted_id3_1_formats)} """.strip()) + self.SORT_BY_DATE = BoolAttribute( + name="sort_by_date", + description="If this is set to true, it will set the albumsort attribute such that,\n" + "the albums are sorted by date.", + value="true" + ) + + self.SORT_BY_ALBUM_TYPE = BoolAttribute( + name="sort_album_by_type", + description="If this is set to true, it will set the albumsort attribute such that,\n" + "the albums are put into categories before being sorted.\n" + "This means for example, the Studio Albums and EP's are always in front of Singles, " + "and Compilations are in the back.", + value="true" + ) + self.DOWNLOAD_PATH = StringAttribute( name="download_path", value="{genre}/{artist}/{album_type}/{album}", @@ -105,6 +129,8 @@ ID3.1: {', '.join(_sorted_id3_1_formats)} self.BITRATE, self.AUDIO_FORMAT, EmptyLine(), + self.SORT_BY_DATE, + self.SORT_BY_ALBUM_TYPE, Description(""" There are multiple fields, you can use for the path and file name: - genre diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 0ea757d..9e4a6ef 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -94,3 +94,6 @@ CHUNK_SIZE = CONNECTION_SECTION.CHUNK_SIZE.object_from_value # If the percentage goes over this threshold DownloadResult returns the download errors # in the __str__ method SHOW_DOWNLOAD_ERRORS_THRESHOLD = CONNECTION_SECTION.SHOW_DOWNLOAD_ERRORS_THRESHOLD.object_from_value + +SORT_BY_DATE = AUDIO_SECTION.SORT_BY_DATE.object_from_value +SORT_BY_ALBUM_TYPE = AUDIO_SECTION.SORT_BY_ALBUM_TYPE.object_from_value