vicompres 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kirill Pechenkin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: vicompres
3
+ Version: 0.3.0
4
+ Summary: Efficiently compress video files using ffmpeg
5
+ Keywords: video,compression,ffmpeg,cli
6
+ Author: Kirill Pechenkin
7
+ Author-email: Kirill Pechenkin <pechkirill@mail.ru>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: End Users/Desktop
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Multimedia :: Video :: Conversion
20
+ Requires-Dist: click>=8.1
21
+ Requires-Python: >=3.10
22
+ Project-URL: Homepage, https://github.com/kirillismad/vicompres
23
+ Project-URL: Repository, https://github.com/kirillismad/vicompres
24
+ Project-URL: Issues, https://github.com/kirillismad/vicompres/issues
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Vicompres
28
+
29
+ Vicompres is a CLI tool to efficiently compress video files using ffmpeg. It
30
+ provides a simple interface for batch-compressing videos with configurable
31
+ quality levels.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ uv tool install vicompres
37
+ ```
38
+
39
+ Or run it without installing:
40
+
41
+ ```bash
42
+ uvx vicompres 'videos/*.mp4'
43
+ ```
44
+
45
+ With pip: `pip install vicompres`.
46
+
47
+ **Prerequisite:** [ffmpeg](https://ffmpeg.org/) (with ffprobe) must be
48
+ installed and available in your PATH.
49
+
50
+ ## Usage
51
+
52
+ ```bash
53
+ vicompres [OPTIONS] PATTERNS...
54
+ ```
55
+
56
+ Each pattern is a file, a directory (all videos directly inside it) or a glob
57
+ pattern. Quote a pattern to let vicompres expand it itself; `**` matches nested
58
+ directories. Hidden files and files with other extensions are left out.
59
+
60
+ ```bash
61
+ vicompres clip.mp4 other.mkv # files
62
+ vicompres trip/ # every video in trip/
63
+ vicompres *.mov # expanded by the shell
64
+ vicompres -c 7 'videos/**/*.mp4' # expanded by vicompres, recursively
65
+ vicompres -r -o small/ 'trip/*' # write to small/, delete originals
66
+ ```
67
+
68
+ Options:
69
+
70
+ - `-c`, `--compression`: compression level 1-10 (default 5). Higher levels
71
+ produce smaller files at lower quality and take more time. Each level maps to
72
+ an ffmpeg preset, quality setting (CRF for H.264, `-q:v` for MPEG-4 in
73
+ `.avi`) and audio bitrate.
74
+ - `-o`, `--output`: directory for the compressed files. By default each copy is
75
+ written next to its original.
76
+ - `-s`, `--suffix`: suffix of the output names, `clip.mp4` -> `clip.<suffix>.mp4`
77
+ (default `compressed`).
78
+ - `-r`, `--remove-original`: delete each original after it is compressed. If the
79
+ compressed copy is not smaller, the original is kept and the copy is removed.
80
+ - `--overwrite`: replace compressed copies that already exist. By default a file
81
+ whose copy already exists is skipped.
82
+
83
+ Recognising compressed files:
84
+
85
+ Every file vicompres writes carries a tag in its metadata, for example
86
+ `encoded_by=vicompres 0.3.0; level 5`. Files with this tag are skipped, so
87
+ running vicompres again over the same files, or over a folder that mixes
88
+ originals and compressed copies, does not compress anything twice. The tag
89
+ stays with the file when it is renamed, moved or copied. To see it:
90
+
91
+ ```bash
92
+ ffprobe -v error -show_entries format_tags=encoded_by clip.compressed.mp4
93
+ ```
94
+
95
+ If two files would be written to the same output path (for example
96
+ `a/clip.mp4` and `b/clip.mp4` with `-o out`), vicompres stops before
97
+ compressing anything.
98
+
99
+ Supported file extensions:
100
+
101
+ | Extension | Video codec | Audio codec | Other streams |
102
+ | --------- | ----------- | ----------- | --------------------------------------------- |
103
+ | `.mp4` | H.264 | AAC | first video and audio stream |
104
+ | `.mov` | H.264 | AAC | first video and audio stream |
105
+ | `.mkv` | H.264 | AAC | all audio tracks, subtitles and attachments |
106
+ | `.avi` | MPEG-4 | MP3 | first video and audio stream |
107
+
108
+ Metadata of the original, including the location and camera tags of iPhone
109
+ videos, is copied to the compressed file.
110
+
111
+ Graceful shutdown:
112
+
113
+ Press Ctrl+C once to finish the current file and stop before the next one.
114
+ Press it again to stop immediately: the file in progress is discarded. A file is
115
+ written under its final name only after ffmpeg succeeds, so an interrupted or
116
+ failed run never leaves partial output.
117
+
118
+ Exit codes:
119
+
120
+ - `0`: all files were compressed or skipped as already compressed.
121
+ - `1`: a file failed to compress, no video matched the patterns, output files
122
+ conflict, or ffmpeg is missing.
123
+ - `2`: invalid command-line arguments or a path that does not exist.
124
+ - `130`: interrupted with Ctrl+C (`143` for SIGTERM, `129` for SIGHUP).
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ uv sync # create .venv and install the project in editable mode
130
+ uv run vicompres --help # run the CLI from the source tree
131
+ uvx ruff check # lint (rules are in pyproject.toml)
132
+ uvx ruff format # format
133
+ uv build # build sdist and wheel into dist/
134
+ uv publish # upload to PyPI
135
+ ```
136
+
137
+ `python -m vicompres` runs the CLI too; `vicompres --version` prints the
138
+ version.
139
+
140
+ Package layout:
141
+
142
+ | Module | Responsibility |
143
+ | --------------- | --------------------------------------------------------- |
144
+ | `cli.py` | click command: options, wiring, exit codes |
145
+ | `compressor.py` | `BatchCompressor`: runs a batch, reports to a `Reporter` |
146
+ | `console.py` | `ConsoleReporter`: terminal output |
147
+ | `ffmpeg.py` | `FFmpeg`: builds and runs ffmpeg commands |
148
+ | `files.py` | `select_inputs` for patterns, `OutputNamer` for outputs |
149
+ | `marker.py` | `Marker`: the tag that identifies compressed files |
150
+ | `profiles.py` | compression levels and per-container codec settings |
151
+ | `shutdown.py` | `ShutdownController`: graceful and forced stop on signals |
152
+
153
+ The core does not print anything, so it can be used as a library:
154
+
155
+ ```python
156
+ from vicompres import BatchCompressor, CompressionOptions, select_inputs
157
+
158
+ files = select_inputs(["videos/**/*.mp4"]).files
159
+ report = BatchCompressor(CompressionOptions(level=7)).run(files)
160
+ print(report.succeeded, report.bytes_saved)
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT
@@ -0,0 +1,139 @@
1
+ # Vicompres
2
+
3
+ Vicompres is a CLI tool to efficiently compress video files using ffmpeg. It
4
+ provides a simple interface for batch-compressing videos with configurable
5
+ quality levels.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ uv tool install vicompres
11
+ ```
12
+
13
+ Or run it without installing:
14
+
15
+ ```bash
16
+ uvx vicompres 'videos/*.mp4'
17
+ ```
18
+
19
+ With pip: `pip install vicompres`.
20
+
21
+ **Prerequisite:** [ffmpeg](https://ffmpeg.org/) (with ffprobe) must be
22
+ installed and available in your PATH.
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ vicompres [OPTIONS] PATTERNS...
28
+ ```
29
+
30
+ Each pattern is a file, a directory (all videos directly inside it) or a glob
31
+ pattern. Quote a pattern to let vicompres expand it itself; `**` matches nested
32
+ directories. Hidden files and files with other extensions are left out.
33
+
34
+ ```bash
35
+ vicompres clip.mp4 other.mkv # files
36
+ vicompres trip/ # every video in trip/
37
+ vicompres *.mov # expanded by the shell
38
+ vicompres -c 7 'videos/**/*.mp4' # expanded by vicompres, recursively
39
+ vicompres -r -o small/ 'trip/*' # write to small/, delete originals
40
+ ```
41
+
42
+ Options:
43
+
44
+ - `-c`, `--compression`: compression level 1-10 (default 5). Higher levels
45
+ produce smaller files at lower quality and take more time. Each level maps to
46
+ an ffmpeg preset, quality setting (CRF for H.264, `-q:v` for MPEG-4 in
47
+ `.avi`) and audio bitrate.
48
+ - `-o`, `--output`: directory for the compressed files. By default each copy is
49
+ written next to its original.
50
+ - `-s`, `--suffix`: suffix of the output names, `clip.mp4` -> `clip.<suffix>.mp4`
51
+ (default `compressed`).
52
+ - `-r`, `--remove-original`: delete each original after it is compressed. If the
53
+ compressed copy is not smaller, the original is kept and the copy is removed.
54
+ - `--overwrite`: replace compressed copies that already exist. By default a file
55
+ whose copy already exists is skipped.
56
+
57
+ Recognising compressed files:
58
+
59
+ Every file vicompres writes carries a tag in its metadata, for example
60
+ `encoded_by=vicompres 0.3.0; level 5`. Files with this tag are skipped, so
61
+ running vicompres again over the same files, or over a folder that mixes
62
+ originals and compressed copies, does not compress anything twice. The tag
63
+ stays with the file when it is renamed, moved or copied. To see it:
64
+
65
+ ```bash
66
+ ffprobe -v error -show_entries format_tags=encoded_by clip.compressed.mp4
67
+ ```
68
+
69
+ If two files would be written to the same output path (for example
70
+ `a/clip.mp4` and `b/clip.mp4` with `-o out`), vicompres stops before
71
+ compressing anything.
72
+
73
+ Supported file extensions:
74
+
75
+ | Extension | Video codec | Audio codec | Other streams |
76
+ | --------- | ----------- | ----------- | --------------------------------------------- |
77
+ | `.mp4` | H.264 | AAC | first video and audio stream |
78
+ | `.mov` | H.264 | AAC | first video and audio stream |
79
+ | `.mkv` | H.264 | AAC | all audio tracks, subtitles and attachments |
80
+ | `.avi` | MPEG-4 | MP3 | first video and audio stream |
81
+
82
+ Metadata of the original, including the location and camera tags of iPhone
83
+ videos, is copied to the compressed file.
84
+
85
+ Graceful shutdown:
86
+
87
+ Press Ctrl+C once to finish the current file and stop before the next one.
88
+ Press it again to stop immediately: the file in progress is discarded. A file is
89
+ written under its final name only after ffmpeg succeeds, so an interrupted or
90
+ failed run never leaves partial output.
91
+
92
+ Exit codes:
93
+
94
+ - `0`: all files were compressed or skipped as already compressed.
95
+ - `1`: a file failed to compress, no video matched the patterns, output files
96
+ conflict, or ffmpeg is missing.
97
+ - `2`: invalid command-line arguments or a path that does not exist.
98
+ - `130`: interrupted with Ctrl+C (`143` for SIGTERM, `129` for SIGHUP).
99
+
100
+ ## Development
101
+
102
+ ```bash
103
+ uv sync # create .venv and install the project in editable mode
104
+ uv run vicompres --help # run the CLI from the source tree
105
+ uvx ruff check # lint (rules are in pyproject.toml)
106
+ uvx ruff format # format
107
+ uv build # build sdist and wheel into dist/
108
+ uv publish # upload to PyPI
109
+ ```
110
+
111
+ `python -m vicompres` runs the CLI too; `vicompres --version` prints the
112
+ version.
113
+
114
+ Package layout:
115
+
116
+ | Module | Responsibility |
117
+ | --------------- | --------------------------------------------------------- |
118
+ | `cli.py` | click command: options, wiring, exit codes |
119
+ | `compressor.py` | `BatchCompressor`: runs a batch, reports to a `Reporter` |
120
+ | `console.py` | `ConsoleReporter`: terminal output |
121
+ | `ffmpeg.py` | `FFmpeg`: builds and runs ffmpeg commands |
122
+ | `files.py` | `select_inputs` for patterns, `OutputNamer` for outputs |
123
+ | `marker.py` | `Marker`: the tag that identifies compressed files |
124
+ | `profiles.py` | compression levels and per-container codec settings |
125
+ | `shutdown.py` | `ShutdownController`: graceful and forced stop on signals |
126
+
127
+ The core does not print anything, so it can be used as a library:
128
+
129
+ ```python
130
+ from vicompres import BatchCompressor, CompressionOptions, select_inputs
131
+
132
+ files = select_inputs(["videos/**/*.mp4"]).files
133
+ report = BatchCompressor(CompressionOptions(level=7)).run(files)
134
+ print(report.succeeded, report.bytes_saved)
135
+ ```
136
+
137
+ ## License
138
+
139
+ MIT
@@ -0,0 +1,99 @@
1
+ [project]
2
+ name = "vicompres"
3
+ version = "0.3.0"
4
+ description = "Efficiently compress video files using ffmpeg"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = [
9
+ "video",
10
+ "compression",
11
+ "ffmpeg",
12
+ "cli",
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: End Users/Desktop",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Multimedia :: Video :: Conversion",
25
+ ]
26
+ requires-python = ">=3.10"
27
+ dependencies = ["click>=8.1"]
28
+
29
+ [[project.authors]]
30
+ name = "Kirill Pechenkin"
31
+ email = "pechkirill@mail.ru"
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/kirillismad/vicompres"
35
+ Repository = "https://github.com/kirillismad/vicompres"
36
+ Issues = "https://github.com/kirillismad/vicompres/issues"
37
+
38
+ [project.scripts]
39
+ vicompres = "vicompres.cli:main"
40
+
41
+ [build-system]
42
+ requires = ["uv_build>=0.13.5,<0.14.0"]
43
+ build-backend = "uv_build"
44
+
45
+ [tool.uv.build-backend]
46
+ module-name = "vicompres"
47
+ module-root = ""
48
+
49
+ [tool.ruff]
50
+ line-length = 100
51
+
52
+ [tool.ruff.lint]
53
+ select = [
54
+ "E",
55
+ "W",
56
+ "F",
57
+ "I",
58
+ "N",
59
+ "UP",
60
+ "B",
61
+ "A",
62
+ "C4",
63
+ "PIE",
64
+ "RET",
65
+ "SIM",
66
+ "PTH",
67
+ "S",
68
+ "T20",
69
+ "EXE",
70
+ "TRY",
71
+ "PERF",
72
+ "FURB",
73
+ "PL",
74
+ "RUF",
75
+ ]
76
+ ignore = [
77
+ "S603",
78
+ "S607",
79
+ "TRY003",
80
+ ]
81
+ allowed-confusables = ["–"]
82
+
83
+ [tool.ruff.lint.per-file-ignores]
84
+ "vicompres/cli.py" = [
85
+ "PLR0913",
86
+ "PLR0917",
87
+ ]
88
+ "tests/**" = [
89
+ "S101",
90
+ "PLR2004",
91
+ "T201",
92
+ "S603",
93
+ ]
94
+
95
+ [tool.ruff.lint.isort]
96
+ known-first-party = ["vicompres"]
97
+
98
+ [tool.ruff.format]
99
+ docstring-code-format = true
@@ -0,0 +1,89 @@
1
+ [project]
2
+ name = "vicompres"
3
+ version = "0.3.0"
4
+ description = "Efficiently compress video files using ffmpeg"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Kirill Pechenkin", email = "pechkirill@mail.ru" },
10
+ ]
11
+ keywords = ["video", "compression", "ffmpeg", "cli"]
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Environment :: Console",
15
+ "Intended Audience :: End Users/Desktop",
16
+ "Operating System :: OS Independent",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Multimedia :: Video :: Conversion",
23
+ ]
24
+ requires-python = ">=3.10"
25
+ dependencies = [
26
+ "click>=8.1",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/kirillismad/vicompres"
31
+ Repository = "https://github.com/kirillismad/vicompres"
32
+ Issues = "https://github.com/kirillismad/vicompres/issues"
33
+
34
+ [project.scripts]
35
+ vicompres = "vicompres.cli:main"
36
+
37
+ [build-system]
38
+ requires = ["uv_build>=0.13.5,<0.14.0"]
39
+ build-backend = "uv_build"
40
+
41
+ [tool.uv.build-backend]
42
+ module-name = "vicompres"
43
+ module-root = ""
44
+
45
+ [tool.ruff]
46
+ # target-version is taken from project.requires-python (>=3.10).
47
+ line-length = 100
48
+
49
+ [tool.ruff.lint]
50
+ select = [
51
+ "E", "W", # pycodestyle
52
+ "F", # pyflakes
53
+ "I", # isort
54
+ "N", # pep8-naming
55
+ "UP", # pyupgrade
56
+ "B", # flake8-bugbear
57
+ "A", # flake8-builtins
58
+ "C4", # flake8-comprehensions
59
+ "PIE", # flake8-pie
60
+ "RET", # flake8-return
61
+ "SIM", # flake8-simplify
62
+ "PTH", # flake8-use-pathlib
63
+ "S", # flake8-bandit
64
+ "T20", # flake8-print: output goes through click.echo
65
+ "EXE", # flake8-executable
66
+ "TRY", # tryceratops
67
+ "PERF", # perflint
68
+ "FURB", # refurb
69
+ "PL", # pylint
70
+ "RUF", # ruff-specific
71
+ ]
72
+ ignore = [
73
+ "S603", # subprocess call: ffmpeg arguments are built from a fixed list
74
+ "S607", # partial executable path: ffmpeg is looked up in PATH on purpose
75
+ "TRY003", # long messages in exception constructors are fine here
76
+ ]
77
+ # Output uses typographic dashes on purpose.
78
+ allowed-confusables = ["–"]
79
+
80
+ [tool.ruff.lint.per-file-ignores]
81
+ # A click command takes one parameter per option.
82
+ "vicompres/cli.py" = ["PLR0913", "PLR0917"]
83
+ "tests/**" = ["S101", "PLR2004", "T201", "S603"]
84
+
85
+ [tool.ruff.lint.isort]
86
+ known-first-party = ["vicompres"]
87
+
88
+ [tool.ruff.format]
89
+ docstring-code-format = true
@@ -0,0 +1,41 @@
1
+ """Vicompres - Efficiently compress video files using ffmpeg."""
2
+
3
+ from vicompres._version import __version__
4
+ from vicompres.compressor import (
5
+ BatchCompressor,
6
+ BatchReport,
7
+ CompressionOptions,
8
+ FileResult,
9
+ Job,
10
+ OutputConflictError,
11
+ Reporter,
12
+ )
13
+ from vicompres.ffmpeg import EncodeError, FFmpeg, FFmpegError, FFmpegNotFoundError
14
+ from vicompres.files import InputSelection, OutputNamer, select_inputs
15
+ from vicompres.marker import Marker
16
+ from vicompres.profiles import PROFILES, Container, Profile
17
+ from vicompres.shutdown import ForcedShutdown, ShutdownController
18
+
19
+ __all__ = [
20
+ "PROFILES",
21
+ "BatchCompressor",
22
+ "BatchReport",
23
+ "CompressionOptions",
24
+ "Container",
25
+ "EncodeError",
26
+ "FFmpeg",
27
+ "FFmpegError",
28
+ "FFmpegNotFoundError",
29
+ "FileResult",
30
+ "ForcedShutdown",
31
+ "InputSelection",
32
+ "Job",
33
+ "Marker",
34
+ "OutputConflictError",
35
+ "OutputNamer",
36
+ "Profile",
37
+ "Reporter",
38
+ "ShutdownController",
39
+ "__version__",
40
+ "select_inputs",
41
+ ]
@@ -0,0 +1,5 @@
1
+ """Allow ``python -m vicompres``."""
2
+
3
+ from vicompres.cli import main
4
+
5
+ main(prog_name="vicompres")
@@ -0,0 +1,8 @@
1
+ """Installed package version."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ try:
6
+ __version__ = version("vicompres")
7
+ except PackageNotFoundError: # running from a source tree that is not installed
8
+ __version__ = "0.0.0"
@@ -0,0 +1,125 @@
1
+ """Command-line interface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import click
8
+
9
+ from vicompres.compressor import BatchCompressor, CompressionOptions, OutputConflictError
10
+ from vicompres.console import ConsoleReporter
11
+ from vicompres.ffmpeg import FFmpegNotFoundError
12
+ from vicompres.files import OutputNamer, select_inputs
13
+ from vicompres.profiles import DEFAULT_LEVEL, MAX_LEVEL, MIN_LEVEL
14
+ from vicompres.shutdown import ForcedShutdown, ShutdownController
15
+
16
+ EXIT_FAILED = 1
17
+ # Status a shell reports for a run stopped by Ctrl+C: 128 + SIGINT.
18
+ EXIT_INTERRUPTED = 130
19
+
20
+
21
+ def _to_namer(_ctx: click.Context, _param: click.Parameter, value: str) -> OutputNamer:
22
+ try:
23
+ return OutputNamer(value)
24
+ except ValueError as exc:
25
+ raise click.BadParameter(str(exc)) from exc
26
+
27
+
28
+ @click.command(context_settings={"help_option_names": ["-h", "--help"]})
29
+ @click.version_option(package_name="vicompres", prog_name="vicompres")
30
+ @click.argument("patterns", nargs=-1, required=True)
31
+ @click.option(
32
+ "-c",
33
+ "--compression",
34
+ type=click.IntRange(MIN_LEVEL, MAX_LEVEL),
35
+ default=DEFAULT_LEVEL,
36
+ show_default=True,
37
+ help="Compression level. Higher = smaller files, lower quality, slower.",
38
+ )
39
+ @click.option(
40
+ "-o",
41
+ "--output",
42
+ "output_dir",
43
+ type=click.Path(file_okay=False, resolve_path=True, path_type=Path),
44
+ default=None,
45
+ help="Output directory for compressed files (default: next to each original).",
46
+ )
47
+ @click.option(
48
+ "-s",
49
+ "--suffix",
50
+ "namer",
51
+ default="compressed",
52
+ show_default=True,
53
+ callback=_to_namer,
54
+ help="Suffix of output file names: clip.mp4 -> clip.<suffix>.mp4.",
55
+ )
56
+ @click.option(
57
+ "-r",
58
+ "--remove-original",
59
+ is_flag=True,
60
+ help="Delete originals after successful compression (kept if the copy is not smaller).",
61
+ )
62
+ @click.option(
63
+ "--overwrite",
64
+ is_flag=True,
65
+ help="Replace compressed copies that already exist (default: skip those files).",
66
+ )
67
+ def main(
68
+ patterns: tuple[str, ...],
69
+ compression: int,
70
+ output_dir: Path | None,
71
+ namer: OutputNamer,
72
+ remove_original: bool,
73
+ overwrite: bool,
74
+ ) -> None:
75
+ """Compress the videos in PATTERNS with ffmpeg.
76
+
77
+ PATTERNS are files, directories (all videos directly inside) or glob
78
+ patterns. Quote a pattern to let vicompres expand it; ** matches nested
79
+ directories:
80
+
81
+ \b
82
+ vicompres clip.mp4 trip/
83
+ vicompres -c 7 'videos/**/*.mov'
84
+
85
+ Every compressed file is tagged, so running vicompres again skips it.
86
+ """
87
+ selection = select_inputs(patterns)
88
+ if selection.missing:
89
+ raise click.BadParameter(
90
+ "No such file or directory: " + ", ".join(selection.missing),
91
+ param_hint="'PATTERNS...'",
92
+ )
93
+
94
+ reporter = ConsoleReporter()
95
+ reporter.input_problems(selection)
96
+ if not selection.files:
97
+ reporter.no_files()
98
+ raise SystemExit(EXIT_FAILED)
99
+
100
+ shutdown = ShutdownController(on_request=reporter.shutdown_requested)
101
+ compressor = BatchCompressor(
102
+ CompressionOptions(
103
+ level=compression,
104
+ output_dir=output_dir,
105
+ namer=namer,
106
+ remove_original=remove_original,
107
+ overwrite=overwrite,
108
+ ),
109
+ reporter=reporter,
110
+ shutdown=shutdown,
111
+ )
112
+
113
+ try:
114
+ shutdown.install()
115
+ report = compressor.run(selection.files)
116
+ except (FFmpegNotFoundError, OutputConflictError) as exc:
117
+ raise click.ClickException(str(exc)) from exc
118
+ except ForcedShutdown as exc:
119
+ reporter.forced_shutdown()
120
+ raise SystemExit(exc.exit_code) from None
121
+
122
+ if report.interrupted:
123
+ raise SystemExit(EXIT_INTERRUPTED)
124
+ if report.failed:
125
+ raise SystemExit(EXIT_FAILED)