#!/usr/bin/perl 

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell
#
# This file is part of Audio-MPD
#
# This software is copyright (c) 2007 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#

use 5.010;
use strict;
use warnings;

package main;
BEGIN {
  $main::VERSION = '1.110560';
}
#ABSTRACT: rate your songs for mpd-dynamic

use Audio::MPD;
use DB_File;
use Encode;
use Getopt::Euclid qw{ :minimal_keys };

# fetch current song
my $song = encode( 'utf-8', Audio::MPD->new->current->file );

# open ratings file
my %ratings;
tie %ratings, 'DB_File', $ARGV{ratings}, O_RDWR|O_CREAT, oct(666), $DB_HASH
    or die "$ARGV{ratings}: $!";

# update rating or print it
if ( defined $ARGV{rating} ) { $ratings{$song} = $ARGV{rating}; }
else { say exists $ratings{$song} ? $ratings{$song} : 0; }

untie %ratings;




=pod

=head1 NAME

main - rate your songs for mpd-dynamic

=head1 VERSION

version 1.110560

=head1 DESCRIPTION

This program allows you to rate your songs, to allow mpd-dynamic to use ratings.

=head1 USAGE

    mpd-rate [options]

=head1 OPTIONS

You can customize the usage of mpd-dynamic with the following options:

=over 4

=item -r[atings] <ratings>

The path of a db file with the ratings per song. The keys are the song path
(relative to MPD root), and the value is an integer (the rating). Default to
C<~/.mpd/ratings.db>.

=for Euclid: ratings.type:     writable
    ratings.default:  "$ENV{HOME}/.mpd/ratings.db"

=item <rating>

The rating you want to apply to the current song. If not supplied, will
print its current rating.

=for Euclid: rating.type:    integer

=item --version

=item --usage

=item --help

=item --man

Print the usual program information

=back

=head1 AUTHOR

Jerome Quelin, C<< <jquelin@cpan.org> >>

=head1 COPYRIGHT & LICENSE

Copyright (c) 2010 Jerome Quelin, all rights reserved.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Jerome Quelin

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2007 by Jerome Quelin.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut


__END__

