diff --git a/rip_dvd.pl b/rip_dvd.pl index 3d443da..f7dc91c 100755 --- a/rip_dvd.pl +++ b/rip_dvd.pl @@ -1,4 +1,5 @@ -# !/usr/bin/perl +#!/usr/bin/perl + # Copy dvd with dvdbackup sub trim { @@ -8,11 +9,19 @@ sub trim { } sub printHelp { - print "Usage: $0 [source] + print +"Usage: $0 [source] + source: Dvd device to rip from + Defaults to /dev/cdrom - source: dvd device to rip from. Default: /dev/cdrom" +Error-codes: + 0 - Success + 2 - Destination folder already exists + * - Some unexpected error +" } +my $startTime = `date +%s`; my $source = "/dev/cdrom"; if($ARGV[0] eq "help" || $ARGV[0] eq "--help"){ printHelp; @@ -24,15 +33,28 @@ if($ARGV[0] eq "help" || $ARGV[0] eq "--help"){ my $dest = "/home/julian/Videos/dvds/"; my $title = trim `lsdvd /dev/cdrom | grep "Disc Title" | sed 's/Disc Title: //'`; +if(-d $dest . $title) { + print "Destination folder already exists!"; + exit 2; +} + print "Ripping dvd $title ($source) to $dest"; my $exitcode = system("dvdbackup -i $source -o $dest -M -n $title"); # $exitcode >>= 8; +my $now = `date +%s`; +my $elapsedTimeSeconds = $now - $startTime; +my $elapsedTimeMinutes = $elapsedTimeSeconds / 60.0; +my $elapsedTimeFormatted = sprintf "%.1f", $elapsedTimeMinutes; + if($exitcode == 0) { - print "Success!"; + print "Success!\nRipping took $elapsedTimeFormatted min\n"; + system 'notify-send "DVD $title ripped successfully in ' . $elapsedTimeFormatted . ' min!!!"'; + system "mplayer /usr/share/sounds/freedesktop/stereo/bell.oga 2&> /dev/null"; +} else { + print "Error!\nRipping took $elapsedTimeFormatted min\n"; + system 'notify-send "Error ripping DVD $title !!!"'; + system "mplayer /usr/share/sounds/freedesktop/stereo/bell.oga 2&> /dev/null"; } - -`notify-send "DVD $title ripped successfully!!!"`; # `eject $source`; -