scripts/encoder-parameters.py
Simon Bruder ecd7808dd1
Make scripts suitable for running on NixOS
Older scripts (that now have no real purpose) or ones that require
packages that are not in nixpkgs are not updated. They should either be
removed or fixed at a later date.
2020-08-25 23:52:58 +02:00

48 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p 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))