Skip to content

Instantly share code, notes, and snippets.

@samirfor
Last active August 29, 2015 14:25
Show Gist options
  • Save samirfor/3e9fe8aa2a2feb89f8e7 to your computer and use it in GitHub Desktop.
Save samirfor/3e9fe8aa2a2feb89f8e7 to your computer and use it in GitHub Desktop.
This script uses the mkvsrtadd to process a batch of mkv files at once.
#!/bin/bash
# This script needs "mkvsrtadd" script
# (available on https://gist.github.com/samirfor/6dd0d0e8e2344ba3d093)
# to work properly. Make sure you have it in the same path of this script.
self=$(basename "$0")
selfdir=$(dirname "$0")
PWD=$(pwd -P) # resolving symbolic links
usage="[i] Usage: $self \"pattern\" \nBe sure pattern is into double quotes."
# Checking parameter
if [ -z "${1+x}" ]; then
echo ""; echo "$usage"; echo ""; exit 1
fi
SAMEFOLDEROUTPUT=0
if [[ ! -z "${2+x}" && "$2" =~ [Ss] ]]; then
echo "Same folder output files [put all output files in current folder]<ON>"
SAMEFOLDEROUTPUT=1
fi
# Displaying the files match by pattern
# ignoring files already processed (*.br.mkv)
echo
echo "INFO: The following files will be processed ..."
echo
find . -type f -name "$1" ! -name "*.br.mkv" -print
echo
read -p "Are you sure? [Y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "INFO: Aborted."
exit 1
fi
# Do it by a pattern
find . -type f -name "$1" ! -name "*.br.mkv" -print0 | while IFS= read -d $'\0' file; do
echo
echo "INFO: Processing '$file' ..."
if [ $SAMEFOLDEROUTPUT == 1 ]; then
bash "$selfdir/mkvsrtadd" "$file"
else
DIR=$(dirname "$file")
FILE=$(basename "$file")
cd "$DIR"
bash "$selfdir/mkvsrtadd" "$FILE"
cd - 1> /dev/null
fi
done
cd "$PWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment