-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsubtitle-shift
executable file
·96 lines (82 loc) · 2.98 KB
/
subtitle-shift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#
# progname - short desciption
#
# Copyright (C) 2013 Rodrigo Silva (MestreLion) <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. See <http://www.gnu.org/licenses/gpl.html>
#
# Long description
# ... that may span over multiple lines
myname="${0##*/}"
mydir=$(dirname "$(readlink -f "$0")")
verbose=0
shift="+00:00:00.700"
fatal() { [[ "$1" ]] && echo "$myname: error: $1" >&2 ; exit ${2:-1} ; }
message() { ((verbose)) && printf "%s\n" "$1"; }
integer() { [[ "$1" != *[!0-9]* ]] || argerr "'$1'${2:+ in $2} is not an integer." ; }
skip() { i=${2:-$file}; message "skipping${i:+ $i}${1:+: $1}"; continue ; }
argerr() { printf "%s: %s\n" "$myname" "${1:-error}" >&2 ; usage 1 ; }
invalid() { argerr "invalid option: $1" ; }
missing() { argerr "missing ${2:+$2 }argument${1:+ from $1}." ; }
quit() { message "Goodbye!" ; exit; }
relpath() { python -c "import os, sys; print os.path.relpath(*sys.argv[1:3])" "$@"; }
usage() {
cat <<-USAGE
Usage: $myname [options] FILE
USAGE
if [[ "$1" ]] ; then
cat >&2 <<- USAGE
Try '$myname --help' for more information.
USAGE
exit 1
fi
cat <<-USAGE
Short description
Options:
-h|--help - show this page.
-v|--verbose - print more details about what is being done.
--shift TIME - how much TIME to shift, in HH:MM:SS.xxx format (Default: $shift)
--text TEXT - start shift from the line containing TEXT.
If blank, start shift from the first line
Copyright (C) 2013 Rodrigo Silva (MestreLion) <[email protected]>
License: GPLv3 or later. See <http://www.gnu.org/licenses/gpl.html>
USAGE
exit 0
}
# Option handling
files=()
for arg in "$@"; do [[ "$arg" == "-h" || "$arg" == "--help" ]] && usage ; done
while (( $# )); do
case "$1" in
-v|--verbose ) verbose=1 ;;
--text=* ) text="${1#*=}" ;;
--text ) shift ; text="$1" ;;
--shift=* ) shift="${1#*=}" ;;
--shift ) shift ; shift="$1" ;;
-- ) shift ; break ;;
-* ) invalid "$1" ;;
* ) [[ "$file" ]] && invalid "$1";
file="$1" ;;
esac
shift
done
[[ "$shift" ]] || missing "--shift" "NUM"
[[ "$file" ]] || missing "FILE"
echo "var=$text"
echo "var=$shift"
echo "var=$file"
tempfile=$(mktemp) || fatal
trap 'rm -f -- "$tempfile"' EXIT
cp "$file" "$temp" || fatal