daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
  4. SELF=$SCRIPTPATH/$(basename $0)
  5. LOG=/var/log/ripit.log
  6.  
  7. function usage() {
  8.     cat <<EOF
  9. ripit, semi-automated dvd ripping
  10. usage: $0 master </path/to/storage>
  11.        $0 event <device> <path/to/storage>
  12.        $0 slave <device> <path/to/storage>
  13. EOF
  14. }
  15.  
  16. if [[ $# < 2 ]] ; then
  17.     usage
  18.     exit 1
  19. fi
  20.  
  21. if [[ $1 == "master" ]] ; then
  22.     # mode: master
  23.  
  24.     STORAGE=$2
  25.     RULES=/etc/udev/rules.d/99-ripit.rules
  26.  
  27.     # add udev rule which calls slave on disk insertion
  28.     cat > $RULES <<EOF
  29. ACTION=="change", KERNEL=="sr[0-9]*", ENV{ID_CDROM_DVD}=="1", ENV{ID_CDROM_MEDIA_STATE}=="complete", RUN+="$SELF event \$kernel '$STORAGE'"
  30. EOF
  31.     udevadm control --reload-rules
  32.  
  33.     echo "udev rule installed, waiting for disk insertion"
  34.  
  35.     # tail slave log
  36.     touch $LOG
  37.     tail -n 0 -f $LOG
  38.  
  39.     echo "removing udev rule"
  40.     rm -rf $RULES
  41.     udevadm control --reload-rules
  42.  
  43. elif [[ $1 == "event" ]] ; then
  44.     # mode: event
  45.  
  46.     exec >> $LOG
  47.     exec 2>&1
  48.    
  49.     echo "$@"
  50.     # re-invoke self detached to avoid blocking udevd
  51.     echo "$SELF" slave "${@:2}" | batch
  52.  
  53. elif [[ $1 == "slave" ]] ; then
  54.  
  55.     # mode: slave
  56.  
  57.     exec >> $LOG
  58.     exec 2>&1
  59.    
  60.     dev=/dev/$2
  61.  
  62.     echo "insertion event: $dev"
  63.  
  64.     # grab volume label
  65.     TITLE=$(blkid -o value -s LABEL $dev)
  66.  
  67.     # TODO convert "UPPER_SNAKE_CASE" to "Title Space Case"
  68.     # TODO grab title from DVD content rather than volume label?
  69.  
  70.     dst=$3/$TITLE.mp4
  71.     if [ -f $dst ] ; then
  72.         echo "$dst already exists"
  73.     else
  74.         echo "ripping: $dst"
  75.         # TODO: avoid calling handbrake as root?
  76.         # TODO: refine transcoding options
  77.         HandBrakeCLI -i $dev \
  78.             --main-feature \
  79.             --audio-lang-list eng,fra \
  80.             --subtitle-lang-list eng,fra \
  81.             -f av_mp4 \
  82.             -o $dst
  83.  
  84.         # TODO: remove output on failure
  85.         # TODO: chown/chmod output
  86.     fi
  87.  
  88.     eject $dev
  89. else
  90.     usage
  91. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top