diff options
| author | MetroWind <chris.corsair@gmail.com> | 2025-11-02 14:54:22 -0800 |
|---|---|---|
| committer | MetroWind <chris.corsair@gmail.com> | 2025-11-02 14:54:22 -0800 |
| commit | fbd38acebbced481c0487e15313dabc924da2cb3 (patch) | |
| tree | 3c53b3b0ffa16236ca80968d81c16603a2ddb230 /ffmagick | |
| parent | d72388fcaf7edc74f15fddfed58e17a7500da458 (diff) | |
ffmagick: add option to set output dir.
Diffstat (limited to 'ffmagick')
| -rw-r--r-- | ffmagick/ffmagick.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/ffmagick/ffmagick.py b/ffmagick/ffmagick.py index 08191bc..794bb4d 100644 --- a/ffmagick/ffmagick.py +++ b/ffmagick/ffmagick.py | |||
| @@ -130,8 +130,15 @@ class Configuration: | |||
| 130 | if p.name == name: | 130 | if p.name == name: |
| 131 | return p | 131 | return p |
| 132 | 132 | ||
| 133 | def runOnce(config, profile, input_file): | 133 | def runOnce(config, profile, input_file, output_dir): |
| 134 | output_file = os.path.splitext(input_file)[0] + "." + profile.output_ext | 134 | if output_dir is None: |
| 135 | output_file = os.path.splitext(input_file)[0] + "." + profile.output_ext | ||
| 136 | else: | ||
| 137 | output_file = os.path.join(output_dir, os.path.basename(input_file)) | ||
| 138 | output_file = os.path.splitext(output_file)[0] + "." + \ | ||
| 139 | profile.output_ext | ||
| 140 | if not os.path.exists(output_dir): | ||
| 141 | os.makedirs(output_dir) | ||
| 135 | if profile.processor == Processor.FFMPEG: | 142 | if profile.processor == Processor.FFMPEG: |
| 136 | cmd = "\"{}\" -y -i \"{}\" {} \"{}\"".format( | 143 | cmd = "\"{}\" -y -i \"{}\" {} \"{}\"".format( |
| 137 | config.ffmpeg_bin, input_file, profile.command, output_file) | 144 | config.ffmpeg_bin, input_file, profile.command, output_file) |
| @@ -141,11 +148,11 @@ def runOnce(config, profile, input_file): | |||
| 141 | return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 148 | return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| 142 | text=True) | 149 | text=True) |
| 143 | 150 | ||
| 144 | def runAll(config, profile, input_files): | 151 | def runAll(config, profile, input_files, output_dir): |
| 145 | bar = Progress("Processing", max=len(input_files)) | 152 | bar = Progress("Processing", max=len(input_files)) |
| 146 | for f in input_files: | 153 | for f in input_files: |
| 147 | bar.next() | 154 | bar.next() |
| 148 | result = runOnce(config, profile, f) | 155 | result = runOnce(config, profile, f, output_dir) |
| 149 | if result.returncode != 0: | 156 | if result.returncode != 0: |
| 150 | bar.finish() | 157 | bar.finish() |
| 151 | print("ERROR: failed to process {}. Log:\n") | 158 | print("ERROR: failed to process {}. Log:\n") |
| @@ -168,6 +175,10 @@ def main(): | |||
| 168 | parser.add_argument("--list-config-files", action="store_true", | 175 | parser.add_argument("--list-config-files", action="store_true", |
| 169 | dest="should_list_conf_files", | 176 | dest="should_list_conf_files", |
| 170 | help="List all config files found") | 177 | help="List all config files found") |
| 178 | parser.add_argument("-o", "--output-dir", metavar="DIR", dest="output_dir", | ||
| 179 | help="Write the processed files into directory DIR. " | ||
| 180 | "Create if not exists. Default: same directory as the " | ||
| 181 | "input files.") | ||
| 171 | args = parser.parse_args() | 182 | args = parser.parse_args() |
| 172 | 183 | ||
| 173 | config = Configuration.get() | 184 | config = Configuration.get() |
| @@ -186,7 +197,11 @@ def main(): | |||
| 186 | print("Profile needed") | 197 | print("Profile needed") |
| 187 | return 1 | 198 | return 1 |
| 188 | 199 | ||
| 189 | if not runAll(config, config.getProfile(args.profile), args.files): | 200 | output_dir = None |
| 201 | if "output_dir" in args: | ||
| 202 | output_dir = args.output_dir | ||
| 203 | if not runAll(config, config.getProfile(args.profile), args.files, | ||
| 204 | output_dir): | ||
| 190 | return 1 | 205 | return 1 |
| 191 | 206 | ||
| 192 | return 0 | 207 | return 0 |
