scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

commit 8f86f60d025bff832dc0605c64dd19fe1d8e574d
parent 6c782693658ae47541d8635b4b80489b452244c4
Author: lostd <lostd@2f30.org>
Date:   Sat Aug 24 15:57:49 +0300

style, fault tollerance, readability

Diffstat:
mksub | 40++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/mksub b/mksub @@ -4,24 +4,32 @@ # the specified tv series filenames in the current directory if test -z "$1"; then - echo "usage: $(basename $0) "'"Title.of.Show"' - exit + echo "usage: $(basename $0) "'"Title.of.Show"' && exit 1 fi -pp="$1" -tt=$(echo $pp | sed 's/\./ /g') -ddir=$(test -n "$DOWNLOADS" && echo "$DOWNLOADS" || echo /tmp/web) +PP="$1" +TT=$(echo $PP | sed 's|\.|*|g') # inject wildcards +DOWNLOADS=$(test -n "$DOWNLOADS" && echo "$DOWNLOADS" || echo /tmp/web) -echo $pp -for f in ${pp}.S??E??*.{avi,mp4,mkv}; do - if test "$(echo $f | grep '*')"; then continue; fi - s=$(echo $f | sed "s/.*S\(..\)E...*/\1/") - e=$(echo $f | sed "s/.*S..E\(..\).*/\1/") - x=$(echo $f | sed "s/.*\.//") - b=$(echo $ddir/"${tt}"*${s}x${e}*.srt) - echo -n "S${s}E${e}" - if test "$(echo $b | grep '*')"; then echo; continue; else - cp "$b" $(basename $f .$x).srt - echo " OK" +# note: grep '*' means that wildcard did not expand + +echo $PP +for F in ${PP}.S??E??*.{avi,mp4,mkv}; do + if test "$(echo $F | grep '*')"; then + continue fi + S=$(echo $F | sed "s/.*S\(..\)E...*/\1/") + E=$(echo $F | sed "s/.*S..E\(..\).*/\1/") + echo -n "S${S}E${E}" + for SUB in $DOWNLOADS/${TT}*${S}x${E}*.srt; do + if test "$(echo $SUB | grep '*')"; then + echo + break + else + # do copy the first matching subtitle file + cp "$SUB" ${F%.*}.srt + echo " OK" + break + fi + done done