Source Size berechnet
This commit is contained in:
parent
bc3ad079d1
commit
8db6107dfa
4 changed files with 39 additions and 38 deletions
|
|
@ -112,38 +112,3 @@ class Process:
|
|||
"bitrate": self.bitrate,
|
||||
"speed": self.speed
|
||||
}}}
|
||||
|
||||
@staticmethod
|
||||
def size_convert(source: str, target, unit: str, size=0):
|
||||
list_unit: list = []
|
||||
|
||||
if unit == "storage":
|
||||
list_unit = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]
|
||||
elif unit == "data_rate":
|
||||
list_unit = ["bps", "Kbps", "Mbps", "Gbps", "Tbps", "Pbps"]
|
||||
elif unit == "binary_data_rate":
|
||||
list_unit = ["b/s", "Kib/s", "Mib/s", "Gib/s", "Tib/s", "Pib/s"]
|
||||
|
||||
factor = 1024 # Binäre Umrechnung
|
||||
|
||||
if source not in list_unit:
|
||||
raise ValueError("Ungültige Quell-Einheit!")
|
||||
|
||||
source_index = list_unit.index(source)
|
||||
|
||||
if target:
|
||||
if target not in list_unit:
|
||||
raise ValueError("Ungültige Ziel-Einheit!")
|
||||
target_index = list_unit.index(target)
|
||||
|
||||
if source_index < target_index:
|
||||
return size / (factor ** (target_index - source_index)), target
|
||||
else:
|
||||
return size * (factor ** (source_index - target_index)), target
|
||||
|
||||
# Automatische Umrechnung
|
||||
while size >= 1000 and source_index < len(list_unit) - 1:
|
||||
size /= factor
|
||||
source_index += 1
|
||||
|
||||
return [round(size,1), list_unit[source_index]]
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Media:
|
|||
self.source_file: str = path
|
||||
self.source_file_name: str = os.path.basename(self.source_file)
|
||||
self.source_duration: int = self.time_in_sec(streams_video[0]["tags"].get("DURATION" or "duration", "00:00:00"))
|
||||
self.source_size: int = 0
|
||||
self.source_size: list = self.size_convert("B", None, "storage", int(streams_format[0].get("size")))
|
||||
self.source_frame_rate: int = self.frame_rate(streams_video)
|
||||
self.source_frames_total: int = self.source_frame_rate * self.source_duration
|
||||
self.source_time: int = 0
|
||||
|
|
@ -172,4 +172,39 @@ class Media:
|
|||
h, m, s = map(float, parts) # In float umwandeln, falls Nachkommastellen im Sekundenwert sind
|
||||
return int(h * 3600 + m * 60 + s) # Alles in Sekunden umrechnen
|
||||
|
||||
raise ValueError(f"Ungültiges Zeitformat: {time_str}")
|
||||
raise ValueError(f"Ungültiges Zeitformat: {time_str}")
|
||||
|
||||
@staticmethod
|
||||
def size_convert(source: str, target, unit: str, size=0):
|
||||
list_unit: list = []
|
||||
|
||||
if unit == "storage":
|
||||
list_unit = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]
|
||||
elif unit == "data_rate":
|
||||
list_unit = ["bps", "Kbps", "Mbps", "Gbps", "Tbps", "Pbps"]
|
||||
elif unit == "binary_data_rate":
|
||||
list_unit = ["b/s", "Kib/s", "Mib/s", "Gib/s", "Tib/s", "Pib/s"]
|
||||
|
||||
factor = 1024 # Binäre Umrechnung
|
||||
|
||||
if source not in list_unit:
|
||||
raise ValueError("Ungültige Quell-Einheit!")
|
||||
|
||||
source_index = list_unit.index(source)
|
||||
|
||||
if target:
|
||||
if target not in list_unit:
|
||||
raise ValueError("Ungültige Ziel-Einheit!")
|
||||
target_index = list_unit.index(target)
|
||||
|
||||
if source_index < target_index:
|
||||
return size / (factor ** (target_index - source_index)), target
|
||||
else:
|
||||
return size * (factor ** (source_index - target_index)), target
|
||||
|
||||
# Automatische Umrechnung
|
||||
while size >= 1000 and source_index < len(list_unit) - 1:
|
||||
size /= factor
|
||||
source_index += 1
|
||||
|
||||
return [round(size, 1), list_unit[source_index]]
|
||||
|
|
@ -99,7 +99,7 @@ class Server:
|
|||
app.router.add_get("/", self.handle_index)
|
||||
app.router.add_get("/api/ip", self.handle_ip)
|
||||
app.router.add_get("/api/stats", self.handle_stat)
|
||||
app.router.add_static("/client", path="./client", name="client")
|
||||
app.router.add_static("/client/", path="./client", name="client")
|
||||
runner = web.AppRunner(app)
|
||||
await runner.setup()
|
||||
site = web.TCPSite(runner, "0.0.0.0", 8080)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>Websocket Client</title>
|
||||
<link rel="stylesheet" href="/client/index_style.css">
|
||||
<link rel="icon" href="/client/icons/favicon.ico" type="image/x-icon">
|
||||
</head>
|
||||
<body>
|
||||
<!-- === Menü === -->
|
||||
|
|
|
|||
Loading…
Reference in a new issue