Last active
March 20, 2016 21:20
-
-
Save munkyjunky/41aaff1a964afe9434ef to your computer and use it in GitHub Desktop.
DVD Rip Script
This file contains hidden or 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 | |
##### VARIABLES ##### | |
# LOCATIONS | |
SOURCE_DRIVE=/dev/sr0 | |
OUTPUT_DIR=/tmp/ripdvd | |
MOVIES_DIR=/media/sdc/movies | |
TELEVISION_DIR=/media/sdd/television | |
# TV SHOWS | |
SERIES_NAME="" | |
SERIES_NUMBER=0 | |
EPISODE_COUNT=0 | |
START_FROM=0 | |
# HANDBRAKE | |
HANDBRAKE_PRESET="Normal" | |
EXTENSION="MP4" | |
##### MERGE OPTIONS ##### | |
# CHECK THERES A DVD | |
#################### | |
# Grab the DVD title | |
DVD_TITLE=$(blkid -o value -s LABEL $SOURCE_DRIVE) | |
# Replace spaces with underscores | |
DVD_TITLE=${DVD_TITLE// /_} | |
if [ -z "$DVD_TITLE" ] | |
then | |
notify "ERROR" "No DVD found in drive $SOURCE_DRIVE." | |
exit | |
fi | |
# CALCULATE EPISODES | |
#################### | |
TITLE_COUNT=$(lsdvd $SOURCE_DRIVE | grep ^'Title: ' | wc -l) | |
EPISODE_COUNT=0 | |
for (( i=1; i<=$TITLE_COUNT; i++ )) | |
do | |
# Grab the title string | |
TITLE_STRING=$(lsdvd $SOURCE_DRIVE -t $i ) | |
REGEX="Length: ([0-9]+):([0-9]+)" | |
# find the length | |
if [[ $TITLE_STRING =~ $REGEX ]] | |
then | |
HOURS="${BASH_REMATCH[1]}" | |
MINUTES="${BASH_REMATCH[2]}" | |
# if it's between 15 & 59 minutes, its an episode | |
if [ $MINUTES -gt 15 ] && [ $MINUTES -lt 59 ] | |
then | |
EPISODE_COUNT=$(($EPISODE_COUNT+1)) | |
fi | |
fi | |
done | |
if [ $EPISODE_COUNT -gt 1 ] | |
then | |
notify "DVD Rip" "Detected TV show, quitting." | |
exit | |
fi | |
# BACK UP DVD | |
############# | |
notify "DVD Rip" "Started ripping $DVD_TITLE" | |
# Backup the DVD to the hard drive | |
dvdbackup -i $SOURCE_DRIVE -o $OUTPUT_DIR -M -n $DVD_TITLE | |
# Pop out the disc | |
eject $SOURCE_DRIVE | |
notify "DVD Rip" "Finished ripping $DVD_TITLE to $OUTPUT_DIR." | |
# RIP USING HANDBRAKE | |
##################### | |
# 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 1; done | |
fi | |
# if there's only 1 episode count, assume movie | |
if [$EPISODE_COUNT -lt 2 ] | |
HandBrakeCLI -i $OUTPUT_DIR/$DVD_TITLE -o $OUTPUT_DIR/$DVD_TITLE.$EXTENSION --preset=$HANDBRAKE_PRESET --main-feature | |
if [ ! -f "$OUTPUT_DIR/$DVD_TITLE.$EXTENSION" ] | |
then | |
notify "ERROR" "HandBrake failed to encode $DVD_TITLE." | |
exit | |
fi | |
# Move into final destination | |
mv $OUTPUT_DIR/$DVD_TITLE.$EXTENSION $MOVIES_DIR | |
else | |
let ERROR_COUNT=0 | |
# iterate over each title | |
for (( c=1; c <= $EPISODE_COUNT; c++ )) do | |
EPISODE=$((START_FROM-1 + c)) | |
# make sure all episodes have double digit IDs | |
PREFIX="" | |
if [ $EPISODE -lt 10 ]; then PREFIX="0" ; fi | |
# rip | |
HandBrakeCLI -i $OUTPUT_DIR/$DVD_TITLE -o "$OUTPUT_DIR/$SERIES_NAME/SEASON $SERIES_NUMBER/EPISODE $PREFIX$EPISODE.$EXTENSION" --preset=$HANDBRAKE_PRESET -t $c | |
# make sure it ripped correctly | |
if [ ! -f "$OUTPUT_DIR/$SERIES_NAME/SEASON $SERIES_NUMBER/EPISODE $PREFIX$EPISODE.$EXTENSION" ] | |
then | |
ERROR_COUNT++ | |
notify "ERROR" "HandBrake failed to encode $DVD_TITLE Episode $PREFIX$EPISODE." | |
fi | |
done | |
# Make sure at least some files ripped | |
if [ $ERROR_COUNT -lt $EPISODE_COUNT] | |
#move files | |
#mv -r $OUTPUT_DIR/$SERIES_NAME $TELEVISON_DIR | |
fi | |
fi | |
notify "DVD Rip" "Finished encoding $DVD_TITLE." |
This file contains hidden or 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 | |
FINAL_DESTINATION="/media/sdc/movies" | |
OUTPUT_DIR="/tmp/ripdvd" | |
SOURCE_DRIVE="/dev/sr0" | |
HANDBRAKE_PRESET="Normal" | |
EXTENSION="mp4" | |
function rip_dvd() { | |
# Grab the DVD title | |
DVD_TITLE=$(blkid -o value -s LABEL $SOURCE_DRIVE) | |
# Replace spaces with underscores | |
DVD_TITLE=${DVD_TITLE// /_} | |
if [ -z "$DVD_TITLE" ] | |
then | |
notify "ERROR" "No DVD found in drive $SOURCE_DRIVE." | |
exit | |
fi | |
notify "DVD Rip" "Started ripping $DVD_TITLE" | |
# Backup the DVD to out hard drive | |
dvdbackup -i $SOURCE_DRIVE -o $OUTPUT_DIR -M -n $DVD_TITLE | |
# 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 1; done | |
fi | |
eject $SOURCE_DRIVE | |
notify "DVD Rip" "Finished ripping $DVD_TITLE to $OUTPUT_DIR." | |
# And now we can start encoding | |
HandBrakeCLI -i $OUTPUT_DIR/$DVD_TITLE -o $OUTPUT_DIR/$DVD_TITLE.$EXTENSION --preset=$HANDBRAKE_PRESET --main-feature | |
if [ ! -f "$OUTPUT_DIR/$DVD_TITLE.$EXTENSION" ] | |
then | |
notify "ERROR" "HandBrake failed to encode $DVD_TITLE. Assumed copy protected." | |
exit | |
fi | |
# Move into final destination | |
mv $OUTPUT_DIR/$DVD_TITLE.$EXTENSION $FINAL_DESTINATION | |
notify "DVD Rip" "Finished encoding $DVD_TITLE." | |
} | |
rip_dvd |
This file contains hidden or 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 | |
function rip_series() { | |
NAME=$1 | |
SERIES=$2 | |
COUNT=$3 | |
START=$4 | |
HANDBRAKE_PRESET="Normal" | |
SOURCE_DRIVE=/dev/sr0 | |
OUTPUT_DIR=/tmp/ripseries | |
FINAL_DESTINATION=/media/sdd/television | |
EXTENSION="MP4" | |
# Grab the DVD title | |
DVD_TITLE=$(blkid -o value -s LABEL $SOURCE_DRIVE) | |
# Replace spaces with underscores | |
DVD_TITLE=${DVD_TITLE// /_} | |
if [ -z "$DVD_TITLE" ] | |
then | |
notify "ERROR" "No DVD found in drive $SOURCE_DRIVE." | |
exit | |
fi | |
notify "DVD Rip" "Started ripping $DVD_TITLE" | |
# Backup the DVD to out hard drive | |
dvdbackup -i $SOURCE_DRIVE -o $OUTPUT_DIR -M -n $DVD_TITLE | |
# grep for the HandBrakeCLI process and get the PID | |
HANDBRAKE_PID=`ps aux|grep H\[a\]ndBrakeCLI` | |
set -- $HANDBRAKE_PID | |
HANDBRAKE_PID=$2 | |
# HandBrake isn't ripping anything so we can pop out the disc | |
eject $SOURCE_DRIVE | |
# Wait until our previous Handbrake job is done | |
if [ -n "$HANDBRAKE_PID" ] | |
then | |
while [ -e /proc/$HANDBRAKE_PID ]; do sleep 1; done | |
fi | |
# # HandBrake isn't ripping anything so we can pop out the disc | |
# eject $SOURCE_DRIVE | |
notify "DVD Rip" "Finished ripping $DVD_TITLE to $OUTPUT_DIR." | |
# iterate over each title | |
for (( c=1; c <= $COUNT; c++ )) do | |
PREFIX="" | |
EPISODE=$((START-1 + c)) | |
if [ $EPISODE -lt 10 ]; then PREFIX="0" ; fi | |
# And now we can start encoding | |
HandBrakeCLI -i $OUTPUT_DIR/$DVD_TITLE -o "$OUTPUT_DIR/$NAME/$SERIES/EPISODE $PREFIX$EPISODE.$EXTENSION" --preset=$HANDBRAKE_PRESET -t $c | |
done | |
# if [ ! -f "$OUTPUT_DIR/$DVD_TITLE.$EXTENSION" ] | |
# then | |
# notify "ERROR" "HandBrake failed to encode $DVD_TITLE. Assumed copy protected." | |
# exit | |
# fi | |
# Move into final destination | |
# mv $OUTPUT_DIR/$DVD_TITLE.$EXTENSION $FINAL_DESTINATION | |
notify "DVD Rip" "Finished encoding $DVD_TITLE." | |
} | |
rip_series "$1" "$2" "$3" "$4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment