Search:  
Gentoo Wiki

Tip_managing_your_collection_of_dvd_extracted_to_the_hard_disk


Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article


Tip managing your collection of dvd extracted to the hard disk

video manager in action
video manager in action

Here is a perl script for managing dvds you have extracted to the hard disk.
I haven't tested with multiple dvds but I have tested it with multiple videos so it should work

The dependencies

emerge -av gtk2-perl #for the gui
emerge -av mplayer #for the preview of the image otherwise you can also emerge totem but it won't preview the dvds
emerge -av kaffeine #ntest it you'll see that when you change video the player stays and a new video is embedded inside

The script

#!/usr/bin/perl -w
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 3 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.

# use strict;

#tunable variables
our $first_video;
our $pipe;
our $MODE="dvd"; #choice between dvd and videos   #dvd mode didn't work because totem-video-thumbnailer segfaults... so i bugreported and switched to mplayer
# our $mplayer_time;
our $SETTINGS="$ENV{HOME}/.video_manager/";   #(getpwuid $>)[7]
our $FORMAT='.png';
our @pixbuf;



if ($MODE eq "dvd") {
our $VIDEO_DIR='/media/hdc1/films';
our $PROGRAM="kaffeine";
our $PREVIEW_PROGRAM="mplayer"; #choose between mplayer and totem

}

elsif ($MODE eq "videos"){
# our $VIDEO_DIR="/STORAGE/videos";
our $VIDEO_DIR='/home/regis/rex/youtube/daft punk';
# our $VIDEO_DIR="/home/gentux/daft_punk/";
our $PROGRAM="kaffeine";
our $PREVIEW_PROGRAM="mplayer"; #choose between mplayer and totem
}


use Gtk2 '-init' ;
use Glib qw/TRUE FALSE/;
use Gtk2::SimpleList;
use File::Spec;
#use Net::DBus;      #needed for vlc


our @display;
our $first_time_play_file;

#CLI code
opendir(DIR, $VIDEO_DIR) or die "can’t opendir $VIDEO_DIR: $!";
our @files = readdir(DIR);
@files = File::Spec->no_upwards( @files ); # remoove the . and the ..

closedir DIR;

foreach $file (@files) {
chomp $file;
push (@display,$file);
}

sub gui_quit{
   Gtk2->main_quit;
}

sub time_calculations_old {
($total_seconds) = @_;
print 'total_seconds: ',"$total_seconds\n";

my $int_total_seconds = int ($total_seconds);
print "int_total_seconds: $int_total_seconds\n";

my $snapshot_time_seconds_total = int($int_total_seconds / 2);
print "snapshot_time_seconds_total: $snapshot_time_seconds_total\n";


my $snapshot_time_hours = int ($snapshot_time_seconds_total/3600);
print "snapshot_time_hours: $snapshot_time_hours\n";
my $snapshot_time_minutes: = int ($snapshot_time_seconds_total - $snapshot_time_hours * 60);
print "snapshot_time_minutes: $snapshot_time_minutes\n";
my $snapshot_time_seconds = int ($snapshot_time_seconds_total - $snapshot_time_hours * 3600 - $snapshot_time_minutes * 60);
print "snapshot_time_seconds: $snapshot_time_seconds\n";

my $mplayer_time = "$snapshot_time_hours:$snapshot_time_minutes:$snapshot_time_seconds";
print "mplayer time: $mplayer_time\n";
return $mplayer_time;
}
sub time_calculations {
($total_seconds) = @_;


my $int_total_seconds = int ($total_seconds);
print "int_total_seconds: $int_total_seconds\n";

my $snapshot_time_seconds_total = int($int_total_seconds / 2);
print "snapshot_time_seconds_total: $snapshot_time_seconds_total\n";


my $snapshot_time_hours = int ($snapshot_time_seconds_total/3600);
print "snapshot_time_hours: $snapshot_time_hours\n";
my $snapshot_time_hours_rest = int ($snapshot_time_seconds_total % 3600);

my $snapshot_time_minutes: = int ($snapshot_time_hours_rest / 60);
print "snapshot_time_minutes: $snapshot_time_minutes\n";
my $snapshot_time_minutes_rest: = int ($snapshot_time_hours_rest % 60);


my $snapshot_time_seconds = int ($snapshot_time_minutes_rest);
print "snapshot_time_seconds: $snapshot_time_seconds\n";

if ($snapshot_time_minutes lt 10){
$snapshot_time_minutes = 0 . $snapshot_time_minutes;
}

if ($snapshot_time_seconds lt 10){
$snapshot_time_seconds = 0 . $snapshot_time_seconds;
}



my $mplayer_time = "$snapshot_time_hours:$snapshot_time_minutes:$snapshot_time_seconds";
print "mplayer time: $mplayer_time\n";
return $mplayer_time;
}





