| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | # JAlbum config : | ||
| 4 | # Tab main >> | ||
| 5 | # Image directory : Kimdaba's root folder | ||
| 6 | # Tab advanced >> | ||
| 7 | # ignore pattern : ThumbNails|CategoryImages|index.xml | ||
| 8 | |||
| 9 | |||
| 10 | use strict; | ||
| 11 | use Image::Kimdaba; | ||
| 12 | use English qw( -no_match_vars ) ; | ||
| 13 | |||
| 14 | my @ListOfPictures; | ||
| 15 | |||
| 16 | my $folder=getRootFolder(); | ||
| 17 | parseDB( "$folder" ); | ||
| 18 | |||
| 19 | ## Looks like there is no way to start JAlbum with a specified set of pictures | ||
| 20 | |||
| 21 | ##@ListOfPictures=matchAnyOption( "Keywords" => [ "jalbum" ] ); | ||
| 22 | ##my $nb=scalar @ListOfPictures; | ||
| 23 | ## | ||
| 24 | ##print <<END | ||
| 25 | ##This script will create comments used by the JAlbum software : http://jalbum.net/ | ||
| 26 | ##for the $nb pictures with the "jalbum" keyword. | ||
| 27 | ## | ||
| 28 | ##END | ||
| 29 | ##; | ||
| 30 | ##if ($nb == 0) { | ||
| 31 | ## print "$nb pictures found...\nSet the \"jalbum\" keyword first\n"; | ||
| 32 | ## exit( 1 ); | ||
| 33 | ##} | ||
| 34 | |||
| 35 | my %dirs; | ||
| 36 | for (keys %imageattributes) { | ||
| 37 | no warnings; | ||
| 38 | if ( m#^(.*)/(.*)# ) { | ||
| 39 | push @{ $dirs{$1} }, $_; | ||
| 40 | } else { | ||
| 41 | push @{ $dirs{"."} }, $_; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | while( my ($dir,$r_urls) = each %dirs ) | ||
| 45 | { | ||
| 46 | my $nb=0; | ||
| 47 | chdir "$folder/$dir" ; | ||
| 48 | open (C, "> comments.properties" ) || die "Cannot write comment file $!"; # JAlbum comment file | ||
| 49 | print "Directory '$dir' ... "; | ||
| 50 | |||
| 51 | for my $url (@$r_urls) { | ||
| 52 | next unless (-r "$folder/$url" ); | ||
| 53 | next unless exists $imageattributes{$url}; | ||
| 54 | |||
| 55 | #print "\t$url...\n"; | ||
| 56 | $nb++; | ||
| 57 | |||
| 58 | (my $relativename = $url) =~ s#.*/## ; | ||
| 59 | print C "$relativename="; | ||
| 60 | |||
| 61 | my %attrs=%{ $imageattributes{$url} }; | ||
| 62 | my $date=print_date( %attrs ); | ||
| 63 | print C $date; | ||
| 64 | |||
| 65 | my %options=(); | ||
| 66 | if( exists $imageoptions{$url} ) { | ||
| 67 | %options=%{ $imageoptions{$url} }; | ||
| 68 | }; | ||
| 69 | while( my ($key, $r_values) = each( %options ) ) | ||
| 70 | { | ||
| 71 | print C "<b>$key: </b> ", join('; ', @$r_values ) , "<br/>\\\n"; | ||
| 72 | } | ||
| 73 | |||
| 74 | unless ( $attrs{"description"} eq "" ) { | ||
| 75 | my $desc = $attrs{'description'} ; | ||
| 76 | print C "<b>Description: </b>$desc<br/>\\\n"; | ||
| 77 | } | ||
| 78 | print C "\n"; | ||
| 79 | } | ||
| 80 | print " $nb pictures found > $dir/comments.properties\n"; | ||
| 81 | close( C ); | ||
| 82 | } | ||
| 83 | |||
| 84 | sub print_date { | ||
| 85 | my %attrs=@_; | ||
| 86 | my $res; | ||
| 87 | my $minutes; | ||
| 88 | |||
| 89 | if ( ($attrs{"yearFrom"} eq "") or ($attrs{"yearFrom"} eq "1970" ) ) { | ||
| 90 | return ""; | ||
| 91 | } | ||
| 92 | $res = "<b>Date: </b> $attrs{'yearFrom'}-$attrs{'monthFrom'}-$attrs{'dayFrom'} "; | ||
| 93 | |||
| 94 | my ($hour,$minute,$second) =( $attrs{'hourFrom'}, $attrs{'minuteFrom'}, $attrs{'secondFrom'} ); | ||
| 95 | $hour=0 if ($hour eq ""); | ||
| 96 | $minute=0 if ($minute eq ""); | ||
| 97 | $second=0 if ($second eq ""); | ||
| 98 | $minutes="$hour:$minute:$second" ; | ||
| 99 | $res .= " $minutes " unless ($minutes eq "0:0:0" ); | ||
| 100 | |||
| 101 | if ( ($attrs{"yearTo"} eq "") or ($attrs{"yearTo"} eq "0" ) ) { | ||
| 102 | $res .= "<br/>\\\n"; | ||
| 103 | return $res; | ||
| 104 | } | ||
| 105 | |||
| 106 | $res .= " to $attrs{'yearTo'}-$attrs{'monthTo'}-$attrs{'dayTo'} "; | ||
| 107 | |||
| 108 | ($hour,$minute,$second) =( $attrs{'hourTo'}, $attrs{'minuteTo'}, $attrs{'secondTo'} ); | ||
| 109 | { | ||
| 110 | no warnings; | ||
| 111 | $hour=0 if ($hour eq ""); | ||
| 112 | $hour=0 if ($hour eq ""); | ||
| 113 | $minute=0 if ($minute eq ""); | ||
| 114 | $second=0 if ($second eq ""); | ||
| 115 | $minute=0 if ($minute eq ""); | ||
| 116 | $second=0 if ($second eq ""); | ||
| 117 | } | ||
| 118 | $minutes="$hour:$minute:$second" ; | ||
| 119 | $res .= " $minutes " unless ($minutes eq "0:0:0" ); | ||
| 120 | |||
| 121 | $res .= "<br/>\\\n"; | ||
| 122 | return $res; | ||
| 123 | |||
| 124 | } |