mackal

ripep.sh

Sep 11th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.11 KB | None | 0 0
  1. #! /usr/bin/env bash
  2.  
  3. #    This program is free software: you can redistribute it and/or modify
  4. #    it under the terms of the GNU General Public License as published by
  5. #    the Free Software Foundation, either version 3 of the License, or
  6. #    (at your option) any later version.
  7. #
  8. #    This program is distributed in the hope that it will be useful,
  9. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #    GNU General Public License for more details.
  12. #
  13. #    You should have received a copy of the GNU General Public License
  14. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. #    Script by Michael Cook
  17. #    Version: 1.2
  18. #    Email: [email protected]
  19. #    Website: mackal.net
  20.  
  21. #    This script makes ripping TV episodes easier from a DVD
  22. #    while keeping them named nicely
  23. #    Format: TV.Show.Name.S##E##.mkv
  24.  
  25. #    Requirements: lsdvd, HandBrake (0.9.4+svn3278-1 from getdeb
  26. #                                    for Ubuntu 10.04)
  27.  
  28. # Start configurations
  29.  
  30. dvdDevice="/dev/sr0" # Where your DVD Device is
  31. videoDirectory="/home/mike/Videos/TV Shows/" # Where stuff is saved
  32. # Various options for HandBrake
  33. #x264Opts="ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0"
  34. picOpts="--crop --strict-anamorphic --vfr -9 -5 -q 19"
  35. audioOpts="-E ac3"
  36.  
  37. # Good settings
  38. x264Opts="ref=6:b-adapt=2:bframes=6:direct=auto:me=umh:subq=9:analyse=all:trellis=2:no-fast-pskip=1:merange=24:deblock=-2,-2:rc-lookahead=50:aq-strength=1.2"
  39.  
  40. # Good Settings simCGI
  41. #x264Opts="ref=9:b-adapt=2:bframes=7:direct=auto:me=umh:subq=9:analyse=all:trellis=2:no-fast-pskip=1:psy-rd=0.7,0:merange=24:rc-lookahead=50"
  42.  
  43. # Faster SD rips
  44. #x264Opts="ref=5:mixed-refs=1:b-adapt=2:bframes=5:weightb=1:direct=auto:me=umh:subq=8:8x8dct=1:trellis=1:psy-rd=1,0:deblock=-2,-2:rc-lookahead=40:aq-strength=1.2:b-pyramid=1"
  45.  
  46. # End configuration
  47.  
  48. # Function to fetch how many audio tracks there are
  49. function findAudio {
  50.    audio=`grep -n "audio tracks" temp.txt | grep ".*: " -o | sed 's/: //'`
  51.    sub=`grep -n "subtitle tracks" temp.txt | grep ".*: " -o | sed 's/: //'`
  52.    audioStreams=$((sub-audio-1))
  53. }
  54.  
  55. # Function to generate our -a string
  56. function audioString {
  57.    unset audioTracks
  58.    for ((x=1; x<$1+1; x++)); do
  59.       audioTracks="${audioTracks}${x}"
  60.       if (( ${x}!=$1 )); then
  61.          audioTracks="${audioTracks},"
  62.       fi
  63.    done
  64. }
  65.  
  66. # Function to fetch how many subtitle tracks there are
  67. function findSub {
  68.    sub=`grep -n "subtitle tracks" temp.txt | grep ".*: " -o | sed 's/: //'`
  69.    end=`grep -n "HandBrake has exited." temp.txt | grep ".*:" -o | sed 's/://'`
  70.    subtitles=$((end-sub-1))
  71. }
  72.  
  73. # Function to generate our -s string
  74. function subString {
  75.    unset subTracks
  76.    for ((x=1; x<$1+1; x++)); do
  77.       subTracks="${subTracks}${x}"
  78.       if (( ${x}!=$1 )); then
  79.          subTracks="${subTracks},"
  80.       fi
  81.    done
  82. }
  83.  
  84. # Fetching some information about the DVD
  85. # so we can have them named correctly
  86. echo -n "Please enter the title of the show: "
  87. read title
  88.  
  89. echo -n "Please enter the season number: "
  90. read season
  91.  
  92. echo -n "Please enter the number of the first episode on this disc: "
  93. read firstEpisode
  94. echo
  95.  
  96. # Read the titles on the DVD and prompt
  97. # the user to input the titles they want
  98. lsdvd
  99.  
  100. declare -a titles
  101. echo "Seperated by spaces"
  102. echo -n "Please enter the titles you want to rip: "
  103. read -a titles
  104.  
  105. # Set up some stuff for our envirnment
  106. maxTitles=${#titles[@]}
  107. cd "${videoDirectory}"
  108. mkdir -p "${title}"
  109. cd "${title}"
  110.  
  111. # Loop to encode all our crap
  112.  
  113. for ((i=0; i<$maxTitles; i++)); do
  114.    episode=$((firstEpisode+i))
  115.    HandBrakeCLI --scan -t ${titles[${i}]} -i ${dvdDevice} 2> temp.txt
  116.  
  117.    findAudio "${titles[${i}]}"
  118.    audioString "${audioStreams}"
  119.    findSub "${titles[${i}]}"
  120.    subString "${subtitles}"
  121.  
  122.    options="${picOpts} ${audioOpts} -e x264 -x ${x264Opts} -a ${audioTracks} -s ${subTracks} -t ${titles[${i}]} -i ${dvdDevice} -o ${title}.S`printf "%02d" ${season}`E`printf "%02d" ${episode}`.mkv"
  123.    HandBrakeCLI ${options}
  124.  
  125.    # Clean up
  126.    rm temp.txt
  127. done
Advertisement
Add Comment
Please, Sign In to add comment