source: server/lib/queue @ e1871d4

Last change on this file since e1871d4 was e1871d4, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

First few steps towards creating gutenbach queue database

  • Property mode set to 100755
File size: 2.7 KB
Line 
1#!/usr/bin/perl                                                                                                       
2
3use DBI;
4use Net::CUPS;
5use Net::CUPS::Destination;
6use Image::ExifTool qw(ImageInfo);
7
8use strict;
9use warnings;
10
11use vars qw/$queue/;
12require "/usr/lib/gutenbach/config/gutenbach-filter-config.pl" or die "Unable to load configuration";
13
14# Connect to the database
15my $db = DBI->connect("dbi:SQLite:dbname=gutenbach.db","","");
16
17# Check to see if table 'queue' exists; if so, drop it
18my $queue = $db->selectall_arrayref("SELECT name FROM sqlite_master where name='queue'") or die $DBI::errstr;
19my $size = scalar @$queue;
20if ($size == 1)
21{
22    $db->do("drop table queue;") or die $DBI::errstr;
23}
24elsif ($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
32my $cups = Net::CUPS->new();
33my $printer = $cups->getDestination("sipbmp3");
34my @jobs = $printer->getJobs( 0, 0 );
35my ($job_ref, $job_id, $attr);
36
37my $jobnum = 0;
38my $position = 0;
39foreach $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;
96foreach my $row(@$queue)
97{
98    foreach my $val(@$row)
99    {
100        print "$val\t";
101    }
102    print "\n";
103}
104
Note: See TracBrowser for help on using the repository browser.