# Album Plugin:	captions/format/video_tag
# For info:	'album -plugin_info captions/format/video_tag'
# For usage:	'album -plugin_usage captions/format/video_tag'
use strict;

sub start_plugin {
  my ($opt,$plugin,$path) = @_;

  # Setup my hooks
  album::hook($opt,'modify_caption',\&modify_caption);
  album::add_option(1,'size',$album::OPTION_BOOL, default=>1, usage=>"Do we specify disk size?");

  return {
    author => 'David Ljung Madison',
    href => 'http://MarginalHacks.com/',
    version => '1.0',
    description =>
"Video tagger

Adds tags to video captions like:   '[Video, 26M]'

You can change whether size is shown with the option -video_tag:size"
  };
}

# What's the filesize of a file?  (String format)
sub filesize($) {
	my ($file) = @_;
	my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
		$atime,$mtime,$ctime,$blksize,$blocks) = stat($file);
	$size=int($size/102.4)/10;
	$size=int($size) if ($size>10);
	return "${size}k" if ($size<1024);
	$size=int($size/102.4)/10;
	return "${size}M" if ($size<1024);
	$size=int($size/102.4)/10;
	"${size}G";
}


sub modify_caption {
  my ($opt, $data, $hookname, $cap, $dir, $pic) = @_;

	my $size = album::option($opt,'size');

	return unless album::is_movie($opt,$pic);
	return if $cap =~ /\[Video/;	# Don't do anything if it already has a [Video] tag
  # The new caption with the paypal button
	"$cap [Video, ".filesize("$dir/$pic")."]";
}

# Plugins always end with:
1;
