Debian Codegraph @

bin/mpd-rate

raw
1 #!/usr/bin/perl
2 #
3 # This file is part of Audio-MPD
4 #
5 # This software is copyright (c) 2007 by Jerome Quelin.
6 #
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 #
10
11 use 5.010;
12 use strict;
13 use warnings;
14
15 # PODNAME: mpd-rate;
16 # ABSTRACT: rate your songs for mpd-dynamic
17
18 use Audio::MPD;
19 use DB_File;
20 use Encode;
21 use Getopt::Euclid qw{ :minimal_keys };
22
23 # fetch current song
24 my $playing = Audio::MPD->new->current;
25 unless (defined $playing)
26 {
27 die "Cannot rate current song, as no song currently is playing!";
28 }
29 my $song = encode( 'utf-8', $playing->file );
30
31 # open ratings file
32 my %ratings;
33 tie %ratings, 'DB_File', $ARGV{ratings}, O_RDWR|O_CREAT, oct(666), $DB_HASH
34 or die "$ARGV{ratings}: $!";
35
36 # update rating or print it
37 if ( defined $ARGV{rating} ) { $ratings{$song} = $ARGV{rating}; }
38 else { say exists $ratings{$song} ? $ratings{$song} : 0; }
39
40 untie %ratings;
41
42 __END__
43
44 =pod
45
46 =head1 NAME
47
48 mpd-rate; - rate your songs for mpd-dynamic
49
50 =head1 VERSION
51
52 version 2.004
53
54 =head1 DESCRIPTION
55
56 This program allows you to rate your songs, to allow mpd-dynamic to use ratings.
57
58 =head1 USAGE
59
60 mpd-rate [options]
61
62 =head1 OPTIONS
63
64 You can customize the usage of mpd-dynamic with the following options:
65
66 =over 4
67
68 =item -r[atings] <ratings>
69
70 The path of a db file with the ratings per song. The keys are the song path
71 (relative to MPD root), and the value is an integer (the rating). Default to
72 C<~/.mpd/ratings.db>.
73
74 =for Euclid: ratings.type: writable
75 ratings.default: "$ENV{HOME}/.mpd/ratings.db"
76
77 =item <rating>
78
79 The rating you want to apply to the current song. If not supplied, will
80 print its current rating.
81
82 =for Euclid: rating.type: integer
83
84 =item --version
85
86 =item --usage
87
88 =item --help
89
90 =item --man
91
92 Print the usual program information
93
94 =back
95
96 =head1 AUTHOR
97
98 Jerome Quelin
99
100 =head1 COPYRIGHT AND LICENSE
101
102 This software is copyright (c) 2007 by Jerome Quelin.
103
104 This is free software; you can redistribute it and/or modify it under
105 the same terms as the Perl 5 programming language system itself.
106
107 =cut