From c67c4631e9e17451eb1b29d2ffd8c2ae0d6e6795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sat, 6 Jan 2024 07:16:42 +0500 Subject: [PATCH] =?UTF-8?q?v1.0.1=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scan-vid.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/scan-vid.py b/scan-vid.py index 9775fa5..82c6b19 100644 --- a/scan-vid.py +++ b/scan-vid.py @@ -2,8 +2,10 @@ # выбирает информацию по видео файлу. +import os import subprocess import json +import zlib import datetime # правильный перевод! @@ -26,9 +28,38 @@ def humanbytes(B): elif TB <= B: return '{0:.2f} TB'.format(B / TB) +# file_info +def file_info(fn): + meta = {} + with open(fn, 'rb') as fp: + filename, file_extension = os.path.splitext(fn) + created = os.path.getmtime(fn) + dt_m = datetime.datetime.fromtimestamp(created) + size = os.path.getsize(fn) + data = fp.read() + + meta["name"] = fn + meta["path"] = os.path.splitdrive(fn)[1] + meta["ext"] = file_extension.lower() + meta["date"] = dt_m + meta["type"] = "meta" + meta["crc"] = zlib.crc32(data) + meta["size"] = size + return meta + +def humanbitrate(s): + items = s.split("/") + a = float(items[0]) + b = float(items[1]) + bitrate = "%8.1f" % (a / b) + return bitrate.strip() + # =================== начало программы ==================== file = "d:/vids/sea/Ça (1978) (+18) - поиск Яндекса по видео.mp4" +meta = file_info(file) +#print(meta) + cmd = "ffprobe -v quiet -print_format json -show_format -show_streams \"%s\"" % file output = subprocess.run(cmd, capture_output=True, text=True, shell=True) @@ -44,10 +75,15 @@ total_seconds = datetime.timedelta(seconds=float(data["format"]["duration"])) info["duration"] = datetime.datetime.strptime(str(total_seconds), "%H:%M:%S.%f").strftime("%H:%M:%S") info["width"] = data["streams"][0]["width"] info["height"] = data["streams"][0]["height"] -info["bit_rate"] = data["streams"][0]["avg_frame_rate"] +info["bit_rate"] = humanbitrate(data["streams"][0]["avg_frame_rate"]) info["codec"] = data["streams"][0]["codec_name"] -info["filename"] = data["format"]["filename"] -info["size"] = humanbytes(data["format"]["size"]) +info["filename"] = meta["name"] +info["ext"] = meta["ext"] +info["crc"] = meta["crc"] +info["created"] = meta["date"] +info["hcreated"] = meta["date"].strftime("%d.%m.%Y") +info["size"] = data["format"]["size"] +info["hsize"] = humanbytes(data["format"]["size"]) print(info)