From 984f5335bb581f6a4b0c6aa3cc6c5a399a791a83 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 13:00:00 +0200 Subject: [PATCH] added another setting --- src/music_kraken/utils/config/audio.py | 44 ++++++++++++++++++++++++-- src/music_kraken/utils/shared.py | 8 ++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/utils/config/audio.py b/src/music_kraken/utils/config/audio.py index dd4d368..1d253ef 100644 --- a/src/music_kraken/utils/config/audio.py +++ b/src/music_kraken/utils/config/audio.py @@ -7,8 +7,11 @@ from .base_classes import ( Section, Description, EmptyLine, - BoolAttribute + BoolAttribute, + ListAttribute ) +from ...utils.enums.album import AlbumType +from ...utils.exception.config import SettingValueError # Only the formats with id3 metadata can be used # https://www.audioranger.com/audio-formats.php @@ -32,6 +35,15 @@ _sorted_id3_1_formats = sorted(ID3_1_FILE_FORMATS) class AudioFormatAttribute(SingleAttribute): + def validate(self, value: str): + v = self.value.strip().lower() + if v not in ID3_1_FILE_FORMATS and v not in ID3_2_FILE_FORMATS: + raise SettingValueError( + setting_name=self.name, + setting_value=value, + rule="has to be a valid audio format, supporting id3 metadata" + ) + @property def object_from_value(self) -> str: v = self.value.strip().lower() @@ -44,6 +56,21 @@ class AudioFormatAttribute(SingleAttribute): raise ValueError(f"Invalid Audio Format: {v}") +class AlbumTypeListAttribute(ListAttribute): + def validate(self, value: str): + try: + AlbumType(value.strip()) + except ValueError: + raise SettingValueError( + setting_name=self.name, + setting_value=value, + rule="has to be an existing album type" + ) + + def single_object_from_element(self, value: str) -> AlbumType: + return AlbumType(value) + + class AudioSection(Section): def __init__(self): self.BITRATE = FloatAttribute( @@ -124,6 +151,18 @@ ID3.1: {', '.join(_sorted_id3_1_formats)} value="Other", description="Weirdly enough I barely see this used in file systems." ) + + self.ALBUM_TYPE_BLACKLIST = AlbumTypeListAttribute( + name="album_type_blacklist", + description="Music Kraken ignores all albums of those types.\n" + "Following album types exist in the programm:\n" + f"{', '.join(album.value for album in AlbumType)}", + value=[ + AlbumType.COMPILATION_ALBUM.value, + AlbumType.LIVE_ALBUM.value, + AlbumType.MIXTAPE.value + ] + ) self.attribute_list = [ self.BITRATE, @@ -146,7 +185,8 @@ There are multiple fields, you can use for the path and file name: self.DEFAULT_ARTIST, self.DEFAULT_GENRE, self.DEFAULT_LABEL, - self.DEFAULT_SONG + self.DEFAULT_SONG, + self.ALBUM_TYPE_BLACKLIST, ] super().__init__() diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 0dffa5d..3f8d854 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -5,7 +5,7 @@ from typing import List, Tuple from .path_manager import LOCATIONS from .config import LOGGING_SECTION, AUDIO_SECTION, CONNECTION_SECTION, MISC_SECTION, PATHS_SECTION - +from .enums.album import AlbumType CONFIG_FILE = LOCATIONS.CONFIG_FILE @@ -100,3 +100,9 @@ SHOW_DOWNLOAD_ERRORS_THRESHOLD = CONNECTION_SECTION.SHOW_DOWNLOAD_ERRORS_THRESHO SORT_BY_DATE = AUDIO_SECTION.SORT_BY_DATE.object_from_value SORT_BY_ALBUM_TYPE = AUDIO_SECTION.SORT_BY_ALBUM_TYPE.object_from_value + +ALBUM_TYPE_BLACKLIST: List[AlbumType] = [ + AlbumType.COMPILATION_ALBUM, + AlbumType.MIXTAPE, + AlbumType.LIVE_ALBUM +]