#create a window and put a table inside and put a scrolled window inside the table
my $window = Gtk2::Window->new ('toplevel');;
$window->signal_connect (delete_event => \&gui_quit );

my $table = Gtk2::Table->new (2,2 ,FALSE);
$window->add($table);
my $sw = Gtk2::ScrolledWindow->new (undef, undef);
   $sw->set_shadow_type ('etched-out');
   $sw->set_policy ('automatic', 'automatic');
   $sw->set_size_request (300, 300);
   $sw->set_border_width(5);
my $button_launch = Gtk2::Button->new("Lancer");
my $button_quit = Gtk2::Button->new("quiter");
$button_quit->signal_connect("clicked" => \&quit);
$button_launch->signal_connect("clicked" => \&launch);

my $slist = Gtk2::SimpleList->new (   'Video'  =>  'pixbuf',
               'nom'    => 'text');
$table->attach($button_quit,0,1,1,2,[qw(fill)],[qw()],undef,undef);
$table->attach($button_launch,1,2,1,2,[qw(fill)],[qw()],undef,undef);
$table->attach_defaults($sw,0,2,0,1);
$sw->add($slist);




if (! -e $SETTINGS){mkdir "$SETTINGS" or die "can't create $SETTINGS";}

if ($MODE eq "videos") {
   foreach $file (@display) {
      my $input =  "$VIDEO_DIR/$file";
      my $output = "$SETTINGS$file$FORMAT";
      print "here's the input: $input\n";
      print "here's the output: $output\n";
           if (! -e $output){
         if ($PREVIEW_PROGRAM eq "totem"){system "totem-video-thumbnailer", "-l", $input, $output;}   
         if ($PREVIEW_PROGRAM eq "mplayer"){mplayer_videos($input,$output);}   

            }
      
      my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ("$output",100,100) or die "can't pixbuf $output";
      push (@pixbuf,$pixbuf);

}
}

if ($MODE eq "dvd") {
   foreach $file (@display) {
      my $input =  "$VIDEO_DIR/$file";
      my $output = "$SETTINGS$file$FORMAT";
      chdir "$SETTINGS";
      print "here's the input: $input\n";
      print "here's the output: $output\n";
#       $snapshot = int($length/2);
      if (! -e $output){
   print 'output',"$output\n";
         my $total_seconds = `mplayer -nosound -dvd-device $input dvd:// -frames 0 -identify 2>&1|grep -i LENGTH|sed s/.*\=// | tail -n 1`;
#          print "lenght: $lenght \n";
   print ' $total_seconds '," $total_seconds\n";

#          
         my $mplayer_time= time_calculations($total_seconds);
   print 'mplayer_time ',"$mplayer_time\n";



#          $snapshot_time = time_function($lenght);
#          time_function($lenght);
         system "mplayer","-nosound", "-dvd-device", $input, "dvd://", "-frames", "1", "-vo", "png", "-ss", $mplayer_time;
         rename "00000001.png", "$file$FORMAT" or die "failled to rename to $file$FORMAT";
         }
      
      # my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ("$output",50,50) or die "can't process $output";
      my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ("$output",100,100) or die "can't pixbuf $output";
      push (@pixbuf,$pixbuf);
#directory->mplayer length->integer /2->mplayer->00000001.png->rename->pixbf rename
}}


