File Statistik eingebaut, Log Rotation
This commit is contained in:
parent
65e87ce997
commit
3c18dd7e18
5 changed files with 72 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ import logging
|
|||
import asyncio
|
||||
import time
|
||||
from app.class_file_convert_read_out import Process
|
||||
from app.class_media_file_stat import Stat
|
||||
|
||||
class Convert:
|
||||
def __init__(self, websocket, cfg, obj_path):
|
||||
|
|
@ -40,6 +41,7 @@ class Convert:
|
|||
"""Startet die Videokonvertierung asynchron."""
|
||||
|
||||
obj_process = Process(self.obj_websocket)
|
||||
obj_stat = Stat(obj)
|
||||
|
||||
obj.convert_start = time.time()
|
||||
command = self.convert_cmd(obj)
|
||||
|
|
@ -79,6 +81,7 @@ class Convert:
|
|||
self.active_process.discard(obj)
|
||||
self.active_tasks.discard(obj)
|
||||
self.obj_path.save_paths()
|
||||
obj_stat.save_stat()
|
||||
|
||||
obj.convert_end = time.time()
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ class Process:
|
|||
|
||||
self.process_line_extract(obj, line_decoded)
|
||||
|
||||
# in json umwandeln
|
||||
#await self.obj_websocket.send_websocket(self.to_dict())
|
||||
await self.obj_websocket.send_websocket(self.to_dict())
|
||||
|
||||
if self.line_empty > 30:
|
||||
break
|
||||
|
|
|
|||
|
|
@ -82,6 +82,36 @@ class Media:
|
|||
def to_dict():
|
||||
return "Fertig mit der Welt"
|
||||
|
||||
def to_dict_stat(self):
|
||||
return {self.id: {
|
||||
# source
|
||||
"source_file": self.source_file,
|
||||
"source_duration": self.source_duration,
|
||||
"source_size": self.source_size,
|
||||
"source_frame_rate": self.source_frame_rate,
|
||||
"source_frames_total": self.source_frames_total,
|
||||
"source_time": self.source_time,
|
||||
|
||||
# target
|
||||
"target_file": self.target_file,
|
||||
"target_size": self.target_size,
|
||||
|
||||
# process
|
||||
"status": self.status,
|
||||
"process_start": self.process_start,
|
||||
"process_end": self.process_end,
|
||||
"process_time": self.process_time,
|
||||
"process_size": self.process_size,
|
||||
"process_frames": self.process_frames,
|
||||
"process_time_remaining": self.process_time_remaining,
|
||||
|
||||
# statistic
|
||||
"stat_fps": self.stat_fps,
|
||||
"stat_bitrate": self.stat_bitrate,
|
||||
"stat_quantizer": self.stat_quantizer,
|
||||
"stat_speed": self.stat_speed
|
||||
}}
|
||||
|
||||
@staticmethod
|
||||
def frame_rate(video_streams):
|
||||
var_frame_rate = video_streams[0].get("r_frame_rate", "0/0").split("/")
|
||||
|
|
|
|||
26
app/class_media_file_stat.py
Normal file
26
app/class_media_file_stat.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import yaml
|
||||
import os
|
||||
|
||||
class Stat:
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
|
||||
def save_stat(self):
|
||||
pfad = "app/cfg/statistic.yaml"
|
||||
|
||||
# Bestehende Daten laden
|
||||
if os.path.exists(pfad):
|
||||
with open(pfad, "r", encoding="utf8") as file:
|
||||
daten = yaml.safe_load(file) or {}
|
||||
else:
|
||||
daten = {}
|
||||
|
||||
# Videosammlung initialisieren, falls nötig
|
||||
daten.setdefault("videos", {})
|
||||
|
||||
# Neuen Eintrag hinzufügen
|
||||
daten["videos"].update(self.obj.to_dict_stat())
|
||||
|
||||
# Datei mit aktualisierten Daten speichern
|
||||
with open(pfad, "w", encoding="utf8") as file:
|
||||
yaml.dump(daten, file, default_flow_style=False, indent=4, allow_unicode=True)
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import asyncio
|
||||
|
||||
import websockets
|
||||
import json
|
||||
import logging
|
||||
|
||||
from websockets import InvalidUpgrade, ConnectionClosed, ConnectionClosedError
|
||||
|
||||
from app.class_settings import Settings
|
||||
from app.class_file_path import Path
|
||||
from app.class_file_convert import Convert
|
||||
|
|
@ -12,6 +12,7 @@ var_convert_active = False
|
|||
|
||||
class Server:
|
||||
def __init__(self):
|
||||
self.websocket_send = 0
|
||||
self.websocket = None
|
||||
obj_settings = Settings()
|
||||
obj_settings.set_logging()
|
||||
|
|
@ -22,9 +23,14 @@ class Server:
|
|||
|
||||
async def send_websocket(self, message):
|
||||
try:
|
||||
await self.websocket.send(message)
|
||||
await self.websocket.send(json.dumps(message))
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
if self.websocket_send == 0:
|
||||
logging.warning("No websocket client connected!")
|
||||
self.websocket_send += 1
|
||||
|
||||
if self.websocket_send == 100:
|
||||
self.websocket_send = 0
|
||||
|
||||
async def handle_client(self, websocket):
|
||||
self.websocket = websocket
|
||||
|
|
@ -51,11 +57,9 @@ class Server:
|
|||
|
||||
#response = f"Server antwortet: {message.upper()}"
|
||||
#await websocket.send(response)
|
||||
except websockets.exceptions.ConnectionClosedError:
|
||||
except (ConnectionClosedError, InvalidUpgrade):
|
||||
pass
|
||||
except websockets.exceptions.InvalidUpgrade:
|
||||
pass
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
except ConnectionClosed:
|
||||
print("Server sagt: Client getrennt")
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
Loading…
Reference in a new issue