source: client/bin/gbr @ 7cdd65d

debianmacno-cups
Last change on this file since 7cdd65d was 7cdd65d, checked in by Kyle Brogle <broglek@…>, 14 years ago

Implemented default queue in client scripts.
Queue argument now optional for gb{r,rm,q}, and also takes form of -q QUEUE
now.

gutenbach-client-config -sset-default QUEUE will set default queue

Updated manpages accordingly.

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/usr/bin/perl
2
3# Written by Jessica Hamrick (C) 2010
4
5use strict;
6use warnings;
7
8use Net::CUPS;
9use Net::CUPS::Destination;
10use Getopt::Long;
11use Image::ExifTool qw(ImageInfo);
12
13my $usage = "Usage: gbr QUEUE FILES\n";
14
15my $q = "";
16GetOptions ('q|queue=s' => \$q);
17
18my @files = @ARGV[0 .. $#ARGV];
19
20if (!$q){
21    $q = "DEFAULT";
22}
23if (!@files) {
24    print $usage;
25    exit 1
26}
27
28my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
29if (! -e $configpath) {
30    print "Queue '$q' does not exist!  Did you forget to add it with 'gutenbach-client-config'?\n";
31    exit 1;
32}
33
34my ($host, $queue);
35
36if (-r $configpath) {
37    local $/;
38    my $fh;
39    open $fh, $configpath;
40    eval <$fh>;
41}
42
43my $cups = Net::CUPS->new();
44$cups->setServer("$host");
45my $printer = $cups->getDestination("$queue");
46unless( $printer){
47    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
48    exit 1;
49}
50my ($jobid, $title);
51
52foreach my $file(@files) {
53    if ($file =~ m|http://www\.youtube\.com/watch\?v=|) {
54        open FILE, ">", "/tmp/gutenbach-youtube\n" or die "Couldn't create temporary file";
55        print FILE $file;
56        $title = $file;
57        $file = "/tmp/gutenbach-youtube";
58        $printer->addOption("copies", 42);
59    }
60    else {
61        my $fileinfo = ImageInfo($file);
62        my $magic = $fileinfo->{FileType};
63
64        if ($magic && exists($fileinfo->{Title}) && exists($fileinfo->{Artist}) && exists($fileinfo->{Album})) {
65            $title = $fileinfo->{'Title'}." - ".$fileinfo->{'Artist'}." - ".$fileinfo->{'Album'};
66        }
67        else {
68            $title = $file;
69        }
70    }
71
72    $jobid = $printer->printFile($file, $title);
73   
74    if ($jobid) {
75        print "Sent job '$title' (id $jobid)\n";
76    }
77    else {
78        print "Error sending job '$title'\n";
79    }
80}
Note: See TracBrowser for help on using the repository browser.