sub mplayer_dvd {
my($input,$output) = @_;
chdir "$SETTINGS";
my $total_seconds = `mplayer -nosound -dvd-device $input dvd:// -frames 0 -identify 2>&1|grep -i LENGTH|sed s/.*\=// | tail -n 1`;
my $mplayer_time= time_calculations($total_seconds);
system "mplayer","-nosound", "-dvd-device", $input, "dvd://", "-frames", "1", "-vo", "png", "-ss", $mplayer_time;
rename "00000001.png", "$file$FORMAT" or die "failled to rename";
}

sub mplayer_videos {
my($input,$output) = @_;
chdir "$SETTINGS";
my $total_seconds = `mplayer -nosound \Q$input\E -frames 0 -identify 2>&1|grep -i LENGTH|sed s/.*\=// | tail -n 1`;
print "total_seconds: $total_seconds\n";
my $mplayer_time= time_calculations($total_seconds);
system "mplayer", $input,"-frames", "1", "-vo", "png", "-ss", $mplayer_time;

rename "00000001.png", "$file$FORMAT" or die "failled to rename";
}

# time_function {
# $lenght = @_;
# my $int_lenght = int ($lenght);
# print "$int_lenght\n";
# 
# my $time = $int_lenght/25;
# print "time: $time\n";
# 
# my $snapshot_time_seconds_total = int($time/2);
# print "snapshot time: $snapshot_time_seconds\n";
# 
# 
# my $snapshot_time_hours = int ($snapshot_time_seconds_total/3600);
# print "$snapshot_time_hours\n";
# my $snapshot_time_minutes = int (($snapshot_time_seconds - ($snapshot_time_hours * 3600)) / 60);
# print "$snapshot_time_minutes\n";
# my $snapshot_time_seconds = int ($snapshot_time_seconds - ($snapshot_time_hours * 3600) - ($snapshot_time_minutes * 60));
# print "$snapshot_time_seconds\n";
# 
# $mplayer_time = "$snapshot_time_hours:$snapshot_time_minutes:$snapshot_time_seconds";
# 
# #lenght->int->/25->hours,minutes,secondes
# }






# 
# eval: @arry = 0..20; $guesswhatihave = @arry; [$arry[$#arry], $guesswhatihave, $arry[$guesswhatihave]];
# eval 


our $display_number = @display;

for my $i (0..($display_number - 1)) { 
push @{$slist->{data}} , ([$pixbuf[$i],$display[$i]]);
}


sub quit {Gtk2->main_quit;}

sub launch {
@selection = $slist->get_selected_indices;
# print "@selection a ete selectione\n";
print "launching @files[@selection]\n";

if ($MODE eq "dvd") {
close $pipe;   #closing pipe without checking won't hurt...we could have implementd checks but that's more lines so i removed them
print "dvd:/$VIDEO_DIR/@files[@selection]\n";
open $pipe, '-|', "$PROGRAM", "dvd:/$VIDEO_DIR/@files[@selection]";
}

# if ($first_video ne 1) {
# if ($PROGRAM ne "vlc") { 
# close $pipe;   #closing pipe without checking won't hurt...we could have implementd checks but that's more lines so i removed them
# open $pipe, '-|', "$PROGRAM", "$VIDEO_DIR/@files[@selection]"
# }}
# 
# if ($PROGRAM eq "vlc") {
# 
# # if ($first_time_play_file ne 1) {
# open $pipe, '-|', "$PROGRAM", "--control", "dbus", "$VIDEO_DIR/@files[@selection]";
# # $first_time_play_file = 1;
# # }
# # else {
# # 
# # }




# }
} #sub launch



$window->show_all;
Gtk2->main;
0;



#TODO kill the media player before restarting another session closing the pipe or if it's vlc control it using dbus
#handle the folders and the others files
#doesn't close corectly when there is a media player instance
Retrieved from "http://www.gentoo-wiki.info/Tip_managing_your_collection_of_dvd_extracted_to_the_hard_disk"

Last modified: Mon, 08 Sep 2008 19:46:00 +0000 Hits: 3,280