-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
np
executable file
·45 lines (33 loc) · 975 Bytes
/
np
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
# abstract: mpd now playing
use strict;
use Audio::MPD;
use Getopt::Long;
use File::LsColor qw(ls_color);
use feature 'say';
binmode STDOUT, ':utf8';
my %opt;
GetOptions(\%opt,
'np' => scalar @ARGV,
'f|file' => \$opt{file},
'p|path' => \$opt{path},
);
my $m = Audio::MPD->new;
my $c = $m->current;
my $file = $c->file;
my ($basedir) = $file =~ m{(.+)/\S+};
# /mnt/music8/+TAGGED//0-9/50 Cent/+albums/50 Cent │2007│ Curtis [CD, FLAC]
my $abs_dir = sprintf "%s/%s", $ENV{XDG_MUSIC_DIR}, $basedir;
$opt{file} and say $c->file and exit;
$opt{path} and say ls_color($abs_dir), "\n\ncd ", quotemeta($abs_dir) and exit;
my $out;
if(!$c->artist) {
$out = sprintf("np> %s (no id3)",$c->file);
}
else {
$out = sprintf("np> %s: %s (%s) \@ %skbps \{%s\} [%s]",
$c->artist, $c->title, $c->album, $m->status->bitrate,
$c->genre, $c->date);
}
print $out, "\n";
system("printf \"$out\"|xclip");