Index: server/DATABASE-INSTALL
===================================================================
--- server/DATABASE-INSTALL	(revision e1871d4d63477c9658f5255798f53a91e8ae192e)
+++ server/DATABASE-INSTALL	(revision f60e783e34f52c7a70ff2c937db391189c5bad09)
@@ -4,4 +4,4 @@
 
 1) Create the database:
-   	  sqlite3 gutenbach.db 'create table queue(position INTEGER, job_id TINYTEXT); create table jobs(job_id TINYTEXT, jobname TINYTEXT, user TINYTEXT, host TINYTEXT, title TINYTEXT, artist TINYTEXT, album TINYTEXT);'
+   	  sqlite3 gutenbach.db 'create table queue(position INTEGER, job_id TINYTEXT); create table jobs(job_id TINYTEXT, jobname TINYTEXT, user TINYTEXT, title TINYTEXT, artist TINYTEXT, album TINYTEXT);'
 	  
Index: rver/lib/queue
===================================================================
--- server/lib/queue	(revision e1871d4d63477c9658f5255798f53a91e8ae192e)
+++ 	(revision )
@@ -1,104 +1,0 @@
-#!/usr/bin/perl                                                                                                       
-
-use DBI;
-use Net::CUPS;
-use Net::CUPS::Destination;
-use Image::ExifTool qw(ImageInfo);
-
-use strict;
-use warnings;
-
-use vars qw/$queue/;
-require "/usr/lib/gutenbach/config/gutenbach-filter-config.pl" or die "Unable to load configuration";
-
-# Connect to the database
-my $db = DBI->connect("dbi:SQLite:dbname=gutenbach.db","","");
-
-# Check to see if table 'queue' exists; if so, drop it
-my $queue = $db->selectall_arrayref("SELECT name FROM sqlite_master where name='queue'") or die $DBI::errstr;
-my $size = scalar @$queue;
-if ($size == 1)
-{
-    $db->do("drop table queue;") or die $DBI::errstr;
-}
-elsif ($size > 1)
-{
-    die "More than one table named 'queue'";
-}
-
-# Create table 'queue'
-$db->do("create table queue(position INTEGER, job_id TINYTEXT)") or die $DBI::errstr;
-
-my $cups = Net::CUPS->new();
-my $printer = $cups->getDestination("sipbmp3");
-my @jobs = $printer->getJobs( 0, 0 );
-my ($job_ref, $job_id, $attr);
-
-my $jobnum = 0;
-my $position = 0;
-foreach $job_id(@jobs)
-{
-    # Insert job_ids into the table with correct positions
-    $db->do("insert into queue values($position, '$job_id')") or die $DBI::errstr;
-    $position++;
-
-    # $job_exists = $db->selectall_arrayref("SELECT job_id FROM jobs where job_id='$job_id'")
-
-    # $job_ref = $printer->getJob($job_id);
-    # my $filepath = "/var/spool/cups/d0$job_ref->{'id'}-001";
-    # my $fileinfo = ImageInfo($filepath);
-    # my $magic = $fileinfo->{FileType};
-    
-    # if ($jobnum == 0)
-    # {
-    # 	print $job_ref->{'user'}." is currently playing:\n";
-	
-    # 	if ($magic)
-    # 	{
-    # 	    print "\t".$magic." file ".$job_ref->{'title'}."\n";
-    # 	    foreach my $key (qw/Title Artist Album AlbumArtist/)
-    # 	    {
-    # 		if (exists $fileinfo->{$key})
-    # 		{
-    # 		    print "\t$fileinfo->{$key}\n";
-    # 		}
-    # 	    }
-    # 	}
-    # 	else
-    # 	{
-    # 	    print "\t".$job_ref->{'title'}."\n";
-    # 	}
-	
-    # 	print "\nComing up the queue:\n\n";
-    # }
-    # else
-    # {
-    # 	if ($magic)
-    # 	{
-    # 	    my $user = $job_ref->{'user'};
-    # 	    my $title = $fileinfo->{'Title'};
-    # 	    my $artist = $fileinfo->{'Artist'};
-    # 	    my $album = $fileinfo->{'Album'};
-    # 	    print "$user: \"$title\" by \"$artist\" on \"$album\"\n";
-    # 	}
-    # 	else
-    # 	{
-    # 	    my $user = $job_ref->{'user'};
-    # 	    my $file = $job_ref->{'title'};
-    # 	    print "$user: $file\n";
-    # 	}
-    # }
-    
-    # $jobnum += 1;
-}
-
-$queue = $db->selectall_arrayref("SELECT * FROM queue") or die $DBI::errstr;
-foreach my $row(@$queue)
-{
-    foreach my $val(@$row)
-    {
-	print "$val\t";
-    }
-    print "\n";
-}
-
Index: server/lib/update-db
===================================================================
--- server/lib/update-db	(revision f60e783e34f52c7a70ff2c937db391189c5bad09)
+++ server/lib/update-db	(revision f60e783e34f52c7a70ff2c937db391189c5bad09)
@@ -0,0 +1,107 @@
+#!/usr/bin/perl                                                                                                       
+
+use DBI;
+use Net::CUPS;
+use Net::CUPS::Destination;
+use Image::ExifTool qw(ImageInfo);
+
+use strict;
+use warnings;
+
+use vars qw/$queue/;
+require "/usr/lib/gutenbach/config/gutenbach-filter-config.pl" or die "Unable to load configuration";
+
+# Connect to the database
+my $db = DBI->connect("dbi:SQLite:dbname=gutenbach.db","","");
+
+# Check to see if table 'queue' exists; if so, drop it
+my $table_exists = $db->selectall_arrayref("SELECT name FROM sqlite_master where name='queue'") or die $DBI::errstr;
+my $size = scalar @$table_exists;
+if ($size == 1)
+{
+    $db->do("drop table queue;") or die $DBI::errstr;
+}
+elsif ($size > 1)
+{
+    die "More than one table named 'queue'!";
+}
+
+# Create table 'queue'
+$db->do("create table queue(position INTEGER, job_id TINYTEXT)") or die $DBI::errstr;
+
+my $cups = Net::CUPS->new();
+my $printer = $cups->getDestination("pikamp3");
+my @jobs = $printer->getJobs( 0, 0 );
+my ($job_ref, $job_id, $attr);
+my $position = 0;
+
+# Remove old jobs
+my $table = $db->selectall_arrayref("SELECT job_id FROM jobs") or die $DBI::errstr;
+foreach my $row(@$table)
+{
+    $job_id = @$row[0];
+    if (not grep {$_ eq $job_id} @jobs) {
+	$db->do("DELETE FROM jobs where job_id=".$db->quote($job_id)) or die $DBI::errstr;
+    }
+}
+
+# Add new jobs
+foreach $job_id(@jobs)
+{
+    # Insert job_ids into the table with correct positions
+    $db->do("insert into queue values($position, ".$db->quote($job_id).")") or die $DBI::errstr;
+    $position++;
+
+    # Check to see if the job already exists in jobs
+    my $job_exists = $db->selectall_arrayref("SELECT job_id FROM jobs where job_id=".$db->quote($job_id)) or die $DBI::errstr;
+    $size = scalar @$job_exists;
+    if ($size == 1)
+    {
+	next
+    }
+    elsif ($size > 1)
+    {
+	die "More than one job with id '$job_id'!";
+    }
+
+    # If it doesn't, then get the metadata and add it
+    $job_ref = $printer->getJob($job_id);
+    my $filepath = "/var/spool/cups/d0$job_ref->{'id'}-001";
+    my $fileinfo = ImageInfo($filepath);
+    my $magic = $fileinfo->{FileType};
+
+    my ($jobname, $user, $host, $title, $artist, $album);
+    $jobname = $job_ref->{'title'};
+    $user = $job_ref->{'user'};
+    $title = "";
+    $artist = "";
+    $album = "";
+    
+    if ($magic)
+    {
+	if (exists $fileinfo->{'Title'})
+	{
+	    $title = $fileinfo->{'Title'}
+	}
+	if (exists $fileinfo->{'Artist'})
+	{
+	    $artist = $fileinfo->{'Artist'}
+	}
+	if (exists $fileinfo->{'Album'})
+	{
+	    $album = $fileinfo->{'Album'}
+	}
+    }
+
+    $job_id = $db->quote($job_id);
+    $jobname = $db->quote($jobname);
+    $user = $db->quote($user);
+    $title = $db->quote($title);
+    $artist = $db->quote($artist);
+    $album = $db->quote($album);
+
+    $db->do("INSERT INTO jobs VALUES ($job_id, $jobname, $user, $title, $artist, $album)") or die $DBI::errstr;
+}
+
+$db->commit() or die $DBI::errstr;
+$db->disconnect();
