From eb9e509ef8cad776a8a72b2c68a72a49d96b9c4c 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 06:48:11 +0500 Subject: [PATCH] v1.0.0 --- README.md | 12 ++++++++---- scan-vid.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 scan-vid.py diff --git a/README.md b/README.md index bba8948..6a2702d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ -# scan-vid - -scan-vid получение мета информации по видео. +# scan-vid + +Сканирует видео-файлы для получения мета информации + + +## Особенности + +Использует ffprobe для получения информации в виде json файла -Сканирует каталоги \ No newline at end of file diff --git a/scan-vid.py b/scan-vid.py new file mode 100644 index 0000000..9775fa5 --- /dev/null +++ b/scan-vid.py @@ -0,0 +1,53 @@ +#!/usr/local/bin/python + +# выбирает информацию по видео файлу. + +import subprocess +import json +import datetime + +# правильный перевод! +def humanbytes(B): + """Return the given bytes as a human friendly KB, MB, GB, or TB string.""" + B = float(B) + KB = float(1024) + MB = float(KB ** 2) # 1,048,576 + GB = float(KB ** 3) # 1,073,741,824 + TB = float(KB ** 4) # 1,099,511,627,776 + + if B < KB: + return '{0} {1}'.format(B,'Bytes' if 0 == B > 1 else 'Byte') + elif KB <= B < MB: + return '{0:.2f} KB'.format(B / KB) + elif MB <= B < GB: + return '{0:.2f} MB'.format(B / MB) + elif GB <= B < TB: + return '{0:.2f} GB'.format(B / GB) + elif TB <= B: + return '{0:.2f} TB'.format(B / TB) + +# =================== начало программы ==================== + +file = "d:/vids/sea/Ça (1978) (+18) - поиск Яндекса по видео.mp4" +cmd = "ffprobe -v quiet -print_format json -show_format -show_streams \"%s\"" % file +output = subprocess.run(cmd, capture_output=True, text=True, shell=True) + +# обычный вывод +#output = subprocess.run(cmd, text=True, shell=True) +#print(output) + +data = json.loads(output.stdout) +info = {} + +info["audio"] = len(data["streams"]) > 1 +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["codec"] = data["streams"][0]["codec_name"] + +info["filename"] = data["format"]["filename"] +info["size"] = humanbytes(data["format"]["size"]) + +print(info)