# 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";
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 = "