9 my $photos_root = $ENV{HOME} . '/photos';
11 my $album = $ARGV[0] // die "Usage: gal mj-upgrade <album>\n";
12 print "### $album ###\n";
14 ### Scan photos.map ###
18 if ($album eq '2009/Fireworks') { $year = 2008; }
19 print "Loading map for $year\n";
20 open M, "$photos_root/photos.map" or die "No map file found\n";
25 my ($path, $hash) = split /\t/;
28 if (defined $map{$name}) {
29 my $prev = $map{$name};
30 if ($prev->{hash} ne $hash) {
31 print STDERR "Collision for $name: ", $prev->{path}, " vs. ", $path, "\n";
33 # print STDERR "Harmless collision for $name: ", $prev->{path}, " vs. ", $path, "\n";
36 $map{$name} = { path => $path, hash => $hash };
41 ### Scan static list (if any) ###
44 if (open S, "../static/photos/$album/x") {
45 print "Found static list\n";
48 my @fields = split /\t/;
50 push @src, { name => $fields[0], rotate => $fields[2], xform => $fields[3] };
51 } elsif (@fields == 2) {
52 push @src, { name => $fields[0], rotate => $fields[1], xform => '.' };
54 die "Error parsing gallery list: $_\n";
60 ### Parse index.cgi and produce gallery.new ###
62 open I, "$album/index.cgi" or die "Cannot find $album/index.cgi\n";
63 open W, ">$album/gallery.new" or die "Cannot create $album/gallery.new\n";
69 if (/^\s+"(\w+)" => "(.*)",?$/) {
71 print "Option: $1 = $2\n";
72 } elsif (/^img\("([^"]+)\.jpe?g", "([^"]*)"\);\s*# (\S+)/) {
78 my $map = $map{$file};
80 print STDERR "$album: No match for $file\n";
83 my $path = $map->{path};
84 my ($vv, $dd, $ff) = File::Spec->splitpath($path);
87 print "Image: $nr $path [$title]\n";
90 if ($nr =~ m{^\d+$} && $nr <= @src) {
93 print STDERR "$album: Crooked refs ($nr)\n";
100 ($src ? $src->{rotate} : '-'),
101 ($src ? $src->{xform} : '.'),
102 ($title ne "" ? $title : '-'),
104 } elsif (/^($|#|require|SetOptions|\)|Start|Finish)/) {
107 print STDERR "$album/index.cgi: Parse error at line $.: $_\n";
113 if (scalar keys %found_dirs != 1) {
114 print STDERR "$album: Photos in multiple directories\n";
117 ### Create gallery.cf ###
119 open CF, ">$album/gallery.cf" or die "Cannot create $album/gallery.cf";
125 my $gal = require '../../default.cf';
129 for my $cf (reverse sort keys %opt) {
130 print CF "\t$cf => \"", $opt{$cf}, "\",\n";