transefer LOG vars to serverlib#
This commit is contained in:
1 parent
2ea486a8c0
commit
6e9cc10b46
1 file changed
+5
-26
@@ -11,31 +11,10 @@ import sqlite3
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from serverlibrary import CustomLogger
|
||||||
RED = "\033[91m"
|
|
||||||
GREEN = "\033[92m"
|
|
||||||
YELLOW = "\033[93m"
|
|
||||||
BLUE = "\033[94m"
|
|
||||||
RESET = "\033[0m"
|
|
||||||
TRACE = 5
|
|
||||||
|
|
||||||
|
|
||||||
class CustomLogger(logging.Logger):
|
|
||||||
def trace(self, msg: str, *args, **kwargs) -> None:
|
|
||||||
if self.isEnabledFor(TRACE):
|
|
||||||
self._log(TRACE, msg, args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
logging.setLoggerClass(CustomLogger)
|
logging.setLoggerClass(CustomLogger)
|
||||||
logger: CustomLogger = logging.getLogger(__name__) # type: ignore[assignment]
|
logger: CustomLogger = logging.getLogger(__name__) # type: ignore[assignment]
|
||||||
LOG_LEVELS = {
|
|
||||||
"TRACE": TRACE,
|
|
||||||
"DEBUG": logging.DEBUG,
|
|
||||||
"INFO": logging.INFO,
|
|
||||||
"WARNING": logging.WARNING,
|
|
||||||
"ERROR": logging.ERROR,
|
|
||||||
"CRITICAL": logging.CRITICAL,
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata_fields = ["artist", "album", "composer", "comment", "genre", "grouping", "album artist", "description"]
|
metadata_fields = ["artist", "album", "composer", "comment", "genre", "grouping", "album artist", "description"]
|
||||||
audio_extensions = {"*.m4b", "*.m4a", "*.mp3", "*.flac", "*.ogg", "*.opus"}
|
audio_extensions = {"*.m4b", "*.m4a", "*.mp3", "*.flac", "*.ogg", "*.opus"}
|
||||||
@@ -427,7 +406,7 @@ class Audiobook:
|
|||||||
output_file_final = self.bookPath / f"{self.bookPath.name}.m4b"
|
output_file_final = self.bookPath / f"{self.bookPath.name}.m4b"
|
||||||
|
|
||||||
if output_file_final.exists():
|
if output_file_final.exists():
|
||||||
logger.info(f"{RED}[SKIP]{RESET} {output_file_final}")
|
logger.info(f"{red}[SKIP]{reset} {output_file_final}")
|
||||||
logger.info("Book already present")
|
logger.info("Book already present")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -586,7 +565,7 @@ class Audiobook:
|
|||||||
|
|
||||||
if result.returncode == 234:
|
if result.returncode == 234:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"{YELLOW}[WARNING]{RESET} - {self.bookPath.name} - {result.returncode} retrying with aac encoder"
|
f"{yellow}[WARNING]{reset} - {self.bookPath.name} - {result.returncode} retrying with aac encoder"
|
||||||
)
|
)
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
cmd_backup,
|
cmd_backup,
|
||||||
@@ -609,11 +588,11 @@ class Audiobook:
|
|||||||
self.changed = False
|
self.changed = False
|
||||||
self.size = Path(output_file_final).stat().st_size
|
self.size = Path(output_file_final).stat().st_size
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{GREEN}[SUCCESS]{RESET} - {self.bookPath.name} - delete media files"
|
f"{green}[SUCCESS]{reset} - {self.bookPath.name} - delete media files"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"{RED}[ERROR]{RESET} - {self.bookPath.name} - Code: {result.returncode}, Stderr: {result.stderr}"
|
f"{red}[ERROR]{reset} - {self.bookPath.name} - Code: {result.returncode}, Stderr: {result.stderr}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def write_metadata(self, keys=None, dry_run=False):
|
def write_metadata(self, keys=None, dry_run=False):
|
||||||
|
|||||||
Reference in new issue
Block a user