started the config with loging
This commit is contained in:
parent
421ab5d4fb
commit
df2f8f57d2
@ -54,7 +54,7 @@ def print_cute_message():
|
|||||||
def exit_message():
|
def exit_message():
|
||||||
print()
|
print()
|
||||||
print_cute_message()
|
print_cute_message()
|
||||||
print("Have fun with your music. :3")
|
print("See you soon! :3")
|
||||||
|
|
||||||
|
|
||||||
def cli(
|
def cli(
|
||||||
|
@ -55,8 +55,12 @@ if __name__ == "__main__":
|
|||||||
if arguments.test:
|
if arguments.test:
|
||||||
genre = "test"
|
genre = "test"
|
||||||
|
|
||||||
music_kraken.cli(
|
try:
|
||||||
genre=genre,
|
music_kraken.cli(
|
||||||
download_all=arguments.all,
|
genre=genre,
|
||||||
direct_download_url=arguments.url
|
download_all=arguments.all,
|
||||||
)
|
direct_download_url=arguments.url
|
||||||
|
)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n\nRaise an issue if I fucked up:\nhttps://github.com/HeIIow2/music-downloader/issues")
|
||||||
|
music_kraken.exit_message()
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
from .logging import LOGGING_SECTION
|
@ -1,6 +1,8 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, List, Union
|
from typing import Optional, List, Union
|
||||||
|
|
||||||
|
COMMENT_PREFIX = "// "
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Attribute:
|
class Attribute:
|
||||||
@ -8,16 +10,25 @@ class Attribute:
|
|||||||
description: Optional[str]
|
description: Optional[str]
|
||||||
value: Union[str, List[str]]
|
value: Union[str, List[str]]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description_as_comment(self):
|
||||||
|
lines = self.description.split("\n")
|
||||||
|
|
||||||
|
return "\n".join(f"{COMMENT_PREFIX}{line}" for line in lines)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def object_from_value(self):
|
def object_from_value(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.description_as_comment}\n{self.name}={self.value}"
|
||||||
|
|
||||||
|
|
||||||
class SingleAttribute(Attribute):
|
class SingleAttribute(Attribute):
|
||||||
value: str
|
value: str
|
||||||
|
|
||||||
|
|
||||||
class StringAttribute(Attribute):
|
class StringAttribute(SingleAttribute):
|
||||||
@property
|
@property
|
||||||
def object_from_value(self) -> str:
|
def object_from_value(self) -> str:
|
||||||
return self.value
|
return self.value
|
||||||
@ -26,9 +37,32 @@ class StringAttribute(Attribute):
|
|||||||
class ListAttribute(Attribute):
|
class ListAttribute(Attribute):
|
||||||
value: List[str]
|
value: List[str]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.description_as_comment}\n" + \
|
||||||
|
"\n".join(f"{self.name}={element}" for element in self.value)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Description:
|
||||||
|
description: str
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"\n{self.description}"
|
||||||
|
|
||||||
|
|
||||||
|
class EmptyLine(Description):
|
||||||
|
def __init__(self):
|
||||||
|
self.description = "\n"
|
||||||
|
|
||||||
|
|
||||||
class Section:
|
class Section:
|
||||||
"""
|
"""
|
||||||
A placeholder class
|
A placeholder class
|
||||||
"""
|
"""
|
||||||
pass
|
attribute_list: List[Union[
|
||||||
|
Attribute,
|
||||||
|
Description
|
||||||
|
]]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "\n".join(attribute.__str__() for attribute in self.attribute_list)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from .config import SingleAttribute, ListAttribute, StringAttribute, Section
|
from .config import SingleAttribute, StringAttribute, Section, Description, EmptyLine
|
||||||
|
|
||||||
LOG_LEVELS = {
|
LOG_LEVELS = {
|
||||||
"CRITICAL": 50,
|
"CRITICAL": 50,
|
||||||
@ -99,3 +99,22 @@ class LoggingSection(Section):
|
|||||||
description="The logger for the genius scraper",
|
description="The logger for the genius scraper",
|
||||||
value="genius"
|
value="genius"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.attribute_list = [
|
||||||
|
Description("Logging settings for the actual logging:"),
|
||||||
|
self.FORMAT,
|
||||||
|
self.LOG_LEVEL,
|
||||||
|
Description("Just the names for different logger, for different parts of the programm:"),
|
||||||
|
self.DOWNLOAD_LOGGER,
|
||||||
|
self.TAGGING_LOGGER,
|
||||||
|
self.CODEX_LOGGER,
|
||||||
|
self.OBJECT_LOGGER,
|
||||||
|
self.DATABASE_LOGGER,
|
||||||
|
self.MUSIFY_LOGGER,
|
||||||
|
self.YOUTUBE_LOGGER,
|
||||||
|
self.ENCYCLOPAEDIA_METALLUM_LOGGER,
|
||||||
|
self.GENIUS_LOGGER
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
LOGGING_SECTION = LoggingSection()
|
||||||
|
@ -4,6 +4,7 @@ from pathlib import Path
|
|||||||
from typing import List, Set, Tuple
|
from typing import List, Set, Tuple
|
||||||
|
|
||||||
from .path_manager import LOCATIONS
|
from .path_manager import LOCATIONS
|
||||||
|
from .config import LOGGING_SECTION
|
||||||
|
|
||||||
# modifies the garbage collector to speed up the program
|
# 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/
|
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
||||||
@ -44,25 +45,25 @@ MUSIC_DIR: Path = LOCATIONS.MUSIC_DIRECTORY
|
|||||||
|
|
||||||
# configure logger default
|
# configure logger default
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=LOGGING_SECTION.LOG_LEVEL.object_from_value,
|
||||||
format=logging.BASIC_FORMAT,
|
format=LOGGING_SECTION.FORMAT.object_from_value,
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler(LOG_PATH),
|
logging.FileHandler(LOG_PATH),
|
||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
OBJECT_LOGGER = logging.getLogger("objects")
|
OBJECT_LOGGER = LOGGING_SECTION.OBJECT_LOGGER.object_from_value
|
||||||
DATABASE_LOGGER = logging.getLogger("database")
|
DATABASE_LOGGER = LOGGING_SECTION.DATABASE_LOGGER.object_from_value
|
||||||
|
|
||||||
YOUTUBE_LOGGER = logging.getLogger("Youtube")
|
YOUTUBE_LOGGER = LOGGING_SECTION.YOUTUBE_LOGGER.object_from_value
|
||||||
MUSIFY_LOGGER = logging.getLogger("Musify")
|
MUSIFY_LOGGER = LOGGING_SECTION.MUSIFY_LOGGER.object_from_value
|
||||||
GENIUS_LOGGER = logging.getLogger("genius")
|
GENIUS_LOGGER = LOGGING_SECTION.GENIUS_LOGGER
|
||||||
ENCYCLOPAEDIA_METALLUM_LOGGER = logging.getLogger("ma")
|
ENCYCLOPAEDIA_METALLUM_LOGGER = LOGGING_SECTION.ENCYCLOPAEDIA_METALLUM_LOGGER.object_from_value
|
||||||
|
|
||||||
DOWNLOAD_LOGGER = logging.getLogger("download")
|
DOWNLOAD_LOGGER = LOGGING_SECTION.DOWNLOAD_LOGGER.object_from_value
|
||||||
TAGGING_LOGGER = logging.getLogger("tagging")
|
TAGGING_LOGGER = LOGGING_SECTION.TAGGING_LOGGER.object_from_value
|
||||||
CODEX_LOGGER = logging.getLogger("codex")
|
CODEX_LOGGER = LOGGING_SECTION.CODEX_LOGGER.object_from_value
|
||||||
|
|
||||||
NOT_A_GENRE_REGEX: Tuple[str] = (
|
NOT_A_GENRE_REGEX: Tuple[str] = (
|
||||||
r'^\.', # is hidden/starts with a "."
|
r'^\.', # is hidden/starts with a "."
|
||||||
|
Loading…
Reference in New Issue
Block a user