Shell Scripts

The place to discuss linux version of MakeMKV
Post Reply
cpare
Posts: 8
Joined: Mon Aug 01, 2016 12:53 am

Shell Scripts

Post by cpare »

Can we get a sticky post to share shell scripts? It could be a big help for those getting started, and might even get improved by the rest of the community.

Mine below -> This started from the copy found here https://pathar.tl/blog/the-ultimate-aut ... g-machine/

Code: Select all

#!/bin/bash

OUTPUT_DIR="/movies"
SOURCE_DRIVE="/dev/sr0"
HANDBRAKE_PRESET="High Profile"
EXTENSION="mkv"

function rip_bluray() {

        # Cleanup any mkv files before getting started
        #rm $OUTPUT_DIR/*.mkv

        # Grab the DVD title
        echo `date`   Starting to look for disc label
        BLURAY_TITLE=`blkid -o value -s LABEL $SOURCE_DRIVE`
        echo `date`   Title:  $BLURAY_TITLE
        # Replace spaces with underscores
        BLURAY_TITLE=${BLURAY_TITLE// /_}
        echo `date`   Corrected Title:  $BLURAY_TITLE

        # rip files linger than 3600 seconds to the disk
        echo "makemkvcon --minlength=3600 -r --decrypt --directio=true mkv disc:1 all $OUTPUT_DIR"
        makemkvcon --minlength=3600 --decrypt --directio=true mkv disc:1 all $OUTPUT_DIR

        #Rename the title files to the disk name
        rename "s/title/$BLURAY_TITLE/"  $OUTPUT_DIR/*.mkv

        #grep for the HandBrakeCLI process and get the PID
        HANDBRAKE_PID=`ps aux|grep H\[a\]ndBrakeCLI`
        set -- $HANDBRAKE_PID
        HANDBRAKE_PID=$2

        # Wait until our previous Handbrake job is done
        if [ -n "$HANDBRAKE_PID" ]
        then
                while [ -e /proc/$HANDBRAKE_PID ]; do sleep 10; done
        fi

        # HandBrake isn't ripping anything so we can pop out the disc
        eject $SOURCE_DRIVE

        # And now we can start encoding the mkv files we created
        for FILE in `ls $OUTPUT_DIR/*.mkv`
        do
                filename=$(basename $FILE)
                extension=${filename##*.}
                filename=${filename%.*}
                HandBrakeCLI -i $OUTPUT_DIR/$filename.mkv -o $OUTPUT_DIR/$filename.mp4 --preset="High Profile"
                rm $OUTPUT_DIR/$filename.mkv
        done

        #Clean up
        #rm -R $OUTPUT_DIR/$BLURAY_TITLE
}

echo `date`     "Starting RipBlueRay"
rip_bluray
Post Reply