PDA

View Full Version : VideoTS (ISO) batch to MKV (moving to Plex)



frank90
01-16-2016, 05:26 AM
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#${INPU T_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

MightyGem
01-16-2016, 04:33 PM
Use Handbrake, certainly for the .img files, although I'm not sure if it can cope with .iso files. It has a batch function and will give MKV files at the end.
https://handbrake.fr/downloads.php

frank90
01-16-2016, 07:14 PM
I have handbrake of course, but the batch is not automatic. I am setting up a hands-off batch that moves files from folder to folder and resulting in a final file. Handbrakes batch is not that automatic. I have to manually open Handbrake, add files to batch one-at-a-time and start.

At least thats what I have found out. A hotfolder (auto loads to batch from new items in folder) would be best, but cant see that Handbrake supports this.

That is why I am looking in to scripts, and I am not really that good at this part. Sorry!

frank90
01-16-2016, 07:23 PM
Any clues why following command gives me this error (after successful password prompt):

install: /usr/bin//makemkvcon: Operation not permitted

I am an Admin-user on my account

cd /opt/homebrew-cask/Caskroom/makemkv/1.9.8/MakeMKV.app/contents/macos && sudo /usr/bin/install makemkvcon /usr/bin/ && sudo /usr/bin/install libmakemkv.dylib /usr/bin/ && sudo /usr/bin/install libdriveio.dylib /usr/bin/ && sudo /usr/bin/install libffm.dylib /usr/bin/ && sudo /usr/bin/install libfdk.dylib /usr/bin/

cradom
01-16-2016, 07:49 PM
You're trying to run an .app as a terminal command? Don't think that's going to work.
Also you have two slashes in the path. Is there something supposed to be there? Or typo?
Where are you getting these commands?

chas_m
01-16-2016, 09:36 PM
I don't know enough about Plex to comment (but that's never stopped me before! :)) but I have to ask ... surely it plays lots of media types (kind of the whole point I would have thought)? Why not convert this stuff to something standard rather than the oddball MKV format? Like, hey here's an idea, the MPEG-standard MPEG4/H.264 that will be much more transportable on your next setup ... or when you get an Apple TV ... or a Roku ... or anything ...

frank90
01-17-2016, 03:55 AM
Thanks!

Yes I will convert to Mp4 in next step. I have found an app that takes mkv files and converts them to mp4 by dropping in one folder. (But not any app that takes video_ts folders and batchconverts through hotfolders to mp4). Theese are not pirated discimages, though!

The above script calls an command-line appversion of makemkv. Takes Video_TS folder and creates a MKV.

The script will be triggered by hazel when dropping files in a certain folder.