[+] Colors
This commit is contained in:
+21
-11
@@ -3,6 +3,8 @@ from pathlib import Path
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from hypy_utils import printc
|
||||
|
||||
|
||||
def main():
|
||||
agupa = argparse.ArgumentParser("formtool", "ffmpeg shortcuts")
|
||||
@@ -12,14 +14,14 @@ def main():
|
||||
|
||||
# Process each file provided on the command line
|
||||
for inf in args.files:
|
||||
inf = Path(inf)
|
||||
inf: Path = Path(inf)
|
||||
|
||||
if not inf.exists():
|
||||
print(f"Error: File not found, skipping: {inf}", file=sys.stderr)
|
||||
printc(f"&cError: File not found, skipping: {inf}")
|
||||
continue
|
||||
|
||||
ouf = f'{inf.stem}.comp.av1.mp4'
|
||||
print(f"-> Compressing '{inf.name}'...")
|
||||
ouf = inf.with_name(f'{inf.stem}.comp.av1.mp4')
|
||||
printc(f"&e-> Compressing '{inf.name}' > '{ouf.name}'")
|
||||
|
||||
try:
|
||||
params = {
|
||||
@@ -30,28 +32,36 @@ def main():
|
||||
'-b:a': '96k',
|
||||
'-vbr': 'on',
|
||||
}
|
||||
old_size = inf.stat().st_size
|
||||
|
||||
# Check for any passthrough arguments and add them to params (overrides defaults)
|
||||
_tmp = iter(passthrough)
|
||||
for k, v in zip(_tmp, _tmp):
|
||||
print(f" Overriding parameter: {k} {v} (was {params.get(k, 'not set')})")
|
||||
printc(f"&a Overriding parameter: {k} {v} (was {params.get(k, 'not set')})")
|
||||
params[k] = v
|
||||
|
||||
# Construct and run the ffmpeg command
|
||||
cmd = ['ffmpeg', '-hide_banner', '-i', inf.absolute(), *sum(([k, v] for k, v in params.items()), []), ouf]
|
||||
print(f" Running command: {' '.join(cmd)}")
|
||||
printc(f"&e Running command: {' '.join(cmd)}")
|
||||
|
||||
check_call(cmd)
|
||||
print(f" Compression successful.")
|
||||
printc(f"&a Compression successful :)")
|
||||
new_size = ouf.stat().st_size
|
||||
ratio = new_size / old_size
|
||||
printc(f"&a Size: {old_size / 1_000_000:.2f} MB -> {new_size / 1_000_000:.2f} MB ({ratio:.2%})")
|
||||
|
||||
if not args.keep:
|
||||
inf.unlink()
|
||||
print(f" Removed original file: '{inf.name}'")
|
||||
if new_size >= old_size:
|
||||
printc(f"&c Warning: Compressed file is not smaller than original! Keeping original file.")
|
||||
else:
|
||||
inf.unlink()
|
||||
printc(f"&c Removed original file: '{inf.name}'")
|
||||
|
||||
print()
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred while processing {inf.name}: {e}", file=sys.stderr)
|
||||
print(" Leaving original file intact.\n", file=sys.stderr)
|
||||
printc(f"&cAn error occurred while processing {inf.name}: {e}")
|
||||
printc("&c Leaving original file intact.\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+3
-1
@@ -4,4 +4,6 @@ version = "0.1.0"
|
||||
description = "ffmpeg command shortcuts"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = []
|
||||
dependencies = [
|
||||
"hypy-utils>=1.0.29",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.10"
|
||||
|
||||
[[package]]
|
||||
name = "formtool"
|
||||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "hypy-utils" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "hypy-utils", specifier = ">=1.0.29" }]
|
||||
|
||||
[[package]]
|
||||
name = "hypy-utils"
|
||||
version = "1.0.29"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e1/02/6c93a5f7be972d55b4a29c14ffa4d9e1ae919449084861584dd2c18ba12a/hypy_utils-1.0.29.tar.gz", hash = "sha256:c72217df93e62f1c9af955e4f8cecd92ef51428c6c7399efc824cfb41fd9c4bd", size = 1403860, upload-time = "2024-12-10T11:51:14.233Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e8/34/7e4f6c09da586d317a74958e6b853da8a4c220898c5a8adf98030abb1492/hypy_utils-1.0.29-py3-none-any.whl", hash = "sha256:146a5aa85d3b4bc175e64d3f9e26befd0d87d221c4366eb70e137e46933eb65d", size = 18099, upload-time = "2024-12-10T11:51:12.019Z" },
|
||||
]
|
||||
Reference in New Issue
Block a user