use File::Basename;

$plugin_purpose{'info-firstdash'} =
  "Retrieve meta data from strings formated as PERFORMER - TITLE";
$plugin_options{'info-firstdash'} = [
  ['forcefile', 'Force to use file name as source of meta data'],
  ['forcetitle', 'Force to use title flag as source of meta data']];

push(@info_plugin_hook, sub {
    my ($ti, $langs) = @_;
    my $use_title = !$plugin{'info-firstdash'}{forcefile} &&
      ($plugin{'info-firstdash'}{forcetitle} ||
	  (defined $ti->{TITLE} && $ti->{TITLE}->[0] =~ /-/));
    track_info_ensure_defined($ti, qw(TITLE PERFORMER));
    for my $nl(0..$#$langs) {
	my $s = undef;
	if ($use_title) {
	    $s = $ti->{TITLE}->[$nl];
	} else {
	    $s = basename($ti->{FILE});
	    $s =~ s/\.\w+$//;
	    $s =~ s/_/ /g;
	}

	if ($s =~ /^(.*?)\s*-\s*(.*)$/) {
	    $ti->{PERFORMER}->[$nl] = $1;
	    $ti->{TITLE}->[$nl] = $2;
	}
    }
});

1;

# vim:ft=perl
