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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/usr/bin/perl
#===============================================================================
#
# FILE: mpd.pl
#
# USAGE: ./mpd.pl
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Raghavendra Prabhu (),
# COMPANY:
# VERSION: 1.0
# CREATED: 07/17/2010 05:06:23 PM
# REVISION: ---
#===============================================================================
#use strict;
#use warnings;
use Data::Dumper;
use Encode 'decode_utf8';
use Term::ANSIColor qw(:constants);
my $query;
$Term::ANSIColor::AUTORESET = 1;
if ($#ARGV < 0){
print STDERR "Assuming album as the query and mtime as the sorter\n";
$query='Album';
#die "Supply one of the query strings: $!\n";
}
else{
$query=$ARGV[0];
}
my $sorter = 'mtime';
my %bucket=();
my $mpd="~/.mpd/mpd.db";
open(FH,'<',glob($mpd)) or die "Opening failed: $!";
#{{{
sub strip {
@temp=split /:/,$_[0];
chomp @temp;
$temp[1]=~ s/^\s+//;
return $temp[1];
}
sub sortb{
my @current=();
my $key;
my $predicate = $_[0];
while(<FH>){
if(/^$predicate/../^$sorter/){
if (/^$predicate/) {
@current=();
push(@current,strip $_);
}
elsif (/^$sorter/){
$key = strip $_;
#if ($query eq "Artist"){
$bucket{$predicate}->{$key}=join " | ",@current[0..2];
#}
#else{
#$bucket{$predicate}->{$key}=join " | ",@current[0,3];
#}
}
else
{
push(@current,strip $_);
}
}
}
}
#}}}
sortb($query,$sorter);
close(FH);
my $hash = $bucket{$query};
my @tmp;
my %dup;
foreach my $key (sort {$a <=> $b} (keys %$hash)){
#print $bucket{$query}->{$key}."\n";
#next;
@tmp = split / | /, $bucket{$query}->{$key};
#print @tmp[0];
if (!defined $dup{$tmp[0]}) { print "\n\n Added on ".localtime($key)."\n"; $dup{$tmp[0]} = 1; }
print BLUE "@tmp\n";
#print BLUE @tmp[0];
#print join " ",@tmp[1..$#tmp]."\n";
}
|