blob: baef7a129b2bd9088f5712d20586268783d11134 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#!/bin/bash
# /usr/LH/bin/ripD_eject.sh
# A DVD rip and eject script.
########################################################################
DEV='/dev/sr0' # DVD device
MPNT='media/cdrom' # Mount Point
Ddir='/myth/video' # DVD output dir List
Bsnd='/usr/share/sounds/init.wav' # Begin sound file
Esnd='/usr/share/sounds/complete.wav' # End sound file
DATE=$(date +%Y%m%d_%H%M) # current date/time
LOG='/var/log/mythtv/ripD.log' # name of Log file.
#TRACK=$(lsdvd | grep -i longest | awk '{print $3}') #Finds longest track
FILE=$TITLE
#-----------------------------------------------------------------------
[ -r /etc/rip.cfg ] && . /etc/rip.cfg
#-----------------------------------------------------------------------
LOCK=/tmp/.ripLock.$$
[ "$DISPLAY" == "" ] && export DISPLAY=:0
########################################################################
function osd { # $1=text, $2=delay
msg_client.py --clear ripD
msg_client.py --kill
msg_client.py --msg "$1" --timeout $2 --tag ripD
} >& /dev/null
function osd_loop() {
FN=$1 ; shift
TXT="to $dir/$FILE"
N=0
while [ -f "$LOCK" ]; do
osd "Backing up '$TITLE' $TXT" 70
N=$(($N+1))
TXT="($N min. elapsed)"
sleep 60
done
}
########################################################################
osd "Detecting DVD..." 60 &
# first make sure DMA is on:
sudo hdparm -d1 -u1 $DEV >& /dev/null
dvdFound=false
for c in {1..10}; do
dvdBACKlog=$(dvdbackup -i /dev/sr0 -I)
if [[ $dvdBACKlog == *"information"* ]]; then
echo "`date` detected DVD" >> $LOG
rm -f /tmp/.ripLock.*
# attempt to get the DVD information:
TITLE=$(dvdbackup -i /dev/sr0 -I | grep information | awk '{ s = ""; for (i = 8; i <= NF; i++) s = s $i " "; print s }' | tr -d '"' | sed 's/ /_/g' | sed 's/_$//g')
dvdFound=true
osd "Found DVD '$TITLE'" 10 &
sleep 1
break
fi
sleep 3
done
if ! $dvdFound ; then
echo "no DVD" >> $LOG
osd "DVD not found" 10 &
eject ; eject
exit 0
fi
#=======================================================================
for dir in $Ddir ; do
if [ -d $dir -a -w $dir ]; then
break
fi
done
#-----------------------------------------------------------------------
if [ ! -d "$dir" ]; then
echo "no $dir" >> $LOG
osd "$dir Not Found!" 10 &
eject ; eject
exit 0
fi
if [ ! -w "$dir" ]; then
echo "$dir not writable" >> $LOG
osd "$dir Not Writable!" 10 &
eject ; eject
exit 0
fi
#-----------------------------------------------------------------------
#mount $DEV >& /dev/null
#dev=$(readlink $DEV)
#df=$(df -h /dev/$dev | grep /dev/$dev)
#MAX=$(echo $df | while read d v r ; do echo $v ; done)
#echo " backup $MAX to $dir" >> $LOG
#=======================================================================
if [ "$TITLE" == "DVD_VIDEO" -o "$TITLE" == "" \
-o "$TITLE" == " " -o "$TITLE" == "[ ].*" ]; then
# if not a good title,
TITLE="dvdbackup_$DATE"
fi
echo " $TITLE" >> $LOG
if [[ $1 = "m" ]]; then
COMMAND='dvdbackup -M -i $DEV -o $dir -n $TITLE'
FILE=$TITLE
elif [[ $1 = "h" ]]; then
COMMAND='HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "HQ 480p30 Surround" --main-feature'
FILE=$TITLE.mp4
elif [[ $1 = "n" ]]; then
COMMAND='HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "Fast 480p30" --main-feature'
FILE=$TITLE.mp4
elif [[ $1 = "l" ]]; then
COMMAND='HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "Very Fast 480p30" --main-feature'
FILE=$TITLE.mp4
else
COMMAND='dd if=$DEV of=$dir/$TITLE.iso bs=2048'
FILE=$TITLE.iso
fi
{ # for the redir below:
# Begin:
touch $LOCK
osd_loop "$dir/$TITLE" "$TITLE" &
sleep 1 ; aplay $Bsnd
eval $COMMAND
# Finish:
rm -f $LOCK
sleep 1
osd "Done Backing up '$TITLE' to $dir/$FILE" 5 &
sleep 1
aplay $Esnd
# Eject the media:
sudo eject ; sudo eject
} > $dir/.$TITLE.log 2>&1
echo " `du -sh $dir/$FILE`" >> $LOG
echo " `date` finished DVD" >> $LOG
echo "" >> $LOG
exit 0
########################################################################
# End
|