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
RevLine 
[fe74c7c]1#!/usr/bin/perl
2
3# Written by Jessica Hamrick (C) 2010
4
5use strict;
6use warnings;
7
[b58aada]8use Net::CUPS;
9use Net::CUPS::Destination;
[7cdd65d]10use Getopt::Long;
[b58aada]11use Image::ExifTool qw(ImageInfo);
12
[38388ac]13my $usage = "Usage: gbr QUEUE FILES\n";
[fe74c7c]14
[7cdd65d]15my $q = "";
16GetOptions ('q|queue=s' => \$q);
[fe74c7c]17
[7cdd65d]18my @files = @ARGV[0 .. $#ARGV];
19
20if (!$q){
21    $q = "DEFAULT";
22}
23if (!@files) {
[fe74c7c]24    print $usage;
25    exit 1
26}
27
28my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
[85a1ac1]29if (! -e $configpath) {
[0d02eca]30    print "Queue '$q' does not exist!  Did you forget to add it with 'gutenbach-client-config'?\n";
[85a1ac1]31    exit 1;
32}
33
[fe74c7c]34my ($host, $queue);
35
36if (-r $configpath) {
37    local $/;
38    my $fh;
39    open $fh, $configpath;
40    eval <$fh>;
41}
42
[b58aada]43my $cups = Net::CUPS->new();
44$cups->setServer("$host");
45my $printer = $cups->getDestination("$queue");
[9fdf4a1]46unless( $printer){
47    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
48    exit 1;
49}
[b58aada]50my ($jobid, $title);
[c5a98db]51
[38388ac]52foreach my $file(@files) {
53    if ($file =~ m|http://www\.youtube\.com/watch\?v=|) {
[b58aada]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);
[38388ac]59    }
60    else {
[b58aada]61        my $fileinfo = ImageInfo($file);
62        my $magic = $fileinfo->{FileType};
63
[9fdf4a1]64        if ($magic && exists($fileinfo->{Title}) && exists($fileinfo->{Artist}) && exists($fileinfo->{Album})) {
[b58aada]65            $title = $fileinfo->{'Title'}." - ".$fileinfo->{'Artist'}." - ".$fileinfo->{'Album'};
66        }
67        else {
68            $title = $file;
[38388ac]69        }
70    }
71
[b58aada]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    }
[c5a98db]80}
Note: See TracBrowser for help on using the repository browser.