Add support for multiple files at the sime time

This commit is contained in:
Augusto Gunsch 2021-10-27 20:02:04 -03:00
parent 0086fa7fb9
commit 7feb65e8f9
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 43 additions and 31 deletions

View File

@ -1,5 +1,5 @@
# fsub # fsub
`fsub` is a very simple script (less than 50 lines of code) for cleaning a .srt file `fsub` is a very simple script (less than 60 lines of code) for cleaning a .srt file
# Usage # Usage
`fsub <file>` `fsub <file>`

72
fsub
View File

@ -4,44 +4,56 @@ set -e
FSUBRC=~/.config/fsubrc FSUBRC=~/.config/fsubrc
usage() { usage() {
echo "usage: fsub <file>" echo "usage: fsub <files>"
echo "fsub expects $FSUBRC to have a blacklist of words" echo "fsub expects $FSUBRC to have a blacklist of words"
exit 1 exit 1
} }
[ -z "$1" ] && usage [ -z "$1" ] && usage
[ -f "$1" ] || usage
[ -z "$2" ] || usage for arg in "$@"; do
if [ ! -f "$arg" ]; then
echo "$arg is not a file"
usage
fi
if [ "${arg: -4}" != ".srt" ]; then
echo "$arg is not a .srt file"
usage
fi
done
[ -f "$FSUBRC" ] || touch $FSUBRC [ -f "$FSUBRC" ] || touch $FSUBRC
awk ' for arg in "$@"; do
BEGIN { awk '
n = 1 BEGIN {
i = 0 n = 1
while(getline < "'$FSUBRC'") { i = 0
blacklist[i] = $0 while(getline < "'$FSUBRC'") {
i++ blacklist[i] = $0
i++
}
} }
} /^[[:digit:]]+[[:space:]]*$/ {
/^[[:digit:]]+[[:space:]]*$/ { getline
getline time = $0
time = $0
linen = 0 linen = 0
while(getline) { while(getline) {
lines[linen] = $0 lines[linen] = $0
linen++ linen++
if($0 ~ /^[[:space:]]*$/) break if($0 ~ /^[[:space:]]*$/) break
} }
for(j = 0; j < i; j++) for(j = 0; j < i; j++)
for(k = 0; k < linen; k++) for(k = 0; k < linen; k++)
if(lines[k] ~ blacklist[j]) next if(lines[k] ~ blacklist[j]) next
print n print n
n++ n++
print time print time
for(j = 0; j < linen; j++) for(j = 0; j < linen; j++)
print lines[j] print lines[j]
}' "$1" | sed 's/\r//' > /tmp/fsub }' "$arg" | sed 's/\r//' > /tmp/fsub
mv /tmp/fsub "$1" mv /tmp/fsub "$arg"
done