continued with the audio config

This commit is contained in:
Hellow
2023-04-14 12:40:52 +02:00
parent 04417ff947
commit d8c0cc288f
4 changed files with 41 additions and 35 deletions

View File

@@ -1 +1,2 @@
from .logging import LOGGING_SECTION
from .audio import AUDIO_SECTION

View File

@@ -1,25 +1,26 @@
import logging
from typing import Tuple
from .config import SingleAttribute, StringAttribute, IntAttribute, Section, Description, EmptyLine
from .config import SingleAttribute, FloatAttribute, StringAttribute, IntAttribute, Section, Description, EmptyLine
# Only the formats with id3 metadata can be used
# https://www.audioranger.com/audio-formats.php
# https://web.archive.org/web/20230322234434/https://www.audioranger.com/audio-formats.php
ID3_2_FILE_FORMATS = (
ID3_2_FILE_FORMATS = frozenset((
"mp3", "mp2", "mp1", # MPEG-1 ID3.2
"wav", "wave", "rmi", # RIFF (including WAV) ID3.2
"aiff", "aif", "aifc", # AIFF ID3.2
"aac", "aacp", # Raw AAC ID3.2
"tta", # True Audio ID3.2
)
))
_sorted_id3_2_formats = sorted(ID3_2_FILE_FORMATS)
ID3_1_FILE_FORMATS = (
ID3_1_FILE_FORMATS = frozenset((
"ape", # Monkey's Audio ID3.1
"mpc", "mpp", "mp+", # MusePack ID3.1
"wv", # WavPack ID3.1
"ofr", "ofs" # OptimFrog ID3.1
)
))
_sorted_id3_1_formats = sorted(ID3_1_FILE_FORMATS)
class AudioFormatAttribute(SingleAttribute):
@@ -35,12 +36,12 @@ class AudioFormatAttribute(SingleAttribute):
raise ValueError(f"Invalid Audio Format: {v}")
class AudioSection(Section):
def __init__(self):
self.BITRATE = IntAttribute(
self.BITRATE = FloatAttribute(
name="bitrate",
description="Streams the audio with this bitrate. Can't get more bitrate than the audio source though.",
description="Streams the audio with this bitrate (kB/s). Can't get more bitrate than the audio source "
"though.",
value="125"
)
@@ -48,10 +49,22 @@ class AudioSection(Section):
Music Kraken will stream the audio into this format.
You can use Audio formats which support ID3.2 and ID3.1,\n
but you will have cleaner Metadata using ID3.2.\n
ID3.2: {', '.join(f for f in ID3_2_FILE_FORMATS)}
ID3.1: {', '.join(f for f in ID3_1_FILE_FORMATS)}
ID3.2: {', '.join(_sorted_id3_2_formats)}
ID3.1: {', '.join(_sorted_id3_1_formats)}
""".strip())
self.DOWNLOAD_PATH = StringAttribute(
name="download_path",
value="{genre}/{artist}/{album_type}/{album}",
description="The folder music kraken should put the songs into."
)
self.DOWNLOAD_FILE = StringAttribute(
name="download_file",
value="{song}.{audio_format}",
description="The filename of the audio file."
)
self.attribute_list = [
self.BITRATE,
self.AUDIO_FORMAT

View File

@@ -42,6 +42,15 @@ class IntAttribute(SingleAttribute):
return int(self.value)
class FloatAttribute(SingleAttribute):
@property
def object_from_value(self) -> float:
if not self.value.isnumeric():
raise ValueError(f"The value of {self.name} needs to be a number, not {self.value}")
return float(self.value)
class ListAttribute(Attribute):
value: List[str]