subgapfix 0.0.1__py3-none-any.whl
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.
subgapfix/__init__.py
ADDED
|
File without changes
|
subgapfix/subgapfix.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import srt
|
|
3
|
+
from datetime import timedelta
|
|
4
|
+
|
|
5
|
+
def extend_subs(input_file, output_file, extend_sub_start=0.5, extend_sub_end=2.0, min_gap=1.0):
|
|
6
|
+
|
|
7
|
+
if min_gap > extend_sub_start:
|
|
8
|
+
|
|
9
|
+
with open(input_file, "r", encoding="utf-8") as f:
|
|
10
|
+
subs = list(srt.parse(f.read()))
|
|
11
|
+
|
|
12
|
+
for i in range(len(subs) - 1):
|
|
13
|
+
first, second = subs[i], subs[i + 1]
|
|
14
|
+
gap = (second.start - first.end).total_seconds()
|
|
15
|
+
|
|
16
|
+
if gap < min_gap:
|
|
17
|
+
first.end += timedelta(seconds=gap/2)
|
|
18
|
+
second.start -= timedelta(seconds=gap/2)
|
|
19
|
+
|
|
20
|
+
if gap >= min_gap:
|
|
21
|
+
extendable = gap - extend_sub_start
|
|
22
|
+
if extendable > 0:
|
|
23
|
+
extension = min(extendable, extend_sub_end)
|
|
24
|
+
first.end += timedelta(seconds=extension)
|
|
25
|
+
second.start -= timedelta(seconds=extend_sub_start)
|
|
26
|
+
|
|
27
|
+
# Make sure subs don't overlap each other
|
|
28
|
+
if second.start <= first.end:
|
|
29
|
+
second.start = first.end + timedelta(milliseconds=10)
|
|
30
|
+
|
|
31
|
+
with open(output_file, "w", encoding="utf-8") as f:
|
|
32
|
+
f.write(srt.compose(subs))
|
|
33
|
+
|
|
34
|
+
else:
|
|
35
|
+
print("Hold up! The value of min_gap should be greater than that of extended_sub_start.")
|
|
36
|
+
|
|
37
|
+
def main():
|
|
38
|
+
parser = argparse.ArgumentParser(
|
|
39
|
+
description="Extend subtitle durations when there is a gap before the next subtitle."
|
|
40
|
+
)
|
|
41
|
+
parser.add_argument("input", help="Input SRT file")
|
|
42
|
+
parser.add_argument("-o", "--output", default="subgapfix.srt", help="Output SRT file")
|
|
43
|
+
parser.add_argument("--extend-sub-start", "-ess", type=float, default=0.5, help="Seconds to add to start of subtitle. Default is: -ess 0.5")
|
|
44
|
+
parser.add_argument("--extend-sub-end", "-ese", type=float, default=2.0, help="Seconds to add to end of subtitle. Default is: -ese 2.0")
|
|
45
|
+
parser.add_argument("--min-gap", "-mg", type=float, default=1.0, help="Minimum gap (in seconds) required to apply extension. Default is: -mg 1.0")
|
|
46
|
+
args = parser.parse_args()
|
|
47
|
+
|
|
48
|
+
extend_subs(args.input, args.output, args.extend_sub_start, args.extend_sub_end, args.min_gap)
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: subgapfix
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A small CLI tool to extend subtitle durations in SRT files by redefining gaps between subtitles.
|
|
5
|
+
Author-email: Reinder Sinnema <reinder@w3bunker.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: srt>=3.5.3
|
|
10
|
+
|
|
11
|
+
# SubGapFix
|
|
12
|
+
|
|
13
|
+
A small Python CLI tool to **extend subtitle durations** in `.srt` files so they stay on screen longer and feel more natural to read.
|
|
14
|
+
Designed especially for subtitles generated by [WhisperX](https://github.com/m-bain/whisperX), which often have very tight timings.
|
|
15
|
+
|
|
16
|
+
## ✨ Features
|
|
17
|
+
|
|
18
|
+
- Automatically extends subtitles when there’s a gap before the next subtitle.
|
|
19
|
+
- Prevents overlaps by adjusting start/end times safely.
|
|
20
|
+
- Configurable via CLI arguments.
|
|
21
|
+
|
|
22
|
+
## 📦 Installation
|
|
23
|
+
|
|
24
|
+
Clone the repository and install dependencies:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/yourusername/subgapfix.git
|
|
28
|
+
cd subgapfix
|
|
29
|
+
pip install -r requirements.txt
|
|
30
|
+
````
|
|
31
|
+
|
|
32
|
+
Dependencies:
|
|
33
|
+
|
|
34
|
+
* [`srt`](https://pypi.org/project/srt/)
|
|
35
|
+
|
|
36
|
+
## 🔧 Usage
|
|
37
|
+
|
|
38
|
+
Basic usage:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python subgapfix.py input.srt -o easyreading.srt
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Options
|
|
45
|
+
|
|
46
|
+
| Option | Default | Description |
|
|
47
|
+
|----------------------------|-----------------|---------------------------------------------------------------------------|
|
|
48
|
+
| `-o, --output` | `subgapfix.srt` | Output SRT file |
|
|
49
|
+
| `--extend-sub-start, -ess` | `0.5` | Seconds to add to start of subtitle. Default is `0.5` |
|
|
50
|
+
| `--extend-sub-end, -ese` | `2.0` | Maximum seconds to add to end of subtitle. Default is `2.0` |
|
|
51
|
+
| `--min-gap, -mg` | `1.0` | Minimum gap (in seconds) required to apply extension. Default is `1.0` |
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### How It Works
|
|
55
|
+
|
|
56
|
+
The script reads your `.srt` file, loops through each pair of consecutive subtitles, and adjusts their timings to make them easier to read.
|
|
57
|
+
|
|
58
|
+
### Example
|
|
59
|
+
|
|
60
|
+
Input:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
1
|
|
64
|
+
00:00:01,000 --> 00:00:03,000
|
|
65
|
+
Hello there.
|
|
66
|
+
|
|
67
|
+
2
|
|
68
|
+
00:00:06,000 --> 00:00:08,000
|
|
69
|
+
How are you?
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Run:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python subgapfix.py input.srt -o fixed.srt
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Output:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
1
|
|
82
|
+
00:00:01,000 --> 00:00:05,000
|
|
83
|
+
Hello there.
|
|
84
|
+
|
|
85
|
+
2
|
|
86
|
+
00:00:05,500 --> 00:00:08,000
|
|
87
|
+
How are you?
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 💡 Why?
|
|
91
|
+
|
|
92
|
+
Tools like WhisperX produce accurate subtitles, but their timings are often too **tight** for comfortable reading.
|
|
93
|
+
`SubGapFix` helps subtitles stay visible longer while keeping synchronization intact.
|
|
94
|
+
|
|
95
|
+
## 🛠 Roadmap
|
|
96
|
+
|
|
97
|
+
* Package for PyPI (`pip install subgapfix`)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
subgapfix/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
subgapfix/subgapfix.py,sha256=tDDn4cqL-jw9KfPK4tkVaxBLVh_ZZ53xWCwi6PWTbDo,2254
|
|
3
|
+
subgapfix-0.0.1.dist-info/METADATA,sha256=Tqyy5R3_mDF0CXqRAXsfkpp_x_t5uxk6BT1EqRruLRc,2620
|
|
4
|
+
subgapfix-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
subgapfix-0.0.1.dist-info/entry_points.txt,sha256=2ln9RkMCsMtg0kFARJgoY7JKxBR4cEzxj4s-bKGCVUw,55
|
|
6
|
+
subgapfix-0.0.1.dist-info/top_level.txt,sha256=1Kmf1LI51trmbRihayDZRnKSCfEQDR7jSyBELfkwTa8,10
|
|
7
|
+
subgapfix-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
subgapfix
|