Last active
August 29, 2015 14:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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