/
add-raw-and-ufraw-to-jpeg-for-upload.pl
56 lines (40 loc) · 1.29 KB
/
add-raw-and-ufraw-to-jpeg-for-upload.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';
my $directory = $ARGV[0] // '.';
opendir my $dir, $directory or die "Can't open dir `$directory': $!";
my @file = sort grep { not /^\.{1,2}$/ } readdir $dir;
closedir $dir;
if (-d 'out') {
say "`out' directory already exists!";
sleep 3;
} else {
mkdir 'out' or die "Can't create 'out': $!";
}
my @jpeg = grep { -f and /\.jpg$/i} @file;
# Go through all the JPEG files and find the equivalent CR2 and UFRAW
# files, rar them up and append them to the JPEG
for my $jpeg (@jpeg) {
my ($name, $ext) = split /\./, $jpeg;
my @append = grep { /^$name\.(?i:cr2|ufraw)$/ } @file;
if (!@append) {
say "No cr2 or ufraw files for $jpeg, skipping";
next;
}
if (-f "out/$jpeg") {
say "out/$jpeg already exists";
next;
}
$, = ",";
say "$jpeg -> append @append";
my $cmd;
$cmd = "rar a $name.rar @append";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "cat $jpeg $name.rar >> $jpeg.new";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "rm $name.rar";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "mv $jpeg.new out/$jpeg";
system $cmd and die "Command `$cmd' failed with code `$?'";
}