[e1871d4] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use DBI; |
---|
| 4 | use Net::CUPS; |
---|
| 5 | use Net::CUPS::Destination; |
---|
| 6 | use Image::ExifTool qw(ImageInfo); |
---|
| 7 | |
---|
| 8 | use strict; |
---|
| 9 | use warnings; |
---|
| 10 | |
---|
| 11 | use vars qw/$queue/; |
---|
| 12 | require "/usr/lib/gutenbach/config/gutenbach-filter-config.pl" or die "Unable to load configuration"; |
---|
| 13 | |
---|
| 14 | # Connect to the database |
---|
| 15 | my $db = DBI->connect("dbi:SQLite:dbname=gutenbach.db","",""); |
---|
| 16 | |
---|
| 17 | # Check to see if table 'queue' exists; if so, drop it |
---|
| 18 | my $queue = $db->selectall_arrayref("SELECT name FROM sqlite_master where name='queue'") or die $DBI::errstr; |
---|
| 19 | my $size = scalar @$queue; |
---|
| 20 | if ($size == 1) |
---|
| 21 | { |
---|
| 22 | $db->do("drop table queue;") or die $DBI::errstr; |
---|
| 23 | } |
---|
| 24 | elsif ($size > 1) |
---|
| 25 | { |
---|
| 26 | die "More than one table named 'queue'"; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | # Create table 'queue' |
---|
| 30 | $db->do("create table queue(position INTEGER, job_id TINYTEXT)") or die $DBI::errstr; |
---|
| 31 | |
---|
| 32 | my $cups = Net::CUPS->new(); |
---|
| 33 | my $printer = $cups->getDestination("sipbmp3"); |
---|
| 34 | my @jobs = $printer->getJobs( 0, 0 ); |
---|
| 35 | my ($job_ref, $job_id, $attr); |
---|
| 36 | |
---|
| 37 | my $jobnum = 0; |
---|
| 38 | my $position = 0; |
---|
| 39 | foreach $job_id(@jobs) |
---|
| 40 | { |
---|
| 41 | # Insert job_ids into the table with correct positions |
---|
| 42 | $db->do("insert into queue values($position, '$job_id')") or die $DBI::errstr; |
---|
| 43 | $position++; |
---|
| 44 | |
---|
| 45 | # $job_exists = $db->selectall_arrayref("SELECT job_id FROM jobs where job_id='$job_id'") |
---|
| 46 | |
---|
| 47 | # $job_ref = $printer->getJob($job_id); |
---|
| 48 | # my $filepath = "/var/spool/cups/d0$job_ref->{'id'}-001"; |
---|
| 49 | # my $fileinfo = ImageInfo($filepath); |
---|
| 50 | # my $magic = $fileinfo->{FileType}; |
---|
| 51 | |
---|
| 52 | # if ($jobnum == 0) |
---|
| 53 | # { |
---|
| 54 | # print $job_ref->{'user'}." is currently playing:\n"; |
---|
| 55 | |
---|
| 56 | # if ($magic) |
---|
| 57 | # { |
---|
| 58 | # print "\t".$magic." file ".$job_ref->{'title'}."\n"; |
---|
| 59 | # foreach my $key (qw/Title Artist Album AlbumArtist/) |
---|
| 60 | # { |
---|
| 61 | # if (exists $fileinfo->{$key}) |
---|
| 62 | # { |
---|
| 63 | # print "\t$fileinfo->{$key}\n"; |
---|
| 64 | # } |
---|
| 65 | # } |
---|
| 66 | # } |
---|
| 67 | # else |
---|
| 68 | # { |
---|
| 69 | # print "\t".$job_ref->{'title'}."\n"; |
---|
| 70 | # } |
---|
| 71 | |
---|
| 72 | # print "\nComing up the queue:\n\n"; |
---|
| 73 | # } |
---|
| 74 | # else |
---|
| 75 | # { |
---|
| 76 | # if ($magic) |
---|
| 77 | # { |
---|
| 78 | # my $user = $job_ref->{'user'}; |
---|
| 79 | # my $title = $fileinfo->{'Title'}; |
---|
| 80 | # my $artist = $fileinfo->{'Artist'}; |
---|
| 81 | # my $album = $fileinfo->{'Album'}; |
---|
| 82 | # print "$user: \"$title\" by \"$artist\" on \"$album\"\n"; |
---|
| 83 | # } |
---|
| 84 | # else |
---|
| 85 | # { |
---|
| 86 | # my $user = $job_ref->{'user'}; |
---|
| 87 | # my $file = $job_ref->{'title'}; |
---|
| 88 | # print "$user: $file\n"; |
---|
| 89 | # } |
---|
| 90 | # } |
---|
| 91 | |
---|
| 92 | # $jobnum += 1; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | $queue = $db->selectall_arrayref("SELECT * FROM queue") or die $DBI::errstr; |
---|
| 96 | foreach my $row(@$queue) |
---|
| 97 | { |
---|
| 98 | foreach my $val(@$row) |
---|
| 99 | { |
---|
| 100 | print "$val\t"; |
---|
| 101 | } |
---|
| 102 | print "\n"; |
---|
| 103 | } |
---|
| 104 | |
---|