10 my $photos_root = $ENV{HOME} . '/photos';
12 my $album = $ARGV[0] // die "Usage: gal mj-upgrade <album>\n";
13 print "### $album ###\n";
15 ### Scan photos.map ###
19 if ($album eq '2009/Fireworks') { $year = 2008; }
20 print "Loading map for $year\n";
21 open M, "$photos_root/photos.map" or die "No map file found\n";
26 my ($path, $hash) = split /\t/;
29 if (defined $map{$name}) {
30 my $prev = $map{$name};
31 if ($prev->{hash} ne $hash) {
32 print STDERR "Collision for $name: ", $prev->{path}, " vs. ", $path, "\n";
34 # print STDERR "Harmless collision for $name: ", $prev->{path}, " vs. ", $path, "\n";
37 $map{$name} = { path => $path, hash => $hash };
42 ### Scan static list (if any) ###
45 if (open S, "../static/photos/$album/x") {
46 print "Found static list\n";
49 my @fields = split /\t/;
51 push @src, { name => $fields[0], rotate => $fields[2], xform => $fields[3] };
52 } elsif (@fields == 2) {
53 push @src, { name => $fields[0], rotate => $fields[1], xform => '.' };
55 die "Error parsing gallery list: $_\n";
61 ### Parse index.cgi and produce gallery.new ###
63 open I, "$album/index.cgi" or die "Cannot find $album/index.cgi\n";
64 open W, ">$album/gallery.new" or die "Cannot create $album/gallery.new\n";
65 open T, ">$album/gallery.thumb" or die "Cannot create $album/gallery.thumb\n";
71 if (/^\s+"(\w+)" => "(.*)",?$/) {
73 print "Option: $1 = $2\n";
74 } elsif (/^img\("([^"]+)(\.jpe?g)", "([^"]*)"\);\s*# (\S+)/) {
81 my $map = $map{$file};
83 print STDERR "$album: No match for $file\n";
86 my $path = $map->{path};
87 my ($vv, $dd, $ff) = File::Spec->splitpath($path);
90 print "Image: $nr $path [$title]\n";
93 if ($nr =~ m{^\d+$} && $nr <= @src) {
96 print STDERR "$album: Crooked refs ($nr)\n";
101 "$photos_root/$path",
103 ($src ? $src->{rotate} : '-'),
104 ($src ? $src->{xform} : '.'),
105 ($title ne "" ? $title : '-'),
109 my $thumb = "../static/photos/$album/$nr-thumb.jpg";
111 print STDERR "$album: Cannot find thumbnail for photo $nr ($thumb)\n";
114 my $im = new Image::Magick;
115 my ($thumb_w, $thumb_h, $thumb_size, $thumb_format) = $im->PingImage($thumb) or die "Error reading $thumb\n";
116 print T "$thumb $thumb_w $thumb_h\n";
118 } elsif (/^($|#|require|SetOptions|\)|Start|Finish)/) {
121 print STDERR "$album/index.cgi: Parse error at line $.: $_\n";
128 if (scalar keys %found_dirs != 1) {
129 print STDERR "$album: Photos in multiple directories\n";
132 ### Create gallery.cf ###
134 open CF, ">$album/gallery.cf" or die "Cannot create $album/gallery.cf";
140 my $gal = require '../../default.cf';
144 for my $cf (reverse sort keys %opt) {
145 print CF "\t$cf => \"", $opt{$cf}, "\",\n";