Pimpd/Info.pm untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 150 CC 11 SCAR 26.2
CC
11
Cov
0%
info
42.0
_on_off
12.0
_current_update
6.0
CRAP 13.8
1 package App::Pimpd::Info;
2 use strict;
3  
4 BEGIN {
5 use Exporter;
6 use vars qw(@ISA @EXPORT);
7 @ISA = qw(Exporter);
8 @EXPORT = qw(
9 current
10 info
11 status
12 stats
13 );
14 }
15  
16 use App::Pimpd;
17 use App::Pimpd::Validate;
18 use Term::ExtendedColor qw(fg clear);
19 use File::LsColor qw(ls_color);
20 use Time::Duration;
21  
22 # FIXME
23 #get_color_support();
24  
25  
26 my(%current, %status, ,%stats);
27  
28 sub _current_update {
29 if($mpd->status->state ne 'stop') {
30 %current = (
31 'artist' => $mpd->current->artist // 'N/A',
32 'album' => $mpd->current->album // 'N/A',
33 'title' => $mpd->current->title // 'N/A',
34 'genre' => $mpd->current->genre // 'N/A',
35 'file' => $mpd->current->file // 'N/A',
36 'date' => $mpd->current->date // 'N/A',
37 'time' => $mpd->status->time->sofar.'/'.
38 $mpd->status->time->total,
39 'bitrate' => $mpd->status->bitrate // 'N/A',
40 'audio' => $mpd->status->audio // 'N/A',
41 );
42 %status = (
43 'repeat' => _on_off( $mpd->status->repeat ),
44 'shuffle' => _on_off( $mpd->status->random ),
45 'xfade' => _on_off( $mpd->status->xfade ),
46 'volume' => $mpd->status->volume,
47 'state' => $mpd->status->state,
48 'list' => $mpd->status->playlist,
49 );
50 %stats = (
51 'song' => $mpd->status->song,
52 'length' => $mpd->status->playlistlength,
53 'songs' => $mpd->stats->songs,
54 'albums' => $mpd->stats->albums,
55 'artists' => $mpd->stats->artists,
56 );
57 }
58 return;
59 }
60  
61 sub current {
62 _current_update();
63  
64 my $output;
65 if(to_terminal()) {
66 $output = sprintf("%s - %s on %s from %s [%s]",
67 fg($c[3], fg('bold', $current{artist})),
68 fg($c[11], $current{title}),
69 fg($c[0], $current{album}),
70 fg($c[4], fg('bold', $current{date})),
71 $current{genre},
72 );
73 }
74 else {
75 $output = sprintf("%s - %s on %s from %s [%s]",
76 $current{artist},
77 $current{title},
78 $current{album},
79 $current{date},
80 $current{genre},
81 );
82 }
83  
84 return $output;
85 }
86  
87 sub info {
88 (undef,undef,undef,undef,undef, my $crnt_year) = localtime(time);
89 $crnt_year += 1900;
90  
91 _current_update();
92  
93 for(keys(%current)) {
94 $current{$_} = fg($c[14], 'N/A') if(!defined($current{$_}));
95 }
96  
97 $status{'state'} = 'Playing' if($status{'state'} eq 'play');
98 $status{'state'} = 'Paused' if($status{'state'} eq 'pause');
99 $status{'state'} = 'Stopped' if($status{'state'} eq 'stop');
100  
101 if($status{volume} < 0) {
102 $status{volume} = 'N/A (Software Mixer)';
103 }
104  
105  
106 printf("%s %8s: %.66s\n", fg('bold', fg('251', 'S')),
107 'Artist', fg($c[3], fg('bold', $current{artist}))
108 );
109 printf("%s %8s: %.66s\n", fg('bold', fg('250', 'O')),
110 'Album', fg($c[0], $current{album})
111 );
112 printf("%s %8s: %.66s\n", fg('bold', fg('249', 'N')),
113 'Song', fg($c[11], fg('bold', $current{title}))
114 );
115  
116 printf("%s %8s: %.66s\n", fg('bold', fg(248, 'G')),
117 'Genre', fg($c[13], $current{genre})
118 );
119 printf("%s %9s: %s\n",'', 'File', ls_color($current{file}));
120  
121 printf("%s %8s: %.66s\n", fg('bold', fg('247', 'I')),
122 'Date', $current{date}
123 );
124 printf("%s %8s: %.66s\n", fg('bold', fg('246', 'N')),
125 'Time', $current{time}
126 );
127 printf("%s %8s: %.66s\n", fg('bold', fg('245', 'F')),
128 'Bitrate', $current{bitrate}
129 );
130 printf("%s %8s: %.66s\n", fg('bold', fg('244', 'O')),
131 'Audio', $current{audio}
132 );
133  
134 print fg($c[15]);
135 print '-' x 25, clear(), "\n";
136  
137 printf("%s %8s: %.66s\n", fg('bold', fg('243', 'S')),
138 'Repeat', $status{repeat}
139 );
140 printf("%s %8s: %.66s\n", fg('bold', fg('242', 'T')),
141 'Shuffle', $status{shuffle}
142 );
143 printf("%s %8s: %.66s\n", fg('bold', fg('242', 'A')),
144 'Xfade', $status{xfade}
145 );
146 printf("%s %8s: %.66s\n", fg('bold', fg('241', 'T')),
147 'Volume', $status{volume}
148 );
149 printf("%s %8s: %.66s\n", fg('bold', fg('240', 'U')),
150 'State', $status{state}
151 );
152 printf("%s %8s: %.66s\n", fg('bold', fg('239', 'S')),
153 'List V', $status{list}
154 );
155  
156 print fg($c[15]);
157 print '-' x 25, clear(), "\n";
158  
159 printf("%s %8s: %.66s\n", fg('bold', fg('238', 'S')),
160 'Song', $stats{song}
161 );
162 printf("%s %8s: %.66s\n", fg('bold', fg('237', 'T')),
163 'List', $stats{length} . ' songs'
164 );
165 printf("%s %8s: %.66s\n", fg('bold', fg('236', 'A')),
166 'Songs', $stats{songs}
167 );
168 printf("%s %8s: %.66s\n", fg('bold', fg('235', 'T')),
169 'Albums', $stats{albums}
170 );
171 printf("%s %8s: %.66s\n", fg('bold', fg('234', 'S')),
172 'Artists', $stats{artists}
173 );
174 return;
175 }
176  
177 sub _on_off {
178 my $state = shift;
179  
180 if($state > 1) {
181 return "ON ($state)";
182 }
183 elsif($state == 1) {
184 return 'ON';
185 }
186 return 'OFF';
187 }
188  
189 sub stats {
190 my $friendly_names = {
191 artists => 'Artists',
192 albums => 'Albums',
193 songs => 'Songs',
194  
195 uptime => 'Uptime',
196 playtime => 'Play time',
197 db_playtime => 'DB Play Time',
198 };
199  
200 my $status = $mpd->stats;
201  
202 for(qw(artists albums songs)) {
203 printf("%15s: %s\n", $friendly_names->{$_}, $status->$_);
204 }
205  
206 print "\n";
207  
208 for my $time(qw(uptime playtime db_playtime)) {
209 printf("%15s: %s\n", $friendly_names->{$time}, duration( $status->$time ));
210 }
211  
212 printf("%15s: %s\n", 'DB Updated', scalar localtime( $status->db_update ));
213 return;
214 }
215  
216 sub status {
217 my $friendly_names = {
218 play => 'playing',
219 pause => 'paused',
220 stop => 'stopped',
221 };
222  
223 my $status = $mpd->status;
224  
225 return $friendly_names->{ $status->state }
226 ? $friendly_names->{ $status->state }
227 : ''
228 }
229  
230  
231  
232  
233 1;
234  
235 __END__