# Album Plugin: extra/media_rss # For info: 'album -plugin_info extra/media_rss' # For usage: 'album -plugin_usage extra/media_rss' # The plugin should have been written using the XML::RSS module combined with # http://search.yahoo.com/mrss namespace. But, outputting the stream to a file # did not work, I had to do it manually. use strict; # Not required, but recommended my $DESCRIPTION = << 'DESCRIPTION'; Generates a Media RSS feed containing the album images. If the medium option is used, an additional media stream containing the medium resolution images is made. A link to the PicLens plugin and a link to launch a slide show using the PicLens plugin is added to the album header. DESCRIPTION my $feedFileName = "photos.xml"; my $LRfeedFileName = "photosLR.xml"; sub start_plugin { my ($opt) = @_; my $ret = { author => 'Reidar D. Midtun', href => 'reidar@midtun.dyndns.org', version => '1.0', description => $DESCRIPTION, }; # Options ## Just use the relative URL... album::add_option(1, 'clean_up', album::OPTION_BOOL, default=>0, usage=>"Removes generated xml files"); # Setup the hooks album::hook($opt, 'write_index', \&setup_header); album::hook($opt, 'end_album', \&end_album); return $ret; } sub get_options { my ($opt, $dir) = @_; # Get options my @fields = split('/', $dir); my $n = @fields; my $albumName = @fields[$n-1]; my $medium = album::option($opt, 'medium'); my $clean_up = album::option($opt, 'clean_up'); return ($medium, $albumName, $clean_up); } # Sets up the meta data in the html header # and creates the media rss file sub end_album { my ($opt, $data, $hook, $dir, $album) = @_; my $nPicks = $#{$data->{pics}}; return unless $nPicks > 0; my ($medium, $albumName, $clean_up) = get_options($opt, $dir); create_image_feed($opt,$data, $albumName, $medium, $clean_up); } sub create_image_feed { my ($opt, $data, $albumName, $medium, $clean_up) = @_; my $dir = $data->{paths}{dir}; my $feedFile = "$dir/$feedFileName"; if ($clean_up) { print "Deleting file: $feedFile\n"; unlink($feedFile); $feedFile = "$dir/$LRfeedFileName"; print "Deleting file: $feedFile\n"; unlink($feedFile); } else { my $rss_header = "\n" . "\n" . "\n" . "$albumName\n" . ".\n"; my $rss_footer = "\n" . "\n"; open FEED, ">$feedFile" or die $!; print FEED $rss_header; write_image_items($opt,$data, $dir, 0); print FEED $rss_footer; close FEED; if ($medium) { $feedFile = "$dir/$LRfeedFileName"; open FEED, ">$feedFile" or die $!; print FEED $rss_header; write_image_items($opt, $data, $dir, 1); print FEED $rss_footer; close FEED; } } } sub write_image_items { my ($opt, $data, $dir, $medium) = @_; foreach my $pic ( @{$data->{pics}} ) { my $obj = $data->{obj}{$pic}; next unless $obj->{is_image}; next unless !$obj->{is_movie}; my $thumb = $obj->{URL}{album_page}{thumb}; $thumb =~ s/^'(.*)'$/$1/; # Remove surrounding quotes ## Just use the relative URL... #my $picRef = "$dir/$pic"; my $picRef = $pic; if ($medium) { # Unfortunately we don't have an $obj->{URL}{album_page}{image_src} # (never needed it..) $picRef = $obj->{URL}{image_page}{image_src}; $picRef =~ s/^'(.*)'$/$1/; $picRef = album::option($opt,'dir')."/".$picRef; } my $item = " \n" . " $pic\n" . " $picRef\n" . ##" \n" . " \n" . " \n" . " \n"; print FEED $item; } } # Makes a header file containing a ref to start the slide show sub setup_header { my ($opt, $data, $hook, $dir, $album) = @_; my $nPicks = $#{$data->{pics}}; return unless $nPicks > 0; my ($medium, $albumName, $clean_up) = get_options($opt, $dir); # Updates the html header with a link to the rss feed and definition # of the script launching the slide show. my $meta = " \n"; album::add_head($opt,$data,$meta); my $launchText = " \n" . " \n"; if ($medium) { $launchText = " \n" . " High Resolution or \n" . " \n" . " Low Resolution \n"; } # The html body header is updated with the content of the header.txt file. # We make a link to the PicLens plugin site and a link to launch the slide show. my $header = "
\n" . " \n" . " Use the PicLens plugin to\n" . " start a slide show\n" . " $launchText" . "
\n"; album::add_header($opt,$data,$header); return 0; } # Plugins always end with: 1;