Convert Fehler behoben
This commit is contained in:
parent
456852399e
commit
e6098171fc
5 changed files with 54 additions and 15 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
log_file: "server.log"
|
log_file: "server.log"
|
||||||
log_level: DEBUG
|
log_level: DEBUG
|
||||||
|
log_rotation: time
|
||||||
path_file: "media_path.yaml"
|
path_file: "media_path.yaml"
|
||||||
server_ip: "0.0.0.0"
|
server_ip: "0.0.0.0"
|
||||||
server_port: 8000
|
server_port: 8000
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ class Convert:
|
||||||
self.yaml = cfg
|
self.yaml = cfg
|
||||||
self.obj_path = obj_path
|
self.obj_path = obj_path
|
||||||
self.obj_websocket = websocket
|
self.obj_websocket = websocket
|
||||||
self.obj_process = Process(websocket)
|
|
||||||
|
|
||||||
self.active_tasks = set()
|
self.active_tasks = set()
|
||||||
self.active_process = set()
|
self.active_process = set()
|
||||||
|
|
@ -40,6 +39,8 @@ class Convert:
|
||||||
async def convert_video(self, obj):
|
async def convert_video(self, obj):
|
||||||
"""Startet die Videokonvertierung asynchron."""
|
"""Startet die Videokonvertierung asynchron."""
|
||||||
|
|
||||||
|
obj_process = Process(self.obj_websocket)
|
||||||
|
|
||||||
obj.convert_start = time.time()
|
obj.convert_start = time.time()
|
||||||
command = self.convert_cmd(obj)
|
command = self.convert_cmd(obj)
|
||||||
result = None
|
result = None
|
||||||
|
|
@ -57,7 +58,7 @@ class Convert:
|
||||||
self.active_process.add(obj)
|
self.active_process.add(obj)
|
||||||
obj.process_start = time.time()
|
obj.process_start = time.time()
|
||||||
|
|
||||||
await self.obj_process.read_out(obj)
|
await obj_process.read_out(obj)
|
||||||
await obj.process.wait()
|
await obj.process.wait()
|
||||||
|
|
||||||
# Prozess beendet, Status auswerten
|
# Prozess beendet, Status auswerten
|
||||||
|
|
@ -74,13 +75,14 @@ class Convert:
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
obj.status = 2
|
obj.status = 2
|
||||||
logging.error(f"Fehler in video_convert(): {e}", exc_info=True)
|
logging.error(f"Fehler in video_convert(): {e}")
|
||||||
finally:
|
finally:
|
||||||
logging.info(f"Prozess {result}({obj.process.returncode}): {obj.source_file_name}")
|
logging.info(f"Prozess {result}({obj.process.returncode}): {obj.source_file_name}")
|
||||||
await self.obj_websocket.send_websocket(obj.to_dict())
|
await self.obj_websocket.send_websocket(obj.to_dict())
|
||||||
|
|
||||||
self.active_process.discard(obj)
|
self.active_process.discard(obj)
|
||||||
self.active_tasks.discard(obj)
|
self.active_tasks.discard(obj)
|
||||||
|
self.obj_path.save_paths()
|
||||||
|
|
||||||
obj.convert_end = time.time()
|
obj.convert_end = time.time()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class Process:
|
||||||
|
|
||||||
async def read_out(self, obj):
|
async def read_out(self, obj):
|
||||||
self.id = obj.id
|
self.id = obj.id
|
||||||
|
self.line_empty = 0
|
||||||
i = 100
|
i = 100
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,13 @@ class Path:
|
||||||
Saves the extrated Paths in a File
|
Saves the extrated Paths in a File
|
||||||
:return: True or False
|
:return: True or False
|
||||||
"""
|
"""
|
||||||
paths_extrat_dict:dict = {}
|
paths:list = []
|
||||||
|
|
||||||
for obj_id, obj in self.paths.items():
|
for obj in self.paths.values():
|
||||||
paths_extrat_dict.update({id: obj.__dict__})
|
if obj.status is None:
|
||||||
|
paths.append(obj.source_file)
|
||||||
|
|
||||||
|
paths_extrat_dict = {"paths": paths}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"app/cfg/{self.yaml["path_file"]}", "w", encoding="utf8") as file:
|
with open(f"app/cfg/{self.yaml["path_file"]}", "w", encoding="utf8") as file:
|
||||||
|
|
@ -91,11 +94,12 @@ class Path:
|
||||||
pattern = r"(?<=\.mkv\s|\.mp4\s|\.avi\s)|(?<=\.webm\s)"
|
pattern = r"(?<=\.mkv\s|\.mp4\s|\.avi\s)|(?<=\.webm\s)"
|
||||||
paths = re.split(pattern, var_paths)
|
paths = re.split(pattern, var_paths)
|
||||||
|
|
||||||
print(paths)
|
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
self.get_with_ffprobe(path)
|
self.get_with_ffprobe(path)
|
||||||
|
|
||||||
|
print(paths)
|
||||||
|
self.save_paths()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -153,7 +157,7 @@ class Path:
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Get Video Information: {e}", exc_info=True)
|
logging.error(f"Get Video Information: {e}")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def search_paths(self, path):
|
def search_paths(self, path):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,14 @@
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
import yaml
|
||||||
|
import traceback
|
||||||
|
from logging.handlers import TimedRotatingFileHandler, RotatingFileHandler
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFormatter(logging.Formatter):
|
||||||
|
def format(self, record):
|
||||||
|
if record.levelno >= logging.ERROR and record.exc_info:
|
||||||
|
record.msg = f"{record.msg}\n{traceback.format_exc()}"
|
||||||
|
return super().format(record)
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -17,11 +26,33 @@ class Settings:
|
||||||
|
|
||||||
def set_logging(self):
|
def set_logging(self):
|
||||||
print(self.yaml)
|
print(self.yaml)
|
||||||
logging.basicConfig(
|
|
||||||
level=self.yaml["log_level"],
|
log_level = self.yaml.get("log_level", "INFO")
|
||||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
log_file = self.yaml.get("log_file", "app.log")
|
||||||
handlers=[
|
log_mode = self.yaml.get("log_rotation", "size") # "time" oder "size"
|
||||||
logging.StreamHandler(),
|
|
||||||
logging.FileHandler(f"app/logs/{self.yaml['log_file']}")
|
handlers = [logging.StreamHandler()]
|
||||||
]
|
|
||||||
|
# Handler je nach Modus erstellen
|
||||||
|
if log_mode == "time":
|
||||||
|
log_handler = TimedRotatingFileHandler(
|
||||||
|
f"app/logs/{log_file}", when="midnight", interval=1, backupCount=7, encoding="utf-8"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
log_handler = RotatingFileHandler(
|
||||||
|
f"app/logs/{log_file}", maxBytes=5 * 1024 * 1024, backupCount=5, encoding="utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
handlers.append(log_handler)
|
||||||
|
|
||||||
|
# Logger konfigurieren
|
||||||
|
logging.basicConfig(
|
||||||
|
level=log_level,
|
||||||
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||||
|
handlers=handlers
|
||||||
|
)
|
||||||
|
|
||||||
|
# Traceback-Formatter setzen
|
||||||
|
formatter = CustomFormatter("%(asctime)s - %(levelname)s - %(message)s")
|
||||||
|
for handler in logging.getLogger().handlers:
|
||||||
|
handler.setFormatter(formatter)
|
||||||
Loading…
Reference in a new issue