]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/mpfire/perl/Audio/MPD/Common/Time.pm
Finalized core13 and redirector fixes
[people/pmueller/ipfire-2.x.git] / config / mpfire / perl / Audio / MPD / Common / Time.pm
1 #
2 # This file is part of Audio::MPD::Common
3 # Copyright (c) 2007 Jerome Quelin, all rights reserved.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
7 #
8 #
9
10 package Audio::MPD::Common::Time;
11
12 use warnings;
13 use strict;
14
15 use base qw[ Class::Accessor::Fast ];
16 __PACKAGE__->mk_accessors
17 ( qw[ percent sofar left total
18 sofar_secs sofar_mins seconds_sofar
19 total_secs total_mins seconds_total
20 left_secs left_mins seconds_left
21 ] );
22
23 #our ($VERSION) = '$Rev$' =~ /(\d+)/;
24
25
26 #--
27 # Constructor
28
29 #
30 # my $status = Audio::MPD::Common::Time->new( $time )
31 #
32 # The constructor for the class Audio::MPD::Common::Time. $time is
33 # the time value (on the "time" line) of what the output MPD server
34 # returns to the status command.
35 #
36 sub new {
37 my ($class, $time) = @_;
38 $time ||= '0:0';
39 my ($seconds_sofar, $seconds_total) = split /:/, $time;
40 my $seconds_left = $seconds_total - $seconds_sofar;
41 my $percent = $seconds_total ? 100*$seconds_sofar/$seconds_total : 0;
42
43 # Parse the time so far
44 my $sofar_mins = int( $seconds_sofar / 60 );
45 my $sofar_secs = $seconds_sofar % 60;
46 my $sofar = sprintf "%d:%02d", $sofar_mins, $sofar_secs;
47
48 # Parse the total time
49 my $total_mins = int( $seconds_total / 60 );
50 my $total_secs = $seconds_total % 60;
51 my $total = sprintf "%d:%02d", $total_mins, $total_secs;
52
53 # Parse the time left
54 my $left_mins = int( $seconds_left / 60 );
55 my $left_secs = $seconds_left % 60;
56 my $left = sprintf "%d:%02d", $left_mins, $left_secs;
57
58
59 # create object
60 my $self = {
61 # time elapsed in seconds
62 seconds_sofar => $seconds_sofar,
63 seconds_left => $seconds_left,
64 seconds_total => $seconds_total,
65
66 # cooked values
67 sofar => $sofar,
68 left => $left,
69 total => $total,
70 percent => sprintf("%.1f", $percent), # 1 decimal
71
72 # details
73 sofar_secs => $sofar_secs,
74 sofar_mins => $sofar_mins,
75 total_secs => $total_secs,
76 total_mins => $total_mins,
77 left_secs => $left_secs,
78 left_mins => $left_mins,
79 };
80 bless $self, $class;
81 return $self;
82 }
83
84
85 1;
86
87 __END__
88
89 =head1 NAME
90
91 Audio::MPD::Common::Time - class representing time of current song
92
93
94 =head1 SYNOPSIS
95
96 my $time = $status->time;
97 print $time->sofar;
98
99
100 =head1 DESCRIPTION
101
102 C<Audio::MPD::Common::Status> returns some time information with the C<time()>
103 accessor. This information relates to the elapsed time of the current song,
104 as well as the remaining and total time. This information is encapsulated
105 in an C<Audio::MPD::Common::Time> object.
106
107 Note that an C<Audio::MPD::Common::Time> object does B<not> update itself
108 regularly, and thus should be used immediately.
109
110
111 =head1 METHODS
112
113 =head2 Constructor
114
115 =over 4
116
117 =item new( $time )
118
119 The C<new()> method is the constructor for the C<Audio::MPD::Common::Time>
120 class.
121
122 Note: one should B<never> ever instantiate an C<Audio::MPD::Common::Time>
123 object directly - use the mpd modules instead.
124
125 =back
126
127
128 =head2 Accessors
129
130 Once created, one can access the following members of the object:
131
132 =over 4
133
134 =item cooked values:
135
136 The C<sofar()>, C<left()> and C<total()> methods return the according values
137 under the form C<minutes:seconds>. Note the existence of a C<percent()>
138 method returning a percentage complete. (one decimal)
139
140
141 =item values in seconds:
142
143 The C<seconds_sofar()>, C<seconds_left()> and C<seconds_total()> return the
144 according values in seconds.
145
146
147 =item detailled values:
148
149 If you want to cook your own value, then the following methods can help:
150 C<sofar_secs()> and C<sofar_mins()> return the seconds and minutes elapsed.
151 Same for C<left_secs()> and C<left_mins()> (time remaining), C<total_secs()>
152 and C<total_mins()>. (total song length)
153
154
155 =back
156
157
158 Please note that those accessors are read-only: changing a value will B<not>
159 change the current settings of MPD server. Use the mpd modules to alter the
160 settings.
161
162
163 =head1 SEE ALSO
164
165 =over 4
166
167 =item L<Audio::MPD>
168
169 =item L<POE::Component::Client::MPD>
170
171 =back
172
173
174 =head1 AUTHOR
175
176 Jerome Quelin, C<< <jquelin at cpan.org> >>
177
178
179 =head1 COPYRIGHT & LICENSE
180
181 Copyright (c) 2007 Jerome Quelin, all rights reserved.
182
183 This program is free software; you can redistribute it and/or modify
184 it under the same terms as Perl itself.
185
186 =cut