scripts

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

mksub (942B)


      1 #!/bin/sh
      2 
      3 # rename subtitle files downloaded from addic7ed.com to match
      4 # the specified tv series filenames in the current directory
      5 
      6 if test -z "$1"; then
      7     echo "usage: $(basename $0) "'"Title.of.Show"' && exit 1
      8 fi
      9 
     10 PP="$1"
     11 TT=$(echo $PP | sed 's|\.|*|g') # inject wildcards
     12 DOWNLOADS=$(test -n "$DOWNLOADS" && echo "$DOWNLOADS" || echo /tmp/web)
     13 
     14 # note: grep '*' means that wildcard did not expand
     15 
     16 echo $PP
     17 for F in ${PP}.S??E??*.{avi,mp4,mkv}; do
     18     if test "$(echo $F | grep '*')"; then
     19         continue
     20     fi
     21     S=$(echo $F | sed "s/.*S\(..\)E...*/\1/")
     22     E=$(echo $F | sed "s/.*S..E\(..\).*/\1/")
     23     echo -n "S${S}E${E}"
     24     for SUB in $DOWNLOADS/${TT}*${S}x${E}*.srt; do
     25         if test "$(echo $SUB | grep '*')"; then
     26             echo
     27             break
     28         else
     29             # do copy the first matching subtitle file
     30             cp "$SUB" ${F%.*}.srt
     31             echo " OK"
     32             break
     33         fi
     34     done
     35 done