source:
client/bin/gbr
@
600e713
Last change on this file since 600e713 was 600e713, checked in by Kyle Brogle <broglek@…>, 14 years ago | |
---|---|
|
|
File size: 1.7 KB |
Rev | Line | |
---|---|---|
[fe74c7c] | 1 | #!/usr/bin/perl |
2 | ||
3 | # Written by Jessica Hamrick (C) 2010 | |
4 | ||
5 | use strict; | |
6 | use warnings; | |
7 | ||
[b58aada] | 8 | use Net::CUPS; |
9 | use Net::CUPS::Destination; | |
[7cdd65d] | 10 | use Getopt::Long; |
[b58aada] | 11 | use Image::ExifTool qw(ImageInfo); |
12 | ||
[38388ac] | 13 | my $usage = "Usage: gbr QUEUE FILES\n"; |
[fe74c7c] | 14 | |
[7cdd65d] | 15 | my $q = ""; |
16 | GetOptions ('q|queue=s' => \$q); | |
[fe74c7c] | 17 | |
[7cdd65d] | 18 | my @files = @ARGV[0 .. $#ARGV]; |
19 | ||
20 | if (!$q){ | |
21 | $q = "DEFAULT"; | |
22 | } | |
23 | if (!@files) { | |
[fe74c7c] | 24 | print $usage; |
25 | exit 1 | |
26 | } | |
27 | ||
28 | my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; | |
[85a1ac1] | 29 | if (! -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] | 34 | my ($host, $queue); |
35 | ||
36 | if (-r $configpath) { | |
37 | local $/; | |
38 | my $fh; | |
39 | open $fh, $configpath; | |
40 | eval <$fh>; | |
41 | } | |
42 | ||
[b58aada] | 43 | my $cups = Net::CUPS->new(); |
44 | $cups->setServer("$host"); | |
45 | my $printer = $cups->getDestination("$queue"); | |
[9fdf4a1] | 46 | unless( $printer){ |
47 | print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; | |
48 | exit 1; | |
49 | } | |
[b58aada] | 50 | my ($jobid, $title); |
[c5a98db] | 51 | |
[38388ac] | 52 | foreach my $file(@files) { |
53 | if ($file =~ m|http://www\.youtube\.com/watch\?v=|) { | |
[600e713] | 54 | open FILE, ">", "/tmp/gutenbach-youtube" or die "Couldn't create temporary file"; |
[b58aada] | 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.