|
|
|
@ -54,9 +54,19 @@ def humanbitrate(s):
|
|
|
|
|
bitrate = "%8.1f" % (a / b)
|
|
|
|
|
return bitrate.strip()
|
|
|
|
|
|
|
|
|
|
# =================== начало программы ====================
|
|
|
|
|
# крманда ffmpeg для получения постера
|
|
|
|
|
def poster(fn):
|
|
|
|
|
seconds = 5
|
|
|
|
|
path = fn
|
|
|
|
|
image = postername(fn)
|
|
|
|
|
ffmpeg = "ffmpeg -ss %s -i \"%s\" -f image2 -vframes 1 -y \"%s\"" % (seconds, path, image)
|
|
|
|
|
return ffmpeg
|
|
|
|
|
|
|
|
|
|
def postername(file_path):
|
|
|
|
|
file_name, file_extension = os.path.splitext(file_path)
|
|
|
|
|
return file_name + ".jpg"
|
|
|
|
|
|
|
|
|
|
file = "d:/vids/sea/Ça (1978) (+18) - поиск Яндекса по видео.mp4"
|
|
|
|
|
def check_file(file):
|
|
|
|
|
meta = file_info(file)
|
|
|
|
|
#print(meta)
|
|
|
|
|
|
|
|
|
@ -68,16 +78,21 @@ output = subprocess.run(cmd, capture_output=True, text=True, shell=True)
|
|
|
|
|
#print(output)
|
|
|
|
|
|
|
|
|
|
data = json.loads(output.stdout)
|
|
|
|
|
info = {}
|
|
|
|
|
|
|
|
|
|
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["duration"] = total_seconds
|
|
|
|
|
#print("seconds", total_seconds, file)
|
|
|
|
|
info["hduration"] = "00:00:00"
|
|
|
|
|
try:
|
|
|
|
|
info["hduration"] = datetime.datetime.strptime(str(total_seconds), "%H:%M:%S.%f").strftime("%H:%M:%S")
|
|
|
|
|
except:
|
|
|
|
|
print("не удалось получить:", total_seconds)
|
|
|
|
|
info["width"] = data["streams"][0]["width"]
|
|
|
|
|
info["height"] = data["streams"][0]["height"]
|
|
|
|
|
info["bit_rate"] = humanbitrate(data["streams"][0]["avg_frame_rate"])
|
|
|
|
|
info["codec"] = data["streams"][0]["codec_name"]
|
|
|
|
|
|
|
|
|
|
info["filename"] = meta["name"]
|
|
|
|
|
info["ext"] = meta["ext"]
|
|
|
|
|
info["crc"] = meta["crc"]
|
|
|
|
@ -85,5 +100,31 @@ info["created"] = meta["date"]
|
|
|
|
|
info["hcreated"] = meta["date"].strftime("%d.%m.%Y")
|
|
|
|
|
info["size"] = data["format"]["size"]
|
|
|
|
|
info["hsize"] = humanbytes(data["format"]["size"])
|
|
|
|
|
info["poster"] = poster(file)
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def valid_file(file):
|
|
|
|
|
valid_ext = ["mp4", "mpeg", "webm"]
|
|
|
|
|
ext = file.split(".")[-1]
|
|
|
|
|
for e in valid_ext:
|
|
|
|
|
if ext == e:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# =================== начало программы ====================
|
|
|
|
|
|
|
|
|
|
dir = "d:\\vids\\ero"
|
|
|
|
|
|
|
|
|
|
print(info)
|
|
|
|
|
files = os.listdir(dir)
|
|
|
|
|
for file in files:
|
|
|
|
|
if valid_file(file):
|
|
|
|
|
path = os.path.join(dir, file)
|
|
|
|
|
print(path)
|
|
|
|
|
try:
|
|
|
|
|
meta = check_file(path)
|
|
|
|
|
print(meta)
|
|
|
|
|
except:
|
|
|
|
|
print("=== Не удалось обработать файл:", path)
|
|
|
|
|
else:
|
|
|
|
|
print("пропускаем файл:", file)
|
|
|
|
|