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]

View File

@ -4,7 +4,7 @@ from pathlib import Path
from typing import List, Set, Tuple
from .path_manager import LOCATIONS
from .config import LOGGING_SECTION
from .config import LOGGING_SECTION, AUDIO_SECTION
# modifies the garbage collector to speed up the program
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
@ -65,6 +65,10 @@ DOWNLOAD_LOGGER = LOGGING_SECTION.DOWNLOAD_LOGGER.object_from_value
TAGGING_LOGGER = LOGGING_SECTION.TAGGING_LOGGER.object_from_value
CODEX_LOGGER = LOGGING_SECTION.CODEX_LOGGER.object_from_value
# kB per second
BITRATE = AUDIO_SECTION.BITRATE.object_from_value
AUDIO_FORMAT = AUDIO_SECTION.AUDIO_FORMAT.object_from_value
NOT_A_GENRE_REGEX: Tuple[str] = (
r'^\.', # is hidden/starts with a "."
)
@ -76,27 +80,6 @@ proxies = {
} if TOR else {}
# 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
ALLOWED_FILE_FORMATS: Set[str] = {
"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
"ape", # Monkey's Audio ID3.1
"mpc", "mpp", "mp+", # MusePack ID3.1
"wv", # WavPack ID3.1
"ofr", "ofs" # OptimFrog ID3.1
}
# kB per second
BITRATE = 125
AUDIO_FORMAT = "mp3"
if AUDIO_FORMAT not in ALLOWED_FILE_FORMATS:
raise ValueError(f"The Audio Format is not in {ALLOWED_FILE_FORMATS} ({AUDIO_FORMAT}).")
"""
available variables:
- genre
@ -106,8 +89,8 @@ available variables:
- song
- album_type
"""
DOWNLOAD_PATH = "{genre}/{artist}/{album_type}/{album}"
DOWNLOAD_FILE = "{song}.{audio_format}"
DOWNLOAD_PATH = AUDIO_SECTION.DOWNLOAD_PATH.object_from_value
DOWNLOAD_FILE = AUDIO_SECTION.DOWNLOAD_FILE.object_from_value
DEFAULT_VALUES = {
"genre": "Various Genre",
"label": "Various Labels",