+function alarm() { perl -e 'alarm shift; exec @ARGV' "$@"; }
+
+function lsdvd_longest_title {
+ dev="$1"
+
+ # Only use lsdvd to extract the longest feature title if we didn't detect an incompatibility earlier
+ if [ $lsdvd_incompatibility -eq 1 ]; then
+ invalid_feature_title=1
+ return
+ fi
+
+ # Try the normal lsdvd command to see if it works
+ alarm $lsdvd_timeout lsdvd $dev >> "$logfile" 2>&1
+ if [ $? != 0 ]; then
+ # lsdvd didn't work
+ invalid_feature_title=1
+ lsdvd_incompatibility=1
+ return
+ fi
+
+ # lsdvd is good to go, use it
+ feature_title=`lsdvd $dev 2>/dev/null | awk '/Longest/ { print $NF }'`
+}
+
+function lsdvd_css {
+ dev="$1"
+
+ # Try the normal lsdvd command to see if it works
+ alarm $lsdvd_timeout lsdvd $dev >> "$logfile" 2>&1
+
+ if [ $? != 0 ]; then
+ # lsdvd didn't work. Try VLC.
+ lsdvd_incompatibility=1
+ if [[ -x `which cvlc` ]]; then
+ echo "-> lsdvd failed to DeCSS the DVD. Trying VLC: $dev" | tee -a "$logfile"
+ alarm $lsdvd_timeout cvlc --no-video --no-audio $dev >> "$logfile" 2>&1
+ # Once you get a DVD that VLC can't handle, figure out how
+ # to detect that here and abort.
+ #if [ $? != 1 ]; then
+ # echo "-> VLC failed to decss the DVD."
+ # return 1
+ #fi
+ else
+ fatal_and_exit "-E- lsdvd failed to DeCSS the DVD. VLC not found, but required to rip this DVD."
+ fi
+ fi
+ return 0
+}
+