#! /bin/bash ### Quick Notes # This is intended to rip a DVD and place the ripped Title files in # ~/dvdrip-output/ in a folder named after the name on the disc and then # in a timestamped inner directory like: # ~/dvdrip-output/ORPHAN_BLACK_S4_D1/102120241340/ # # To avoid duplicates and the "one big file with all the episodes in it" issue # I take 30 second samples of each Title and create a checksum that is compared # to all subsequent files. Over the course of several hundred DVDs this has caused # maybe one ripping issue which can be fixed by specifying the single Title to rip # with the -t command line flag. # i=0 timestamp=$(date +%m%d%Y%H%M) pid=$(ps -A | grep dvd-rip-tvshows | awk '{print $1}') # caffeinate -w $pid # Used to keep my Mac awake when I used a mac while getopts ":s:t:e:" options do case "${options}" in s) stitle="${OPTARG}" ;; t) stitle="${OPTARG}"; etitle="${OPTARG}" ;; e) etitle="${OPTARG}" ;; ?) printf "Usage %s: [ -s: Staring Title ] [ -t Rip this single title ] \n" $0 exit 2;; esac done if [ -z $stitle ] then stitle="1" fi if [ -z $etitle ] then etitle="100" fi echo Start: $stitle echo End: $etitle ### Set the device ID # I kind of prefer hard coding this as it allows me to do the "disk is spinning up" bit # so I can just jam a disk in there, hit Go and let the application wait until the # disk is ready. #### For MacOS #### # id=$(drutil status |grep -m1 -o '/dev/disk[0-9]*') id="/dev/sr0" ### Check for media. Again I prefer hardcoding the device ID # if [ -z "$id" ]; then # echo "No Media Inserted" # fi #### Test the DVD is mounted and ready to rip 9-13-2022 ### while [ -z "$name" ] do ### Cleaning this up using lsdvd instead 10-21-2024 # name=$(blkid | grep sr0 | grep LABEL= | sed "s/'//g" | sed 's/ /_/g' | awk -F "LABEL=\"" '{print $2}' | awk -F "\"" '{print $1}') name=$(lsdvd $id | grep "Disc Title" | awk -F ": " '{print $2}') echo "Drive Spinning Up" sleep 0.5 done ###I haven't tested the above on MacOS, you can always do: # name=$(df | grep "$id" |grep -o /Volumes.* | awk -F "Volumes\/" '{print $2}' | sed 's/ /_/g') ### Create the Output Directory echo $name dir="$name/$timestamp" mkdir -p ~/dvdrip-output/$dir echo $dir ### Finding max title via mencoder broke and is ugly anyway - using lsdvd instead - 10-21-2024 # maxtitle=$(mencoder dvd://100 -o bob | grep "titles on this DVD" | awk '{print $3}') maxtitle=$(lsdvd $id | grep Title | tail -n 1 | awk '{print $2}' | awk -F "," '{print $1}') for (( title=$stitle; title<=$etitle; title++ )) do echo "title = $title" echo "maxtitle = $maxtitle" if [ $title -le $maxtitle ] then echo "*******************************" echo "CURRENTLY SAMPLING TITLE #$title" echo "*******************************" mencoder -dvd-device $id dvd://$title -alang en -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate="1200" -vf scale -zoom -xy 720 -oac mp3lame -lameopts br=128 -endpos 30 -o ~/dvdrip-output/$dir/$title-sample.avi >/dev/null 2>&1 shasum ~/dvdrip-output/$dir/$title-sample.avi > ~/dvdrip-output/$dir/$title-checksum touch ~/dvdrip-output/$dir/rippedchecksums.txt fi done cat ~/dvdrip-output/$dir/*checksum >> ~/dvdrip-output/$dir/allchecksums.txt for (( title=$stitle; title<=$etitle; title++ )) do if [ $title -gt $maxtitle ] then chmod -R 775 ~/dvdrip-output/$dir sleep 3 # drutil tray eject eject exit 0 fi sum=$(cat ~/dvdrip-output/$dir/$title-checksum | awk '{print $1}') match=$(grep $sum ~/dvdrip-output/$dir/rippedchecksums.txt) if [ -z $match ] then echo "*******************************" echo "CURRENTLY RIPPING TITLE #$title" echo "*******************************" ### I used to use mencoder which gave kind of shittily deinterlaced video. When Handbrake started ripping DVDs again I used that instead and they look great ### # # mencoder dvd://$title -alang en -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate="1200" -vf pp=lb scale -zoom -xy 720 -oac mp3lame -lameopts br=128 -o ~/dvdrip-output/$dir/$title.avi ### This makes a very good looking de-interlaced file, but the file is broken and nothing plays it right except elmedia. # mencoder dvd://$title -alang en -vf pp=lb,scale -zoom -xy 720 -ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate="1200" -oac mp3lame -lameopts br=128 -o ~/dvdrip-output/$dir/$title.avi >/dev/null ### ### Handbrake has problems with hardware encoding with the Radeon. This worked great with NVidia but for 1000 other reasons I'm not willing to use NVidia. Now I need to try with CPU encoding. I don't care as long as it looks good # # attempt at using the AMD preset - this works fine in the GUI, but we're not in the gui. #time HandBrakeCLI -v 0 -Z "H.265 VCN 1080p" -i /dev/dvd --deinterlace=Default -t $title -o ~/dvdrip-output/$dir/$title.mp4 # # Pure software, no preset, just let her rip and see what happens: # What happens is 250-300FPS encodes, which is totally fine. time HandBrakeCLI -v 0 -i $id --deinterlace=Default -t $title -o ~/dvdrip-output/$dir/$title.mp4 echo $sum >> ~/dvdrip-output/$dir/rippedchecksums.txt rm ~/dvdrip-output/$dir/$title-checksum rm ~/dvdrip-output/$dir/$title-sample.avi fi done chmod -R 775 ~/dvdrip-output/$dir # (( i++ ))