fix(ffmpeg handling): add translation, revise logging
add more translations add setup logging function for file and stdout logger combine translation functions: translate_audio_tracks, translate_audio_descriptions formatting changes fix move_override function
This commit is contained in:
1 parent
2d544d317f
commit
6d229c59f7
3 files changed
+782
-407
No files matched your search
+744
-405
File diff suppressed because it is too large.
Load diff
@@ -2,6 +2,7 @@ from .core import (
|
||||
TRACE,
|
||||
LOG_LEVELS,
|
||||
CustomLogger,
|
||||
setup_logging,
|
||||
blue,
|
||||
combined_score,
|
||||
get_audio_tracks,
|
||||
@@ -25,6 +26,7 @@ __all__ = [
|
||||
"TRACE",
|
||||
"LOG_LEVELS",
|
||||
"CustomLogger",
|
||||
"setup_logging",
|
||||
"blue",
|
||||
"combined_score",
|
||||
"get_audio_tracks",
|
||||
@@ -42,4 +44,5 @@ __all__ = [
|
||||
"word_similarity",
|
||||
"words",
|
||||
"yellow",
|
||||
]
|
||||
]
|
||||
|
||||
+34
-1
@@ -1,9 +1,11 @@
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
from difflib import SequenceMatcher
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
import logging
|
||||
@@ -12,7 +14,7 @@ import logging
|
||||
# -----------------------------
|
||||
# Logger
|
||||
# -----------------------------
|
||||
TRACE=5
|
||||
TRACE = 5
|
||||
|
||||
red = "\033[91m"
|
||||
green = "\033[92m"
|
||||
@@ -20,11 +22,13 @@ yellow = "\033[93m"
|
||||
blue = "\033[94m"
|
||||
reset = "\033[0m"
|
||||
|
||||
|
||||
class CustomLogger(logging.Logger):
|
||||
def trace(self, msg: str, *args, **kwargs) -> None:
|
||||
if self.isEnabledFor(TRACE):
|
||||
self._log(TRACE, msg, args, **kwargs)
|
||||
|
||||
|
||||
LOG_LEVELS = {
|
||||
"TRACE": TRACE,
|
||||
"DEBUG": logging.DEBUG,
|
||||
@@ -33,6 +37,35 @@ LOG_LEVELS = {
|
||||
"ERROR": logging.ERROR,
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
}
|
||||
|
||||
|
||||
def setup_logging(log_level: str = "INFO", logfile: str = "logfile") -> None:
|
||||
formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s")
|
||||
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
stdout_handler.setFormatter(formatter)
|
||||
stdout_handler.setLevel(LOG_LEVELS[log_level.upper()])
|
||||
|
||||
ext = Path(logfile).suffix
|
||||
if not ext:
|
||||
ext = ".log"
|
||||
logfile_data = (
|
||||
Path("/home/lucas/logs/") / f"{logfile}_{datetime.now():%Y%m%d_%H%M%S}{ext}"
|
||||
)
|
||||
|
||||
file_handler = logging.FileHandler(logfile_data, encoding="utf-8")
|
||||
file_handler.setFormatter(formatter)
|
||||
file_handler.setLevel(TRACE)
|
||||
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(TRACE)
|
||||
root_logger.handlers.clear() # avoid duplicate logging
|
||||
|
||||
root_logger.addHandler(stdout_handler)
|
||||
root_logger.addHandler(file_handler)
|
||||
root_logger.info(f"Set logger to {log_level}, Logfile: {logfile_data}")
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Helpers
|
||||
# -----------------------------
|
||||
|
||||
Reference in new issue
Block a user