Compare commits

..

No commits in common. 'master' and 'automove' have entirely different histories.

  1. 1
      .gitignore
  2. 6
      CHANGELOG.md
  3. 74
      Cargo.lock
  4. 10
      Cargo.toml
  5. 21
      LICENSE
  6. 60
      README.md
  7. 5
      src/main.rs
  8. 27
      test/sample.srt

1
.gitignore vendored

@ -1,3 +1,4 @@
/target
**/*.rs.bk
.idea/
*.srt

@ -1,6 +0,0 @@
# Changelog
# 0.3.1
- fixed some argument handling (negative offset, broken -M)
- update library versions (except clap, which made too many breaking changes and the interface actually got worse)

74
Cargo.lock generated

@ -121,6 +121,11 @@ dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.3.0"
@ -144,6 +149,15 @@ name = "memchr"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nom"
version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "numtoa"
version = "0.1.0"
@ -208,16 +222,61 @@ name = "rustc-demangle"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ryu"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "smart-default"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "srtune"
version = "0.3.0"
version = "0.2.0"
dependencies = [
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"smart-default 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -306,6 +365,11 @@ name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.7"
@ -357,10 +421,12 @@ dependencies = [
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
@ -370,6 +436,11 @@ dependencies = [
"checksum regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0b2f0808e7d7e4fb1cb07feb6ff2f4bc827938f24f8c2e6a3beb7370af544bdd"
"checksum regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d76410686f9e3a17f06128962e0ecc5755870bb890c34820c7af7f1db2e1d48"
"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f"
"checksum serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be"
"checksum serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e"
"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum smart-default 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9dbd5f03d04e80355cbbe3ce5cf1f65c421eac575402e3d4d6e95d5a44edaa"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum syn 0.15.36 (registry+https://github.com/rust-lang/crates.io-index)" = "8b4f551a91e2e3848aeef8751d0d4eec9489b6474c720fd4c55958d8d31a430c"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
@ -382,6 +453,7 @@ dependencies = [
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"

@ -1,13 +1,19 @@
[package]
name = "srtune"
version = "0.3.0"
version = "0.2.0"
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
edition = "2018"
[dependencies]
clap = "2.33.0"
log = "0.4"
env_logger = "0.6.1"
failure = "0.1.5"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
smart-default = "0.5"
lazy_static = "1.3.0"
nom = "4.2.3"
regex = "1.1.7"
env_logger = "0.6.1"

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2019 Ondřej Hruška <ondra@ondrovo.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@ -1,60 +0,0 @@
# srtune 0.3.0
'srtune' helps you edit a .srt file to match a video. Input and output can be either a file, or a stream, so you can
pipe multiple invocations to create more complex operations. However, a single invocation should suffice in most cases.
An example invocation, used to adapt a full-length subtitle track to a shorter version of "Whisper of the Heart", looks
like this:
```bash
srtune source.srt -o whisper.srt -M235=15:06.7 -M309=24:15 -M412=32:12 \
-M411=32:01 -M762=58:51 -M895=1:08:33 -M1125=1:26:28 -M01:44:22=01:41:37.3
```
Times are specified with colons (required) and always include seconds (HH:MM:SS, MM:SS, 0:SS, :SS). Decimal point in the
seconds part, if needed, can be either a period or a comma; times can be copied from the .srt file. Numbers without
colons are assumed to be subtitle indices.
The tool can be used iteratively, adjusting the invocation until the generated subtitle file matches the audio track.
You can reload the file in VLC by dragging it onto the player window. To make this work, subtitle times specified in
arguments are the ones seen in the output file (after shifts and moving), while entry indices are those from the input
file.
Using indices makes it easier to specify a subtitle to alter, but it is tied to the one .srt file. Times are harder to
write, but the one configuration will work for any locatization or variant of the file,so long as it is intended for the
same version of the movie. Enable debug logging with '-v' to see times you can use in place of indices.
Indices are normally not renumbered, so the output file can be used as a reference for both times and indices when you
work out the right set of arguments. The flag '--renumber' will give each output entry a new sequential number. Please
note that, once renumbered, the indices in the output file should no longer be used in the command invocation, as there
can be (and often will be) differences from the original file.
```none
USAGE:
srtune [FLAGS] [OPTIONS] [--] [INFILE]
FLAGS:
-h, --help Prints help information
-r, --renumber Renumber all emitted entries with sequential 1-based numbers.
-v Increase the logging verbosity; can be used multiple times
-V, --version Prints version information
OPTIONS:
-M, --automove <ENTRY=VIDEOTIME>... Move subtitles starting at a given time or index to align with a matching
audio track time. This argument can be given multiple times. Some subtitles
may be dropped if they fall outside the timeline after the move.
-S, --autoscale <SUBTIME=VIDEOTIME> Calculate scaling based on a perceived difference. The scaling is related to
the first emitted subtitle; align it with '--move'. This overrides '--scale'.
-d, --durscale <RATIO> Scale durations, can be combined with '--scale' or '--autoscale'. The given
value will always be multiplied by the absolute time scale. 1 means identity,
1.1 makes all times 10% longer.
-m, --move <OFFSET> Move all subtitles in time (e.g 12:00.15 or -0:44)
-o, --output <OUTFILE> Output file, defaults to stdout
-s, --scale <RATIO> Scale all subtitle times and durations to compensate for bitrate differences.
1 means identity, 1.1 makes all times 10% longer. Scaling is relative to the
first emitted subtitle; align it with '--move'. This option has no effect if
'--autoscale' is used.
ARGS:
<INFILE> Input file, leave out for stdin
```

@ -11,7 +11,8 @@ use std::str::FromStr;
use std::convert::TryFrom;
use std::io::BufRead;
use std::ops::{Add, Mul, MulAssign, AddAssign, SubAssign, Sub};
use std::fmt::{self, Display, Debug};
use std::fmt::{self, Display};
use serde::export::fmt::Debug;
use core::fmt::Write as fmtWrite;
const LOG_LEVELS: [&str; 5] = ["error", "warn", "info", "debug", "trace"];
@ -68,7 +69,6 @@ fn main() {
.short("m")
.long("move")
.value_name("OFFSET")
.allow_hyphen_values(true)
.help("Move all subtitles in time (e.g 12:00.15 or -0:44)"),
)
.arg(clap::Arg::with_name("automove")
@ -76,7 +76,6 @@ fn main() {
.long("automove")
.value_name("ENTRY=VIDEOTIME")
.multiple(true)
.number_of_values(1)
.help("Move subtitles starting at a given time or index to align with \
a matching audio track time. This argument can be given multiple times. \
Some subtitles may be dropped if they fall outside the timeline after \

@ -1,27 +0,0 @@
20
00:00:12,838 --> 00:00:20,762
♪♪~ Country Roads take me home
21
00:00:20,762 --> 00:00:28,770
♪♪~ To the place  belong
22
00:00:28,770 --> 00:00:32,758
♪♪~ West Virginia
23
00:00:32,758 --> 00:00:36,812
♪♪~ mountain momma
24
00:00:36,812 --> 00:00:40,766
♪♪~ Take me home
25
00:00:40,766 --> 00:00:46,772
♪♪~ Country Roads
26
00:00:46,772 --> 00:00:49,775
♪♪~
Loading…
Cancel
Save