diff --git a/bin/__pycache__/handler.cpython-310.pyc b/bin/__pycache__/handler.cpython-310.pyc index 6e18d2f..b82cb66 100644 Binary files a/bin/__pycache__/handler.cpython-310.pyc and b/bin/__pycache__/handler.cpython-310.pyc differ diff --git a/bin/__pycache__/probe.cpython-310.pyc b/bin/__pycache__/probe.cpython-310.pyc new file mode 100644 index 0000000..13a8665 Binary files /dev/null and b/bin/__pycache__/probe.cpython-310.pyc differ diff --git a/bin/handler.py b/bin/handler.py index df1d42a..fc53012 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -10,8 +10,8 @@ import os import sys -import bin.lib.ffmpeg -ffmpeg = bin.lib.ffmpeg +import bin.probe +ffmpeg = bin.probe import configparser import time import shutil @@ -69,7 +69,7 @@ class Handler: if self.os_type == "linux": self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.filepath} {output_path}" elif self.os_type == "win32": - self.command = f"{fsrpath} -QualityMode {quality_setting} {self.filepath} {output_path}" + self.command = f"FidelityFX_CLI -QualityMode {quality_setting} {self.filepath} {output_path}" else: print("OS CURRENTLY UNSUPPORTED!") return False @@ -79,7 +79,7 @@ class Handler: if self.os_type == "linux": self.command = f"wine {fsrpath} -Scale {quality_setting} {quality_setting} {self.filepath} {output_path}" elif self.os_type == "win32": - self.command = f"{fsrpath} -Scale {quality_setting} {quality_setting} {self.filepath} {output_path}" + self.command = f"FidelityFX_CLI -Scale {quality_setting} {quality_setting} {self.filepath} {output_path}" else: print("OS CURRENTLY UNSUPPORTED!") return False @@ -190,7 +190,7 @@ class Handler: if self.os_type == "linux": self.command = f"wine {fsrpath} -QualityMode {quality_setting} {self.files_handle}" elif self.os_type == "win32": - self.command = f"{fsrpath} -QualityMode {quality_setting} {self.files_handle}" + self.command = f"FidelityFX_CLI -QualityMode {quality_setting} {self.files_handle}" else: print("OS CURRENTLY UNSUPPORTED!") return False @@ -199,7 +199,7 @@ class Handler: if self.os_type == "linux": self.command = f"wine {fsrpath} -Scale {quality_setting} {self.files_handle} {self.tmppath}" elif self.os_type == "win32": - self.command = f"{fsrpath} -Scale {quality_setting} {self.files_handle} {self.tmppath}" + self.command = f"FidelityFX_CLI -Scale {quality_setting} {self.files_handle} {self.tmppath}" else: print("OS CURRENTLY UNSUPPORTED!") return False diff --git a/bin/probe.py b/bin/probe.py new file mode 100644 index 0000000..b867b0f --- /dev/null +++ b/bin/probe.py @@ -0,0 +1,56 @@ +import json +import subprocess + +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable + +def convert_kwargs_to_cmd_line_args(kwargs): + """Helper function to build command line arguments out of dict.""" + args = [] + for k in sorted(kwargs.keys()): + v = kwargs[k] + if isinstance(v, Iterable) and not isinstance(v, str): + for value in v: + args.append('-{}'.format(k)) + if value is not None: + args.append('{}'.format(value)) + continue + args.append('-{}'.format(k)) + if v is not None: + args.append('{}'.format(v)) + return args + +class Error(Exception): + def __init__(self, cmd, stdout, stderr): + super(Error, self).__init__( + '{} error (see stderr output for detail)'.format(cmd) + ) + self.stdout = stdout + self.stderr = stderr + +def probe(filename, cmd='ffprobe', timeout=None, **kwargs): + """Run ffprobe on the specified file and return a JSON representation of the output. + + Raises: + :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code, + an :class:`Error` is returned with a generic error message. + The stderr output can be retrieved by accessing the + ``stderr`` property of the exception. + """ + args = [cmd, '-show_format', '-show_streams', '-of', 'json'] + args += convert_kwargs_to_cmd_line_args(kwargs) + args += [filename] + + p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + communicate_kwargs = {} + if timeout is not None: + communicate_kwargs['timeout'] = timeout + out, err = p.communicate(**communicate_kwargs) + if p.returncode != 0: + raise Error('ffprobe', out, err) + return json.loads(out.decode('utf-8')) + + +__all__ = ['probe']