source: client/bin/gbr @ 0d02eca

debianmacno-cupsweb
Last change on this file since 0d02eca was 0d02eca, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

Add a useful reminder message to client scripts, "Did you forget to add it [the queue] with gutenbach-client-config?"

  • Property mode set to 100755
File size: 1.4 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 Image::ExifTool qw(ImageInfo);
11
12my $usage = "Usage: gbr QUEUE FILES\n";
13
14my $q = $ARGV[0];
15my @files = @ARGV[1 .. $#ARGV];
16
17if (!$q or !@files) {
18    print $usage;
19    exit 1
20}
21
22my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
23if (! -e $configpath) {
24    print "Queue '$q' does not exist!  Did you forget to add it with 'gutenbach-client-config'?\n";
25    exit 1;
26}
27
28my ($host, $queue);
29
30if (-r $configpath) {
31    local $/;
32    my $fh;
33    open $fh, $configpath;
34    eval <$fh>;
35}
36
37my $cups = Net::CUPS->new();
38$cups->setServer("$host");
39my $printer = $cups->getDestination("$queue");
40my ($jobid, $title);
41
42foreach my $file(@files) {
43    if ($file =~ m|http://www\.youtube\.com/watch\?v=|) {
44        open FILE, ">", "/tmp/gutenbach-youtube\n" or die "Couldn't create temporary file";
45        print FILE $file;
46        $title = $file;
47        $file = "/tmp/gutenbach-youtube";
48        $printer->addOption("copies", 42);
49    }
50    else {
51        my $fileinfo = ImageInfo($file);
52        my $magic = $fileinfo->{FileType};
53
54        if ($magic) {
55            $title = $fileinfo->{'Title'}." - ".$fileinfo->{'Artist'}." - ".$fileinfo->{'Album'};
56        }
57        else {
58            $title = $file;
59        }
60    }
61
62    $jobid = $printer->printFile($file, $title);
63   
64    if ($jobid) {
65        print "Sent job '$title' (id $jobid)\n";
66    }
67    else {
68        print "Error sending job '$title'\n";
69    }
70}
Note: See TracBrowser for help on using the repository browser.