Skip to content

Commit 3d7ef9f

Browse files
authored
Merge pull request #5 from Nigh/add-regexp
Add regular expression support for time range setup
2 parents 7ad0eac + 1f106b6 commit 3d7ef9f

6 files changed

Lines changed: 326 additions & 178 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
VERSION?=v1.1.0
2+
VERSION?=v1.2.0
33

44
DIR = dist
55
EXECUTABLE = ass-shifter

Makefile_windows

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
VERSION?=v1.1.0
2+
VERSION?=v1.2.0
33

44
DIR = dist
55
EXECUTABLE = ass-shifter

README.md

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Shift Subtitle of [`.ass`, `.srt`] format
33

44
> [!CAUTION]
5-
> It will replace your subtitle, **backup** your subtitle files before run.
5+
> It will replace your subtitle, **backup** your subtitle files before run. Use `--dry` for test.
6+
> From version `v1.2.0`, the program will automatically convert subtitle files to UTF8 encoding.
67
78

89
## Usage
@@ -12,34 +13,70 @@ ass-shifter [path] -t [shift ms]
1213
Positional Variables:
1314
path the subtitle path to shift (Required)
1415
Flags:
15-
--version Displays the program version string.
16-
-h --help Displays help with available flag, subcommand, and positional value parameters.
17-
-t --shift shift ms (default: 0)
18-
-s --start start from HH:MM:SS
19-
-e --end end at HH:MM:SS
16+
--version Displays the program version string.
17+
-h --help Displays help with available flag, subcommand, and positional value parameters.
18+
-t --shift shift ms (default: 0)
19+
-s --start start from HH:MM:SS
20+
-e --end end at HH:MM:SS
21+
-sr --startRegexp start from regular expression
22+
-er --endRegexp end at regular expression
23+
-d --dry dry run
2024
```
2125

26+
The `--start` and `--end` parameters can be used to qualify the time range of the subtitle offset.
27+
The `--startRegexp` and `--endRegexp` parameters can be used to match the content of the subtitle with a regular expression as the start and end of the offset time range.
28+
The time and regular expression parameters can be used together.
29+
2230
## Example
2331
The `start` and `end` parameters are optional. They can also be used together.
2432
```bash
25-
ass-shifter ../Better.Call.Saul/S03 -t -3200
26-
ass-shifter ../Better.Call.Saul/S03 -t -3200 -s 0:06:13
33+
ass-shifter ../Better.Call.Saul/S03 -t 3200
34+
ass-shifter ../Better.Call.Saul/S03 -t 3200 -s 0:06:13
2735
ass-shifter ../Better.Call.Saul/S03 -t -3200 -s 0:06:13 -e 0:24:12
36+
ass-shifter ../Better.Call.Saul/S06 -sr "第.季\s*第.+集" -t 3200
37+
ass-shifter ../Better.Call.Saul/S06 -sr "第.季\s*第.+集" -e 0:24:12 -t 3200
2838
```
2939

3040
The program prints the result of the execution like the following.
3141
```bash
32-
ass-shifter ../Better.Call.Saul/S03 -t -3200 -s 0:06:13
33-
34-
[SUCCESS] Better.Call.Saul.S03E01.2017.1080p.BluRay.x265.10bit.ass
35-
[SUCCESS] Better.Call.Saul.S03E02.2017.1080p.BluRay.x265.10bit.ass
36-
[SUCCESS] Better.Call.Saul.S03E03.2017.1080p.BluRay.x265.10bit.ass
37-
[SUCCESS] Better.Call.Saul.S03E04.2017.1080p.BluRay.x265.10bit.ass
38-
[SUCCESS] Better.Call.Saul.S03E05.2017.1080p.BluRay.x265.10bit.ass
39-
[SUCCESS] Better.Call.Saul.S03E06.2017.1080p.BluRay.x265.10bit.ass
40-
[SUCCESS] Better.Call.Saul.S03E07.2017.1080p.BluRay.x265.10bit.ass
41-
[SUCCESS] Better.Call.Saul.S03E08.2017.1080p.BluRay.x265.10bit.ass
42-
[SUCCESS] Better.Call.Saul.S03E09.2017.1080p.BluRay.x265.10bit.ass
43-
[SUCCESS] Better.Call.Saul.S03E10.2017.1080p.BluRay.x265.10bit.ass
44-
Total 10 files shifted -3200ms from 0:06:13 to end
42+
ass-shifter ../Better.Call.Saul/S06 -t -3200 -s 0:06:13
43+
Better.Call.Saul.S06E01.2022.1080p.WEB-DL.x265.10bit.ass
44+
From 0:06:13.00 to end, 1152 lines shifted 3200ms
45+
46+
Better.Call.Saul.S06E02.2022.1080p.WEB-DL.x265.10bit.ass
47+
From 0:06:13.00 to end, 1222 lines shifted 3200ms
48+
49+
...
50+
51+
Better.Call.Saul.S06E12.2022.1080p.WEB-DL.x265.10bit.ass
52+
From 0:06:13.00 to end, 1035 lines shifted 3200ms
53+
54+
Better.Call.Saul.S06E13.2022.1080p.WEB-DL.x265.10bit.ass
55+
From 0:06:13.00 to end, 1629 lines shifted 3200ms
56+
57+
[Info] 13 subtitle files updated.
58+
```
59+
60+
Dry run would NOT change your file. Good for test.
61+
```bash
62+
ass-shifter ../Better.Call.Saul/S06 -sr "第.季\s*第.+集" -t 3234 --dry
63+
64+
Better.Call.Saul.S06E01.2022.1080p.WEB-DL.x265.10bit.ass
65+
From 0:05:32.87 to end, 1155 lines shifted 3234ms
66+
67+
Better.Call.Saul.S06E02.2022.1080p.WEB-DL.x265.10bit.ass
68+
From 0:07:20.77 to end, 1221 lines shifted 3234ms
69+
70+
...
71+
72+
Better.Call.Saul.S06E11.2022.1080p.WEB-DL.x265.10bit.ass
73+
From 0:01:39.00 to end, 1387 lines shifted 3234ms
74+
75+
Better.Call.Saul.S06E12.2022.1080p.WEB-DL.x265.10bit.ass
76+
From 0:02:50.43 to end, 1145 lines shifted 3234ms
77+
78+
Better.Call.Saul.S06E13.2022.1080p.WEB-DL.x265.10bit.ass
79+
From 0:05:17.70 to end, 1651 lines shifted 3234ms
80+
81+
[Info] Dry run, no file changes.
4582
```

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module github.com/Nigh/subtitle-ass-shifter
22

33
go 1.22.1
44

5-
require github.com/integrii/flaggy v1.5.2
5+
require (
6+
github.com/integrii/flaggy v1.5.2
7+
golang.org/x/net v0.33.0
8+
golang.org/x/text v0.21.0
9+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
22
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
33
github.com/integrii/flaggy v1.5.2 h1:bWV20MQEngo4hWhno3i5Z9ISPxLPKj9NOGNwTWb/8IQ=
44
github.com/integrii/flaggy v1.5.2/go.mod h1:dO13u7SYuhk910nayCJ+s1DeAAGC1THCMj1uSFmwtQ8=
5+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
6+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
7+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
8+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
59
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

0 commit comments

Comments
 (0)