diff --git a/local/bin/dlsubs b/local/bin/dlsubs new file mode 100755 index 0000000..2b7a91c --- /dev/null +++ b/local/bin/dlsubs @@ -0,0 +1,25 @@ +#!/bin/sh + +LANG=pob + +usage() { + echo "usage: dlsubs " + exit 1 +} + +[ -z "$1" ] && usage + +for arg in "$@"; do + case "$arg" in + *.mkv|*.mp4 ) + if [ ! -f "$arg" ]; then + echo "$arg is not a file" + usage + fi ;; + *) echo "$arg is neither a .mkv nor a .mp4 file"; usage ;; + esac +done + +for input in "$@"; do + subdl --lang=$LANG "$input" +done diff --git a/local/bin/fsub b/local/bin/fsub index 4a56445..c347849 100755 --- a/local/bin/fsub +++ b/local/bin/fsub @@ -4,46 +4,56 @@ set -e FSUBRC=~/.config/fsubrc usage() { - echo "usage: fsub " + 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 +[ -z "$1" ] && usage -cp $1 $1.bak -awk ' -BEGIN { - n = 1 - i = 0 - while(getline < "'$FSUBRC'") { - blacklist[i] = $0 - i++ +for arg in "$@"; do + case "$arg" in + *.srt ) + if [ ! -f "$arg" ]; then + echo "$arg is not a file" + usage + fi ;; + *) echo "$arg is not a .srt file"; usage ;; + esac +done + +[ -f "$FSUBRC" ] || touch $FSUBRC + +for arg in "$@"; do + awk ' + BEGIN { + n = 1 + i = 0 + while(getline < "'$FSUBRC'") { + blacklist[i] = $0 + i++ + } } -} -/^[[:digit:]]+[[:space:]]*$/ { - getline - time = $0 + /^[[:digit:]]+[[:space:]]*$/ { + getline + time = $0 - linen = 0 - while(getline) { - lines[linen] = $0 - linen++ - if($0 ~ /^[[:space:]]*$/) break - } + 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 + 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 | sed 's/\r//' > /tmp/fsub -mv /tmp/fsub $1 -rm $1.bak + print n + n++ + print time + for(j = 0; j < linen; j++) + print lines[j] + }' "$arg" | sed 's/\r//' > /tmp/fsub + mv /tmp/fsub "$arg" +done diff --git a/local/bin/tomp4 b/local/bin/tomp4 new file mode 100755 index 0000000..fcb5513 --- /dev/null +++ b/local/bin/tomp4 @@ -0,0 +1,39 @@ +#!/bin/sh +set -e + +usage() { + echo "usage: tomp4 " + exit 1 +} + +[ -z "$1" ] && usage + +for arg in "$@"; do + case "$arg" in + *.mkv ) + if [ ! -f "$arg" ]; then + echo "$arg is not a file" + usage + fi ;; + *) echo "$arg is not a .mkv file"; usage ;; + esac +done + +for input in "$@"; do + base=${input%.mkv} + output="$base.mp4" + tmp="$base.tmp.mp4" + + if [ ! -f "$output" ]; then + ffmpeg -i "$input" "$tmp" + + if [ $? -ne 0 ]; then + rm "$tmp" + exit 1 + fi + + mv "$tmp" "$output" + else + "Skipping $input" + fi +done