vnrecode: replace config class to params
This commit is contained in:
parent
f240fdca5f
commit
71c5764f26
5 changed files with 63 additions and 77 deletions
|
@ -9,7 +9,7 @@ packages = ["vnrecode", "unrenapk", "vnds2renpy"]
|
||||||
include-package-data = true
|
include-package-data = true
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
'vnrecode' = ['*.py', '*.toml']
|
'vnrecode' = ['*.py']
|
||||||
'vnds2renpy' = ['*.py']
|
'vnds2renpy' = ['*.py']
|
||||||
'unrenapk' = ['*.py']
|
'unrenapk' = ['*.py']
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,16 @@ from .application import Application
|
||||||
from .compress import Compress
|
from .compress import Compress
|
||||||
from .printer import Printer
|
from .printer import Printer
|
||||||
from .params import Params
|
from .params import Params
|
||||||
from .config import Config
|
|
||||||
from .utils import Utils
|
from .utils import Utils
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
config = Config.setup_config()
|
params = Params.setup()
|
||||||
params = Params.setup(config.config, config.args)
|
printer = Printer(params.source)
|
||||||
printer = Printer(config.args.source)
|
|
||||||
utils = Utils(params, printer)
|
utils = Utils(params, printer)
|
||||||
compress = Compress(params, printer, utils)
|
compress = Compress(params, printer, utils)
|
||||||
|
|
||||||
Application(params, config.args, compress, printer, utils).run()
|
Application(params, compress, printer, utils).run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -7,9 +7,8 @@ import os
|
||||||
|
|
||||||
class Application:
|
class Application:
|
||||||
|
|
||||||
def __init__(self, params, args, compress, printer, utils):
|
def __init__(self, params, compress, printer, utils):
|
||||||
self.params = params
|
self.params = params
|
||||||
self.args = args
|
|
||||||
self.compress = compress.compress
|
self.compress = compress.compress
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.utils = utils
|
self.utils = utils
|
||||||
|
@ -22,7 +21,7 @@ class Application:
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
self.printer.win_ascii_esc()
|
self.printer.win_ascii_esc()
|
||||||
|
|
||||||
source = os.path.abspath(self.args.source)
|
source = os.path.abspath(self.params.source)
|
||||||
|
|
||||||
if os.path.exists(f"{source}_compressed"):
|
if os.path.exists(f"{source}_compressed"):
|
||||||
shutil.rmtree(f"{source}_compressed")
|
shutil.rmtree(f"{source}_compressed")
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
from argparse import Namespace, ArgumentParser
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from sysconfig import get_path
|
|
||||||
from typing import Any
|
|
||||||
import tomllib
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Config:
|
|
||||||
|
|
||||||
config: dict[str, Any]
|
|
||||||
args: Namespace
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setup_config(cls):
|
|
||||||
default_config = os.path.join(get_path('purelib'), "vnrecode", "vnrecode.toml")
|
|
||||||
parser = ArgumentParser(prog="vnrecode",
|
|
||||||
description="Python utility to compress Visual Novel Resources"
|
|
||||||
)
|
|
||||||
parser.add_argument("source", help="SourceDir")
|
|
||||||
parser.add_argument("-c", "--config", default=default_config, help="ConfigFile")
|
|
||||||
parser.add_argument("-u", action="store_true", help="CopyUnprocessed")
|
|
||||||
parser.add_argument("-f", "--force", action="store_true", help="ForceCompress")
|
|
||||||
parser.add_argument("-m", "--mimic", action="store_true", help="MimicMode")
|
|
||||||
parser.add_argument("-s", "--silent", action="store_true", help="HideErrors")
|
|
||||||
parser.add_argument("--webprgba", action="store_true", help="WebpRGBA")
|
|
||||||
parser.add_argument("-j", "--jobs", type=int, help="Workers")
|
|
||||||
parser.add_argument("-ae", "--aext", help="Audio Extension")
|
|
||||||
parser.add_argument("-ab", "--abit", help="Audio Bitrate")
|
|
||||||
parser.add_argument("-id", "--idown", type=int, help="Image Downscale")
|
|
||||||
parser.add_argument("-ie", "--iext", help="Image Extension")
|
|
||||||
parser.add_argument("-ife", "--ifallext", help="Image Fallback Extension")
|
|
||||||
parser.add_argument("-il", "--ilossless", action="store_true", help="Image Lossless")
|
|
||||||
parser.add_argument("-iq", "--iquality", help="Image Quality")
|
|
||||||
parser.add_argument("--vcrf", help="Video CRF")
|
|
||||||
parser.add_argument("-vs", "--vskip", help="Video Skip")
|
|
||||||
parser.add_argument("-ve", "--vext", help="Video Extension")
|
|
||||||
parser.add_argument("-vc", "--vcodec", help="Video Codec")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if os.path.isfile(args.config):
|
|
||||||
with open(args.config, "rb") as cfile:
|
|
||||||
config = tomllib.load(cfile)
|
|
||||||
else:
|
|
||||||
print("Failed to find config. Check `vnrecode -h` to more info")
|
|
||||||
exit(255)
|
|
||||||
return cls(config=config, args=args)
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
from argparse import ArgumentParser
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
import tomllib
|
||||||
|
import os
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Params:
|
class Params:
|
||||||
|
@ -26,29 +28,64 @@ class Params:
|
||||||
video_ext: str
|
video_ext: str
|
||||||
video_codec: str
|
video_codec: str
|
||||||
|
|
||||||
|
source: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls, config, args) -> Self:
|
def setup(cls) -> Self:
|
||||||
copy_unprocessed = config["FFMPEG"]["CopyUnprocessed"] if not args.u else args.u
|
parser = ArgumentParser(prog="vnrecode",
|
||||||
force_compress = config["FFMPEG"]["ForceCompress"] if not args.force else args.force
|
description="Python utility to compress Visual Novel Resources"
|
||||||
mimic_mode = config["FFMPEG"]["MimicMode"] if not args.mimic else args.mimic
|
)
|
||||||
hide_errors = config["FFMPEG"]["HideErrors"] if not args.silent else args.silent
|
parser.add_argument("source", help="SourceDir")
|
||||||
workers = config["FFMPEG"]["Workers"] if args.jobs is None else args.jobs
|
parser.add_argument("-c", "--config", help="ConfigFile")
|
||||||
webp_rgba = config["FFMPEG"]["WebpRGBA"] if not args.webprgba else args.webprgba
|
parser.add_argument("-u", type=bool, help="CopyUnprocessed", default=True)
|
||||||
audio_ext = config["AUDIO"]["Extension"] if args.aext is None else args.aext
|
parser.add_argument("-f", "--force", type=bool, help="ForceCompress", default=False)
|
||||||
audio_bitrate = config["AUDIO"]["BitRate"] if args.abit is None else args.abit
|
parser.add_argument("-m", "--mimic", type=bool, help="MimicMode", default=True)
|
||||||
image_downscale = config["IMAGE"]["ResDownScale"] if args.idown is None else args.idown
|
parser.add_argument("-s", "--silent", type=bool, help="HideErrors", default=True)
|
||||||
image_ext = config["IMAGE"]["Extension"] if args.iext is None else args.iext
|
parser.add_argument("--webprgba", type=bool, help="WebpRGBA", default=True)
|
||||||
image_fall_ext = config["IMAGE"]["FallBackExtension"] if args.ifallext is None else args.ifallext
|
parser.add_argument("-j", "--jobs", type=int, help="Workers", default=16)
|
||||||
image_lossless = config["IMAGE"]["Lossless"] if not args.ilossless else args.ilossless
|
parser.add_argument("-ae", "--aext", help="Audio Extension", default="opus")
|
||||||
image_quality = config["IMAGE"]["Quality"] if args.iquality is None else args.iquality
|
parser.add_argument("-ab", "--abit", help="Audio Bitrate", default="128k")
|
||||||
video_crf = config["VIDEO"]["CRF"] if args.vcrf is None else args.vcrf
|
parser.add_argument("-id", "--idown", type=int, help="Image Downscale", default=1)
|
||||||
video_skip = config["VIDEO"]["SkipVideo"] if args.vskip is None else args.vskip
|
parser.add_argument("-ie", "--iext", help="Image Extension", default="avif")
|
||||||
video_ext = config["VIDEO"]["Extension"] if args.vext is None else args.vext
|
parser.add_argument("-ife", "--ifallext", help="Image Fallback Extension", default="webp")
|
||||||
video_codec = config["VIDEO"]["Codec"] if args.vcodec is None else args.vcodec
|
parser.add_argument("-il", "--ilossless", type=bool, help="Image Lossless", default=True)
|
||||||
|
parser.add_argument("-iq", "--iquality", type=int, help="Image Quality", default=100)
|
||||||
|
parser.add_argument("--vcrf", help="Video CRF", type=int, default=27)
|
||||||
|
parser.add_argument("-vs", "--vskip", help="Video Skip", default=False)
|
||||||
|
parser.add_argument("-ve", "--vext", help="Video Extension", default="webm")
|
||||||
|
parser.add_argument("-vc", "--vcodec", help="Video Codec", default="libvpx-vp9")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.config is not None:
|
||||||
|
if os.path.isfile(args.config):
|
||||||
|
with open(args.config, "rb") as cfile:
|
||||||
|
config = tomllib.load(cfile)
|
||||||
|
else:
|
||||||
|
print("Failed to find config. Check `vnrecode -h` to more info")
|
||||||
|
exit(255)
|
||||||
|
|
||||||
|
copy_unprocessed = config["FFMPEG"]["CopyUnprocessed"] if args.config else args.u
|
||||||
|
force_compress = config["FFMPEG"]["ForceCompress"] if args.config else args.force
|
||||||
|
mimic_mode = config["FFMPEG"]["MimicMode"] if args.config else args.mimic
|
||||||
|
hide_errors = config["FFMPEG"]["HideErrors"] if args.config else args.silent
|
||||||
|
workers = config["FFMPEG"]["Workers"] if args.config else args.jobs
|
||||||
|
webp_rgba = config["FFMPEG"]["WebpRGBA"] if args.config else args.webprgba
|
||||||
|
audio_ext = config["AUDIO"]["Extension"] if args.config else args.aext
|
||||||
|
audio_bitrate = config["AUDIO"]["BitRate"] if args.config else args.abit
|
||||||
|
image_downscale = config["IMAGE"]["ResDownScale"] if args.config else args.idown
|
||||||
|
image_ext = config["IMAGE"]["Extension"] if args.config else args.iext
|
||||||
|
image_fall_ext = config["IMAGE"]["FallBackExtension"] if args.config else args.ifallext
|
||||||
|
image_lossless = config["IMAGE"]["Lossless"] if args.config else args.ilossless
|
||||||
|
image_quality = config["IMAGE"]["Quality"] if args.config else args.iquality
|
||||||
|
video_crf = config["VIDEO"]["CRF"] if args.config else args.vcrf
|
||||||
|
video_skip = config["VIDEO"]["SkipVideo"] if args.config else args.vskip
|
||||||
|
video_ext = config["VIDEO"]["Extension"] if args.config else args.vext
|
||||||
|
video_codec = config["VIDEO"]["Codec"] if args.config else args.vcodec
|
||||||
|
source = args.source
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
copy_unprocessed, force_compress, mimic_mode, hide_errors, webp_rgba, workers,
|
copy_unprocessed, force_compress, mimic_mode, hide_errors, webp_rgba, workers,
|
||||||
audio_ext, audio_bitrate,
|
audio_ext, audio_bitrate,
|
||||||
image_downscale, image_ext, image_fall_ext, image_lossless, image_quality,
|
image_downscale, image_ext, image_fall_ext, image_lossless, image_quality,
|
||||||
video_crf, video_skip, video_ext, video_codec
|
video_crf, video_skip, video_ext, video_codec, source
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue