Batch convert ISO to MKV (with Hazel for use with Plex)

The place to discuss Mac OS X version of MakeMKV
Post Reply
Frank90
Posts: 1
Joined: Sat Jan 16, 2016 9:31 am

Batch convert ISO to MKV (with Hazel for use with Plex)

Post by Frank90 »

I have a fully automated download process and using hazel to move movies to Plex.
Having spent 20+ hours to try and find a solution to the last step I am almost giving up.
What I have is lots of IMG and ISO files that are unrared. Theese I unpack with TheUnarchiver to get VIDEO_TS folders.
BUT – how do I automate the process of making MKV:s of theese? I simply want a batch processor/script for MKV but cant find any that seems to work.

Found the script below, but cant understand how to use it with hazel – and cant find a way to install MKV to make it command-line available (the commands on the page result in an error).

https://github.com/hcr/convertingMkvScript

ANY help most appriciated.

(I want all subtitles, all languages etc and preserve filename from folder so that Plex can identify the movie)

I am aware of that this might not be an applescript, but guess anyone here knows how to get this to work anyway :-)

!/bin/sh

INPUT_DIR="/Users/AF/Desktop/hotfolder_videodrive"
OUTPUT_DIR="/Users/AF/Desktop/videodrive_klara"
MIN_LENGTH_IN_SECONDS=120
TEMPORARY FOLDERS

TEMP_FOLDER_PATH=""
LOGS_FOLDER_PATH=""
RESULT FOLDERS

SUCCES_FOLDER_PATH=""
FAILED_FOLDER_PATH=""
SCRIPT VARIABLES

NEW_FILE_PATH_WITH_EXT=""
echoStars() {
echo "***********************************************************"
}
echoStripes() {
echo "-----------------------------------------------------------"
}
move() {
local destination=$(dirname "${2}")
mkdir -pv "${destination}"
mv -n$3 -- "${1}" "${2}"
}
createLoggingFolder() {
local name="logs"
local counter=1
local suffix=""
local keep_going=true
while $keep_going; do
if [ -e "${OUTPUT_DIR}/${name}${suffix}" ]; then
suffix="_${counter}"
counter=$((counter + 1))
else
keep_going=false
fi
done
LOGS_FOLDER_PATH="${OUTPUT_DIR}/${name}${suffix}"
mkdir "${LOGS_FOLDER_PATH}"
}
createSuccessFolder() {
SUCCES_FOLDER_PATH="${LOGS_FOLDER_PATH}/success"
mkdir "${SUCCES_FOLDER_PATH}"
}
createFailedFolder() {
FAILED_FOLDER_PATH="${LOGS_FOLDER_PATH}/failure"
mkdir "${FAILED_FOLDER_PATH}"
}
createTempFolder() {
local name="temp"
local counter=1
local keep_going=true
while $keep_going; do
if [ -e "${OUTPUT_DIR}/${name}${counter}" ]; then
counter=$((counter + 1))
else
keep_going=false
fi
done
TEMP_FOLDER_PATH="${OUTPUT_DIR}/${name}${counter}/"
mkdir "${TEMP_FOLDER_PATH}"
}
deleteTempFolder() {
if [ "$(ls -A $TEMP_FOLDER_PATH)" ]; then
echo "Temporary folder ${TEMP_FOLDER_PATH} is not empty, so not removing it"
else
rmdir "${TEMP_FOLDER_PATH}"
fi
}
echoFoldersToProcess() {
echoStars
echo "Input directory : " $INPUT_DIR
echo "Output directory : " $OUTPUT_DIR
echo "Minimum length in seconds : " $MIN_LENGTH_IN_SECONDS
echo "Directories to be processed :"
find "${INPUT_DIR}" -type d -iname "VIDEO_TS" | while read path_to_be_processed;
do
echo " ${path_to_be_processed}"
done
echoStars
}
tryToMakeMkv() {
eval "makemkvcon -r --minlength=$MIN_LENGTH_IN_SECONDS mkv file:\"${1}\" all \"${TEMP_FOLDER_PATH}\" > \"${LOGS_FOLDER_PATH}/makeMkv.log\""
}
checkIfMkvWasCreated() {
if [ "$(ls -A $TEMP_FOLDER_PATH)" ]; then
echo "Success"
move "${LOGS_FOLDER_PATH}/makeMkv.log" "${SUCCES_FOLDER_PATH}${1}.log"
else
echo "Failure"
move "${LOGS_FOLDER_PATH}/makeMkv.log" "${FAILED_FOLDER_PATH}${1}.log"
fi
}
determineNewFileName() {
local new_file_path="${OUTPUT_DIR}${1}"
local counter=1
local suffix=""
local extension=".mkv"

local keep_going=true
while $keep_going; do
if [ -e "${new_file_path}${suffix}${extension}" ]; then
suffix="_${counter}"
counter=$((counter + 1))
else
keep_going=false
fi
done

NEW_FILE_PATH_WITH_EXT="${new_file_path}${suffix}${extension}"
}
renameMkvs() {
if [ "$(ls -A $TEMP_FOLDER_PATH)" ]; then
for file in "${TEMP_FOLDER_PATH}"*
do
determineNewFileName "${1}"
move "${file}" "${NEW_FILE_PATH_WITH_EXT}" v
done
fi
}
echoFinished() {
echoStars
local resultfile="${LOGS_FOLDER_PATH}/result.log"
echoStars >> "${resultfile}"

if [ "$(ls -A $SUCCES_FOLDER_PATH)" ]; then
echo "Successfully converted:" >> "${resultfile}"
find "${SUCCES_FOLDER_PATH}" -type f -iname "*.log" | while read log;
do
local logfile="${log%.log}"
echo "${logfile#${SUCCES_FOLDER_PATH}/}" >> "${resultfile}"
done
echoStars >> "${resultfile}"
fi

if [ "$(ls -A $FAILED_FOLDER_PATH)" ]; then
echo "Failure to convert:" >> "${resultfile}"
find "${FAILED_FOLDER_PATH}" -type f -iname "*.log" | while read log;
do
local logfile="${log%.log}"
echo "${logfile#${FAILED_FOLDER_PATH}/}" >> "${resultfile}"
done
echoStars >> "${resultfile}"
fi

echo "Finished script"
echo "Check ${LOGS_FOLDER_PATH}/result.log for the result"
}
process() {
echoFoldersToProcess
createLoggingFolder
createSuccessFolder
createFailedFolder

echoStars

find "${INPUT_DIR}" -type d -iname "VIDEO_TS" | while read path_to_be_processed;
do
echo "Processing directory: ${path_to_be_processed}"

local without_input_folder=${path_to_be_processed#${INPUT_DIR}}
local media_name=${without_input_folder%/[V,v][I,i][D,d][E,e][O,o]_[T,t][S,s]}

createTempFolder

tryToMakeMkv "${path_to_be_processed}"

checkIfMkvWasCreated "${media_name}"

renameMkvs "${media_name}"

deleteTempFolder

echoStripes
done

echoFinished
}
if [ $# -eq 0 ]; then
echo "Please supply on of these arguments: info, process"
elif [ "$1" = "info" ]; then
echoFoldersToProcess
elif [ "$1" = "process" ]; then
process
else
echo "Invalid argument [${1}]. Please supply on of these arguments: info, process"
fi
Post Reply