47 lines
1.1 KiB
Python
Executable file
47 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import sys
|
|
import subprocess
|
|
import json
|
|
|
|
|
|
def is_number(value):
|
|
numeric_chars = [*map(str, range(10)), "-"]
|
|
numeric_charcodes = list(map(ord, numeric_chars))
|
|
|
|
return all(ord(char) in numeric_charcodes for char in value)
|
|
|
|
|
|
def parse_encoder_params(encoder_params):
|
|
for param in encoder_params.split(" / "):
|
|
if "=" in param:
|
|
key, value = param.split("=", 1)
|
|
|
|
if is_number(value):
|
|
value = int(value)
|
|
elif is_number(value.replace(".", "", 1)):
|
|
value = float(value)
|
|
else:
|
|
key = param
|
|
value = True
|
|
|
|
yield key, value
|
|
|
|
|
|
def run_mediainfo(file):
|
|
cmd = [
|
|
"mediainfo",
|
|
"--Inform=Video;%Encoded_Library%\\n%Encoded_Library_Settings%",
|
|
file,
|
|
]
|
|
process = subprocess.run(cmd, stdout=subprocess.PIPE)
|
|
output = process.stdout.decode("utf-8").split("\n")
|
|
|
|
encoder = output[0]
|
|
params = dict(parse_encoder_params(output[1]))
|
|
|
|
return {"file": file, "encoder": encoder, "params": params}
|
|
|
|
|
|
info = list(map(run_mediainfo, sys.argv[1:]))
|
|
print(json.dumps(info, indent=2, sort_keys=True))
|