subtitle-generator 3.0.3__tar.gz → 3.0.4__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.
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/PKG-INFO +12 -3
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/PYPI_README.md +11 -2
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/pyproject.toml +1 -1
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/__init__.py +1 -1
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/cli/commands.py +48 -13
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/subtitle_gen.py +49 -16
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/CONTRIBUTING.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/LICENSE +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/MANIFEST.in +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/README.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/config/default.yaml +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/docs/API.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/docs/PACKAGING.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/docs/TROUBLESHOOTING.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/docs/example.md +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/environment.yml +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/requirements.txt +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/setup.cfg +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/setup.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/cli/__init__.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/config/__init__.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/config/config_loader.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/config/settings.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/__init__.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/async_processor.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/batch_processor.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/transcriber.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/video_processor.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/models/__init__.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/models/model_manager.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/__init__.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/downloader.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/exceptions.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/file_handler.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/formatters.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/paths.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/validators.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/whisper_setup.py +0 -0
- {subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator.egg-info/SOURCES.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: subtitle-generator
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.4
|
|
4
4
|
Summary: AI-powered subtitle generation from video/audio using Whisper.
|
|
5
5
|
Author-email: Ved Gupta <vedgupta@protonmail.com>
|
|
6
6
|
Maintainer-email: Ved Gupta <vedgupta@protonmail.com>
|
|
@@ -125,7 +125,7 @@ native code), so you need to provide it once.
|
|
|
125
125
|
## Quick Start
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
|
-
# Generate subtitles (VTT format)
|
|
128
|
+
# Generate subtitles (VTT format) into the current directory
|
|
129
129
|
subtitle video.mp4
|
|
130
130
|
|
|
131
131
|
# Generate SRT format
|
|
@@ -136,8 +136,14 @@ subtitle video.mp4 --merge
|
|
|
136
136
|
|
|
137
137
|
# Use a larger model for better accuracy
|
|
138
138
|
subtitle video.mp4 --model large
|
|
139
|
+
|
|
140
|
+
# Route output somewhere other than the current directory
|
|
141
|
+
subtitle /path/to/video.mp4 --output-dir ~/subs
|
|
139
142
|
```
|
|
140
143
|
|
|
144
|
+
> Output lands in the directory you ran the command from (or `--output-dir`
|
|
145
|
+
> if you pass it), regardless of where the input video lives.
|
|
146
|
+
|
|
141
147
|
## CLI Commands
|
|
142
148
|
|
|
143
149
|
| Command | Description |
|
|
@@ -153,9 +159,12 @@ subtitle video.mp4 --model large
|
|
|
153
159
|
| Option | Description |
|
|
154
160
|
|--------|-------------|
|
|
155
161
|
| `--model`, `-m` | Model to use: tiny, base, small, medium, large |
|
|
156
|
-
| `--format`, `-f` | Output format: vtt, srt, txt, json, lrc
|
|
162
|
+
| `--format`, `-f` | Output format: vtt, srt, txt, json, lrc |
|
|
157
163
|
| `--merge` | Embed subtitles into the video file |
|
|
164
|
+
| `--output-dir`, `-o` | Where to write the subtitle (default: current dir) |
|
|
158
165
|
| `--threads`, `-t` | Number of processing threads |
|
|
166
|
+
| `--whisper-binary` | Override the auto-discovered whisper-cli path |
|
|
167
|
+
| `--models-dir` | Override the model cache directory |
|
|
159
168
|
| `--verbose`, `-v` | Enable verbose output |
|
|
160
169
|
|
|
161
170
|
## Python API
|
|
@@ -80,7 +80,7 @@ native code), so you need to provide it once.
|
|
|
80
80
|
## Quick Start
|
|
81
81
|
|
|
82
82
|
```bash
|
|
83
|
-
# Generate subtitles (VTT format)
|
|
83
|
+
# Generate subtitles (VTT format) into the current directory
|
|
84
84
|
subtitle video.mp4
|
|
85
85
|
|
|
86
86
|
# Generate SRT format
|
|
@@ -91,8 +91,14 @@ subtitle video.mp4 --merge
|
|
|
91
91
|
|
|
92
92
|
# Use a larger model for better accuracy
|
|
93
93
|
subtitle video.mp4 --model large
|
|
94
|
+
|
|
95
|
+
# Route output somewhere other than the current directory
|
|
96
|
+
subtitle /path/to/video.mp4 --output-dir ~/subs
|
|
94
97
|
```
|
|
95
98
|
|
|
99
|
+
> Output lands in the directory you ran the command from (or `--output-dir`
|
|
100
|
+
> if you pass it), regardless of where the input video lives.
|
|
101
|
+
|
|
96
102
|
## CLI Commands
|
|
97
103
|
|
|
98
104
|
| Command | Description |
|
|
@@ -108,9 +114,12 @@ subtitle video.mp4 --model large
|
|
|
108
114
|
| Option | Description |
|
|
109
115
|
|--------|-------------|
|
|
110
116
|
| `--model`, `-m` | Model to use: tiny, base, small, medium, large |
|
|
111
|
-
| `--format`, `-f` | Output format: vtt, srt, txt, json, lrc
|
|
117
|
+
| `--format`, `-f` | Output format: vtt, srt, txt, json, lrc |
|
|
112
118
|
| `--merge` | Embed subtitles into the video file |
|
|
119
|
+
| `--output-dir`, `-o` | Where to write the subtitle (default: current dir) |
|
|
113
120
|
| `--threads`, `-t` | Number of processing threads |
|
|
121
|
+
| `--whisper-binary` | Override the auto-discovered whisper-cli path |
|
|
122
|
+
| `--models-dir` | Override the model cache directory |
|
|
114
123
|
| `--verbose`, `-v` | Enable verbose output |
|
|
115
124
|
|
|
116
125
|
## Python API
|
|
@@ -7,6 +7,7 @@ with progress callbacks and rich output.
|
|
|
7
7
|
|
|
8
8
|
import argparse
|
|
9
9
|
import logging
|
|
10
|
+
import os
|
|
10
11
|
import sys
|
|
11
12
|
from abc import ABC, abstractmethod
|
|
12
13
|
from typing import Optional
|
|
@@ -188,11 +189,15 @@ class SubtitleCLI:
|
|
|
188
189
|
self.observer.on_error(f"Download failed: {e}")
|
|
189
190
|
return 1
|
|
190
191
|
|
|
191
|
-
# Sanitize filename if needed
|
|
192
|
+
# Sanitize filename if needed. (Note: this still mutates the
|
|
193
|
+
# user's source file path. With argv-based subprocess invocation
|
|
194
|
+
# in 3.0.2+ it is no longer strictly necessary to do this for
|
|
195
|
+
# whisper-cli to accept the path, but we keep it to match the
|
|
196
|
+
# historical behaviour of moving the renamed file forward
|
|
197
|
+
# through validation.)
|
|
192
198
|
if " " in filepath:
|
|
193
199
|
new_path = sanitize_filename(filepath)
|
|
194
200
|
if new_path != filepath:
|
|
195
|
-
import os
|
|
196
201
|
os.rename(filepath, new_path)
|
|
197
202
|
filepath = new_path
|
|
198
203
|
|
|
@@ -230,36 +235,53 @@ class SubtitleCLI:
|
|
|
230
235
|
def progress_callback(stage: str, progress: float):
|
|
231
236
|
self.observer.on_progress(stage, progress)
|
|
232
237
|
|
|
238
|
+
# Where the final subtitle file lands. Default = current working
|
|
239
|
+
# directory; an absolute or relative path may be supplied via
|
|
240
|
+
# ``--output-dir``. We use the input's *basename* so that
|
|
241
|
+
# ``subtitle /Users/me/videos/foo.mp4`` produces ``./foo.srt`` in
|
|
242
|
+
# the user's CWD, never scribbling next to the input video.
|
|
243
|
+
target_dir = os.path.abspath(args.output_dir) if args.output_dir else os.getcwd()
|
|
244
|
+
os.makedirs(target_dir, exist_ok=True)
|
|
245
|
+
input_basename = os.path.splitext(os.path.basename(filepath))[0]
|
|
246
|
+
final_subtitle_path = os.path.join(
|
|
247
|
+
target_dir, f"{input_basename}.{output_format}"
|
|
248
|
+
)
|
|
249
|
+
|
|
233
250
|
subtitle_path, success = generator.generate_and_rename(
|
|
234
251
|
input_path=filepath,
|
|
235
252
|
model_name=model,
|
|
236
253
|
output_format=output_format,
|
|
237
254
|
output_dir=default_output_dir(),
|
|
255
|
+
output_path=final_subtitle_path,
|
|
238
256
|
progress_callback=progress_callback,
|
|
239
257
|
)
|
|
240
|
-
|
|
258
|
+
|
|
241
259
|
if not success:
|
|
242
260
|
self.observer.on_error("Transcription failed")
|
|
243
261
|
return 1
|
|
244
|
-
|
|
245
|
-
# Merge subtitles into video if requested
|
|
262
|
+
|
|
246
263
|
if merge:
|
|
247
264
|
self.observer.on_progress("merging", 0.0)
|
|
248
265
|
processor = VideoProcessor()
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
|
|
267
|
+
# Mirror the subtitle's "land in CWD" behaviour for the
|
|
268
|
+
# merged video too: a user who ran the command from ~/work
|
|
269
|
+
# expects ~/work/video_subtitled.mp4, not the input video's
|
|
270
|
+
# neighbour.
|
|
271
|
+
input_ext = os.path.splitext(filepath)[1] or ".mp4"
|
|
272
|
+
merged_output_path = os.path.join(
|
|
273
|
+
target_dir, f"{input_basename}_subtitled{input_ext}"
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
if processor.merge_subtitles(filepath, subtitle_path, merged_output_path):
|
|
255
277
|
self.observer.on_progress("merging", 1.0)
|
|
256
|
-
self.observer.on_complete(True,
|
|
278
|
+
self.observer.on_complete(True, merged_output_path)
|
|
257
279
|
else:
|
|
258
280
|
self.observer.on_error("Failed to merge subtitles")
|
|
259
281
|
return 1
|
|
260
282
|
else:
|
|
261
283
|
self.observer.on_complete(True, subtitle_path)
|
|
262
|
-
|
|
284
|
+
|
|
263
285
|
return 0
|
|
264
286
|
|
|
265
287
|
def _handle_models_command(self, args: argparse.Namespace) -> int:
|
|
@@ -451,6 +473,19 @@ Examples:
|
|
|
451
473
|
action="store_true",
|
|
452
474
|
help="Verbose output",
|
|
453
475
|
)
|
|
476
|
+
parser.add_argument(
|
|
477
|
+
"--output-dir", "-o",
|
|
478
|
+
type=str,
|
|
479
|
+
default=None,
|
|
480
|
+
metavar="DIR",
|
|
481
|
+
help=(
|
|
482
|
+
"Directory to write the subtitle file (and, with --merge, the "
|
|
483
|
+
"embedded video). Defaults to the current working directory, "
|
|
484
|
+
"which is usually what you want — running `subtitle "
|
|
485
|
+
"/some/elsewhere/video.mp4` no longer scribbles into "
|
|
486
|
+
"/some/elsewhere/."
|
|
487
|
+
),
|
|
488
|
+
)
|
|
454
489
|
parser.add_argument(
|
|
455
490
|
"--whisper-binary",
|
|
456
491
|
type=str,
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/subtitle_gen.py
RENAMED
|
@@ -7,6 +7,7 @@ using the transcriber strategy and handling the overall workflow.
|
|
|
7
7
|
|
|
8
8
|
import logging
|
|
9
9
|
import os
|
|
10
|
+
import shutil
|
|
10
11
|
from typing import Optional, Callable
|
|
11
12
|
|
|
12
13
|
from .transcriber import TranscriberStrategy, TranscriptionResult
|
|
@@ -103,21 +104,33 @@ class SubtitleGenerator:
|
|
|
103
104
|
model_name: str = "base",
|
|
104
105
|
output_format: str = "vtt",
|
|
105
106
|
output_dir: str = "data",
|
|
107
|
+
output_path: Optional[str] = None,
|
|
106
108
|
progress_callback: Optional[Callable[[str, float], None]] = None,
|
|
107
109
|
) -> tuple[str, bool]:
|
|
108
110
|
"""
|
|
109
|
-
Generate subtitles and
|
|
111
|
+
Generate subtitles and move the result to a final location.
|
|
110
112
|
|
|
111
113
|
Args:
|
|
112
|
-
input_path: Path to input audio/video file
|
|
113
|
-
model_name: Name of the model to use
|
|
114
|
-
output_format: Output subtitle format
|
|
115
|
-
output_dir: Directory for the transient transcription output
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
input_path: Path to input audio/video file.
|
|
115
|
+
model_name: Name of the model to use.
|
|
116
|
+
output_format: Output subtitle format.
|
|
117
|
+
output_dir: Directory for the transient transcription output.
|
|
118
|
+
Whisper.cpp writes a UUID-prefixed file here; it is then
|
|
119
|
+
moved to the final target. Use a temp-style dir to keep
|
|
120
|
+
this from polluting the user's CWD.
|
|
121
|
+
output_path: Optional explicit destination (an absolute or
|
|
122
|
+
relative file path including extension). When ``None``
|
|
123
|
+
(the historic default), the result is renamed to sit
|
|
124
|
+
next to ``input_path`` as ``<input>.<output_format>``.
|
|
125
|
+
CLI callers pass an explicit value so the user gets the
|
|
126
|
+
output in the directory they ran the command from,
|
|
127
|
+
regardless of where the input video lives.
|
|
128
|
+
progress_callback: Optional callback for progress updates.
|
|
118
129
|
|
|
119
130
|
Returns:
|
|
120
|
-
Tuple of (
|
|
131
|
+
Tuple of (final_output_path, success). On rename failure the
|
|
132
|
+
transient path is returned with ``success=True`` so callers
|
|
133
|
+
can still surface the file to the user.
|
|
121
134
|
"""
|
|
122
135
|
result = self.generate(
|
|
123
136
|
input_path=input_path,
|
|
@@ -126,21 +139,41 @@ class SubtitleGenerator:
|
|
|
126
139
|
output_dir=output_dir,
|
|
127
140
|
progress_callback=progress_callback,
|
|
128
141
|
)
|
|
129
|
-
|
|
142
|
+
|
|
130
143
|
if not result.success:
|
|
131
144
|
return ("", False)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
|
|
146
|
+
if output_path:
|
|
147
|
+
final_output_path = output_path
|
|
148
|
+
else:
|
|
149
|
+
base, _ = os.path.splitext(input_path)
|
|
150
|
+
final_output_path = f"{base}.{output_format}"
|
|
151
|
+
|
|
137
152
|
try:
|
|
138
153
|
if os.path.exists(result.output_path):
|
|
139
|
-
|
|
154
|
+
# Make sure the destination directory exists before moving;
|
|
155
|
+
# callers may legitimately point at a path under a CWD that
|
|
156
|
+
# only has the file's parent, not the file.
|
|
157
|
+
final_dir = os.path.dirname(final_output_path)
|
|
158
|
+
if final_dir:
|
|
159
|
+
os.makedirs(final_dir, exist_ok=True)
|
|
160
|
+
# If the destination already exists (re-run, --force-style
|
|
161
|
+
# repeat) remove it first, since `shutil.move` on most
|
|
162
|
+
# platforms refuses to overwrite an existing regular file.
|
|
163
|
+
if os.path.isfile(final_output_path):
|
|
164
|
+
os.remove(final_output_path)
|
|
165
|
+
# `shutil.move` falls back to copy-then-delete when the
|
|
166
|
+
# source and destination are on different filesystems
|
|
167
|
+
# (common when /tmp is a tmpfs or a separate Docker
|
|
168
|
+
# volume), unlike `os.rename` which raises EXDEV.
|
|
169
|
+
shutil.move(result.output_path, final_output_path)
|
|
140
170
|
logger.info(f"Renamed output to: {final_output_path}")
|
|
141
171
|
return (final_output_path, True)
|
|
142
172
|
except OSError as e:
|
|
173
|
+
# Cross-device rename or non-writable parent dir. Surface the
|
|
174
|
+
# transient path so the user can still copy it manually
|
|
175
|
+
# rather than losing a successful transcription.
|
|
143
176
|
logger.error(f"Failed to rename output: {e}")
|
|
144
177
|
return (result.output_path, True)
|
|
145
|
-
|
|
178
|
+
|
|
146
179
|
return (result.output_path, True)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/config/config_loader.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/async_processor.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/batch_processor.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/transcriber.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/core/video_processor.py
RENAMED
|
File without changes
|
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/models/model_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/downloader.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/exceptions.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/file_handler.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/formatters.py
RENAMED
|
File without changes
|
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/validators.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator/utils/whisper_setup.py
RENAMED
|
File without changes
|
{subtitle_generator-3.0.3 → subtitle_generator-3.0.4}/subtitle_generator.egg-info/SOURCES.txt
RENAMED
|
File without changes
|