Here's the full code so you can get a better idea about where everything falls (note: not everything is fully implimented)
#/usr/bin/perl
use Config::Simple;
use Switch;
tie %DVD, "Config::Simple", '/home/mike/MyVideos/titles';
tie %Config, "Config::Simple", '/home/mike/MyVideos/config';
tied(%Config)->autosave(1);
while ()
{
system "clear";
print "---------OPTIONS-----------\n";
print "\'add\' to enter new title:\n";
print "\'delete\' to remove a title:\n";
print "\'import\' to rip a new DVD:\n";
print "\'quit\' to exit:\n";
print "---------------------------\n";
print "DVD Titles\n\n";
foreach (sort keys %DVD)
{
print "$_: \n";
}
print "\nEnter the name of the movie you want to see:";
chomp($title = <STDIN>);
switch ($title)
{
case ('add')
{
&add_title();
}
case ('delete')
{
&remove_title();
}
case ('import')
{
open(LSDVD, "lsdvd -p /dev/hdc|");
@lsdvd = <LSDVD>;
shift(@lsdvd);
print "$lsdvd[1]";
sleep(1);
$lsdvd = $lsdvd[1];
@lsdvd = split(/ /, $lsdvd);
$lsdvd = pop @lsdvd;
print $lsdvd;
$_ = $lsdvd;
if (/(\w+)/)
{
print $!;
}
close(LSDVD);
sleep(5);
#&import_dvd();
}
case ('quit')
{
&quit();
}
else
{
$title = "default." . "$title";
$i =0;
foreach (keys %DVD)
{
if ($title eq $_)
{
$i = 1;
&play_movie();
}
}
if ($i eq 0)
{
system "clear";
print "Please enter a valid title!\n";
sleep(1);
}
}
}
}
sub play_movie
{
print "Loading Movie...\n";
@mount = ("sudo mount" , "-o loop", "-t auto " , "\"$DVD{$title}\"
+" , " /media/dvdbackup");
print @mount;
system "@mount";
print "\nEnjoy!\n";
system("xine -I -A esd -B -D -f --no-splash --verbose=0 dvd:/media
+/dvdbackup/1");
system("sudo umount /media/dvdbackup");
print "Thank you for watching.\n";
}
sub add_title
{
system "clear";
print "Enter the name of the movie: ";
chomp($name = <STDIN>);
$name = "default." . "$name";
print "Enter the file location: ";
chomp($loc = <STDIN>);
print $name . $loc;
tied(%DVD)->param( "$name" , "$loc" );
tied(%DVD)->write();
print "%DVD";
sleep(5)
}
sub import_dvd
{
}
sub remove_title
{
system "clear";
print "Enter Title you wish to remove (this will delete the .iso):
+";
chomp($title = "default." . <STDIN>);
print $DVD{$title} . "\n";
print $title . "\n";
tied(%DVD)->delete("$title");
tied(%DVD)->write();
sleep(2);
}
sub quit
{
tied(%DVD)->write();
exit;
}
I realize the code is undoubtedly ugly, this is my first #real# program so be gentle. The sticky part now is in the import section. You guys are a life saver.
By the way I didn't want to impliment unlink until I had the import code done (just incase). |