69 lines
1.8 KiB
Python
Executable File
69 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from subprocess import check_output
|
|
import configparser
|
|
import os
|
|
import re
|
|
import sys
|
|
import MosDb
|
|
|
|
c = configparser.ConfigParser()
|
|
c.read("config.ini")
|
|
|
|
LOUDNESS_SCANNER = c.get("Tools", "LOUDNESS_SCANNER")
|
|
CLIP_PATH_TRANSFORM_FROM = c.get("MOS", "CLIP_PATH_TRANSFORM_FROM")
|
|
CLIP_PATH_TRANSFORM_TO = c.get("MOS", "CLIP_PATH_TRANSFORM_TO")
|
|
TARGET_LUFS = float(c.get("LUFS", "TARGET_VALUE"))
|
|
|
|
print("Loudness-Scanner: {}".format(LOUDNESS_SCANNER))
|
|
print("Path transform FROM: {}".format(CLIP_PATH_TRANSFORM_FROM))
|
|
print("Path transform TO : {}".format(CLIP_PATH_TRANSFORM_TO))
|
|
|
|
db = MosDb.MosDb()
|
|
|
|
todo = db.get_missing_lufs()
|
|
|
|
print("{} files to analyse.".format(len(todo)))
|
|
devnull = open(os.devnull, "w")
|
|
|
|
for f in todo:
|
|
objId = f[0]
|
|
objPath = f[1]
|
|
|
|
objFile = objPath.replace(CLIP_PATH_TRANSFORM_FROM, CLIP_PATH_TRANSFORM_TO).replace("\\", "/")
|
|
|
|
cmd = [LOUDNESS_SCANNER, "scan", "-l", objFile]
|
|
output = check_output(cmd, stderr=devnull)
|
|
output = output.decode('utf-8')
|
|
|
|
lines = output.split("\n")
|
|
valid = re.compile(r"^\s*(-.+) LUFS, (.+) LU, (.*)$")
|
|
|
|
have_lufs = False
|
|
for l in lines:
|
|
m = valid.match(l)
|
|
if not m:
|
|
continue
|
|
lufs = m.group(1)
|
|
lra = m.group(2)
|
|
print("Found LUFS for {}: {} (LRA: {} LU)".format(objId, lufs, lra), end="")
|
|
if lufs == "-inf":
|
|
lufs = -99.0
|
|
lra = 0.0
|
|
ldiff = 99.0
|
|
else:
|
|
lufs = float(lufs)
|
|
lra = float(lra)
|
|
ldiff = lufs - TARGET_LUFS
|
|
print(", diff to {}: {}".format(TARGET_LUFS, ldiff))
|
|
db.set_lufs(objId, lufs, lra, ldiff)
|
|
have_lufs = True
|
|
break
|
|
|
|
if not have_lufs:
|
|
print("ERROR analysing file for {}: {}".format(objId, objFile))
|
|
|
|
db.finish()
|
|
|