Initial commit

This commit is contained in:
Augusto Gunsch 2021-08-29 10:48:54 -03:00
commit 2b5d28687c
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 56 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# fsub
`fsub` is a very simple script (less than 50 lines of code) for cleaning a .srt file
# Usage
`fsub <file>`
# Features
- Fixes subtitle numbering
- Removes lines which have words listed in ~/.config/fsubrc

47
fsub Executable file
View File

@ -0,0 +1,47 @@
#!/bin/sh
set -e
FSUBRC=~/.config/fsubrc
usage() {
echo "usage: fsub <file>"
echo "fsub expects $FSUBRC to have a blacklist of words"
exit 1
}
[ -z $1 ] && usage
[ -f $1 ] || usage
[ -z $2 ] || usage
[ -f $FSUBRC ] || touch $FSUBRC
awk '
BEGIN {
n = 1
i = 0
while(getline < "'$FSUBRC'") {
blacklist[i] = $0
i++
}
}
/^[[:digit:]]+[[:space:]]*$/ {
getline
time = $0
linen = 0
while(getline) {
lines[linen] = $0
linen++
if($0 ~ /^[[:space:]]*$/) break
}
for(j = 0; j < i; j++)
for(k = 0; k < linen; k++)
if(lines[k] ~ blacklist[j]) next
print n
n++
print time
for(j = 0; j < linen; j++)
print lines[j]
}' $1 > /tmp/fsub
mv /tmp/fsub $1