#!/usr/bin/perl ####################################################################### # # # this is free software released under which ever licence you prefer # # author: ottaky@ottaky.com # # # ####################################################################### use Curses::UI; #### edit these ############################################################### # If lsdvd and mplayer are in your path, leave these blank # Otherwise, enter the paths to lsdvd and mplayer my $lsdvd_path = ''; my $mplayer_path = ''; # If lsdvd fails to automagically select your DVD drive, # enter the path to your drive here e.g. /dev/hdd my $dvd_path = ''; ############################################################################### unless ($lsdvd_path) { $lsdvd_path = `which lsdvd`; die "You need to tell dvdripui.pl where lsdvd is\n" unless ($lsdvd_path); chomp($lsdvd_path) } unless ($mplayer_path) { $mplayer_path = `which mplayer`; chomp($mplayer_path) } if (-x $lsdvd_path) { eval `$lsdvd_path -x -Op $dvd_path 2>/dev/null`; if ($lsdvd{'longest_track'}) { my $cui = new Curses::UI; my $win = $cui->add('win', 'Window'); my $y = 0; my $col2 = 20; $win->add('label_disc', 'Label', -x => 0, -y => $y++, -text => '- DISC -'); $y++; foreach my $value ('title','vmg_id','provider_id','longest_track') { $win->add('label_'.$value, 'Label', -x => 0, -y => $y, -text => $value); $win->add('label_val_'.$value, 'Label', -x => $col2, -y => $y++, -text => $lsdvd{$value}); } foreach my $track (@{$lsdvd{'track'}}) { next unless ($$track{'ix'} == $lsdvd{'longest_track'}); $win->add('label_video', 'Label', -x => 0, -y => $y, -text => 'video'); $win->add('label_val_'.$value, 'Label', -x => $col2, -y => $y++, -text => $$track{'format'}.' '.$$track{'width'}.' x '.$$track{'height'}.' @ '.$$track{'fps'}.'fps'); my $h = int($$track{'length'} / 3600); my $m = int(($$track{'length'} - ($h * 3600)) / 60); my $s = int(($$track{'length'} - (($h * 3600) + ($m * 60)))); $win->add('label_duration', 'Label', -x => 0, -y => $y, -text => 'duration'); $win->add('label_val_duration', 'Label', -x => $col2, -y => $y++, -text => "${h}h ${m}m ${s}s"); my (@avals, %alabels); $win->add('label_audio', 'Label', -x => 0, -y => $y, -text => 'audio'); foreach my $audio (@{$$track{'audio'}}) { push(@avals, $$audio{'streamid'}); $alabels{$$audio{'streamid'}} = join(', ', ($$audio{'streamid'}, $$audio{'channels'}.'ch', $$audio{'language'})); } my $audiopopup = $win->add('audiopopup', 'Popupmenu', -x => $col2, -y => $y++, -values => \@avals, -labels => \%alabels, -selected => 0); $audiopopup->focus(); my @svals = ('x'); my %slabels = ('x' => 'None'); $win->add('label_subtitle', 'Label', -x => 0, -y => $y, -text => 'subtitles'); foreach my $subtitle (@{$$track{'subp'}}) { next if ($$subtitle{'langcode'} eq 'xx'); push(@svals, $$subtitle{'streamid'}); $slabels{$$subtitle{'streamid'}} = join(', ', ($$subtitle{'streamid'}, $$subtitle{'langcode'}, $$subtitle{'language'}, $$subtitle{'content'})); } my $subtitlepopup = $win->add('subtitlepopup', 'Popupmenu', -x => $col2, -y => $y++, -values => \@svals, -labels => \%slabels, -selected => 0); $y++; $win->add('label_output', 'Label', -x => 0, -y => $y++, -text => '- OUTPUT -'); $y++; $win->add('label_target', 'Label', -x => 0, -y => $y, -text => 'target size'); my $targetpopup = $win->add('targetpopup', 'Popupmenu', -x => $col2, -y => $y++, -values => [ 700, 350 ], -labels => { 700 => '700MB', 350 => '350MB' }, -selected => 0); $win->add('label_arate', 'Label', -x => 0, -y => $y, -text => 'audio bitrate'); my $aratepopup = $win->add('aratepopup', 'Popupmenu', -x => $col2, -y => $y++, -values => [ 128, 64, 32 ], -labels => { 128 => '128kbps', 64 => '64kbps', 32 => '32kbps' }, -selected => 0); $win->add('label_keys', 'Label', -x => 0, -y => ++$y, -text => '[q]uit [t]est [d]dump'); $cui->set_binding( sub { if (-x $mplayer_path) { my $cmd = '/usr/local/bin/mplayer dvd://'.$lsdvd{'longest_track'}.' '. '-aid '.oct($audiopopup->get()). (($subtitlepopup->get() ne 'x') ? ' -sid '.(oct($subtitlepopup->get()) - 32) : ''); `$cmd 2>/dev/null`; } else { $cui->error('You need to tell dvdripui.pl where mplayer is'); } }, 't'); $cui->set_binding( sub { my $maxsize = int($targetpopup->get() * 1000); my $seconds = int($$track{'length'}); my $audiosize = int(($aratepopup->get() / 8) * $seconds); my $libre = $maxsize - $audiosize; my $rate = int(($libre * 8) / $seconds); my $cmd = 'mencoder dvd://'.$lsdvd{'longest_track'}.' '. '-aid '.oct($audiopopup->get()).' '. (($subtitlepopup->get() ne 'x') ? '-sid '.(oct($subtitlepopup->get()) - 32).' ' : ''). '-ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate='.$rate.' '. '-vop scale -zoom -xy 640 -oac mp3lame -lameopts br='.$aratepopup->get().' '. '-o '.$lsdvd{'title'}.'.avi'; $cui->dialog($cmd); }, 'd'); $cui->set_binding( sub { exit 0; }, 'q'); $cui->MainLoop; last; } } else { die "$lsdvd_path failed to return longest_track\n" } } else { die "$lsdvd_path is not executable\n" }