commit 2b5d28687cadd6ed1bd9f1a4567593f2228e895a Author: Augusto Gunsch Date: Sun Aug 29 10:48:54 2021 -0300 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..11ab78b --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# fsub +`fsub` is a very simple script (less than 50 lines of code) for cleaning a .srt file + +# Usage +`fsub ` + +# Features +- Fixes subtitle numbering +- Removes lines which have words listed in ~/.config/fsubrc diff --git a/fsub b/fsub new file mode 100755 index 0000000..97f7f7b --- /dev/null +++ b/fsub @@ -0,0 +1,47 @@ +#!/bin/sh +set -e + +FSUBRC=~/.config/fsubrc + +usage() { + echo "usage: fsub " + 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