141 |
&showVersion(); |
&showVersion(); |
142 |
exit; |
exit; |
143 |
} |
} |
144 |
|
if ( $SHOW_STATS ) |
145 |
|
{ |
146 |
|
&showStats( $cache ); |
147 |
|
exit; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
# |
# |
180 |
# |
# |
181 |
find({ wanted => \&findAudio, follow => 1 }, $root); |
find({ wanted => \&findAudio, follow => 1 }, $root); |
182 |
|
|
|
# |
|
|
# Show statistics if that's all the user wants. |
|
|
if ( $SHOW_STATS ) |
|
|
{ |
|
|
&showStats(); |
|
|
&removeLock(); |
|
|
exit; |
|
|
} |
|
|
|
|
183 |
|
|
184 |
# |
# |
185 |
# Process the list of found files. |
# Process the list of found files. |
209 |
|
|
210 |
|
|
211 |
# |
# |
212 |
# Show the number of files found, and their total size. |
# Show the number of files we have indexed, their total size, and |
213 |
|
# the total playlength. |
214 |
# |
# |
215 |
sub showStats( ) |
sub showStats( $ ) |
216 |
{ |
{ |
217 |
my $sizeTotal = 0; |
my ( $file ) = (@_); |
218 |
my $fileTotal = $#FOUND + 1; |
my $COUNT = 0; |
219 |
|
my $SIZE = 0; |
220 |
my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ); |
my $TIME = "0"; |
221 |
|
|
222 |
# |
my %DETAILS = ( ); |
223 |
# Work with the global list of found files. |
|
224 |
foreach my $file ( sort @FOUND ) |
if ( ! -e $file ) |
225 |
{ |
{ |
226 |
# Read the file information. |
print "Stats could not be displayed as the cache file doesnt exist"; |
227 |
( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat( $file ); |
print "The cache file we expect is $file\n"; |
228 |
|
exit; |
229 |
# Increase the running total of sizes. |
} |
230 |
$sizeTotal += $size; |
|
231 |
} |
open( FILY, "<$file" ); |
232 |
|
|
233 |
# |
foreach (<FILY>) |
234 |
# Make the size a human readable number without too much precision. |
{ |
235 |
$sizeTotal = $sizeTotal < (1024) ? |
chomp; |
236 |
$sizeTotal . " bytes" : ( |
my @NAMES = split( /\t/, $_); |
237 |
$sizeTotal < (1024 ** 2) ? |
my $file = shift(@NAMES); |
238 |
(int (10 * $sizeTotal/1024)/10) . "K" : ( |
$DETAILS{$file} = \@NAMES; |
239 |
$sizeTotal < (1024 ** 3) ? |
} |
240 |
(int (10 * $sizeTotal/(1024 ** 2) )/10) . "MB" : |
close( FILY ); |
241 |
((int (10 * $sizeTotal/(1024 ** 3) )/10) . "GB"))); |
|
242 |
|
# |
243 |
# |
# Process the hash. |
244 |
# All done - print the results. |
# Add up song times. |
245 |
print "Beneath $root there are:\n"; |
# Add up total song size. |
246 |
print "$fileTotal audio files - totalling $sizeTotal.\n"; |
# |
247 |
|
foreach my $file ( keys %DETAILS ) |
248 |
|
{ |
249 |
|
my $details = $DETAILS{$file}; |
250 |
|
|
251 |
|
# A new line == A new file in archive. |
252 |
|
$COUNT ++; |
253 |
|
|
254 |
|
foreach my $pair ( @$details ) |
255 |
|
{ |
256 |
|
if ( ( $pair =~ /([A-Z]+)=(.*)/ ) && |
257 |
|
( length( $2 ) ) ) |
258 |
|
{ |
259 |
|
my $key = $1; |
260 |
|
my $val = $2; |
261 |
|
|
262 |
|
if ( $key eq "SIZE" ) |
263 |
|
{ |
264 |
|
$SIZE += $val; |
265 |
|
} |
266 |
|
if ( $key eq "LENGTH" ) |
267 |
|
{ |
268 |
|
if ( $val =~ /([0-9]+):([0-9]+):([0-9]+)/ ) |
269 |
|
{ |
270 |
|
$TIME += $3 + ($2 * 60 ) + ($1 * 60 * 60 ); |
271 |
|
} |
272 |
|
elsif( $val =~ /([0-9]+):([0-9]+)/ ) |
273 |
|
{ |
274 |
|
$TIME += $2 + ($1 * 60 ) |
275 |
|
} |
276 |
|
} |
277 |
|
} |
278 |
|
} |
279 |
|
} |
280 |
|
|
281 |
|
# |
282 |
|
# Fudge the size |
283 |
|
my $sizeTotal = $SIZE; |
284 |
|
$sizeTotal = $sizeTotal < (1024) ? |
285 |
|
$sizeTotal . " bytes" : ( |
286 |
|
$sizeTotal < (1024 ** 2) ? |
287 |
|
(int (10 * $sizeTotal/1024)/10) . "K" : ( |
288 |
|
$sizeTotal < (1024 ** 3) ? |
289 |
|
(int (10 * $sizeTotal/(1024 ** 2) )/10) . "Mb" : |
290 |
|
((int (10 * $sizeTotal/(1024 ** 3) )/10) . "Gb"))); |
291 |
|
|
292 |
|
|
293 |
|
# |
294 |
|
# Fudge the time. |
295 |
|
# |
296 |
|
my $foo = ""; |
297 |
|
|
298 |
|
$foo .= int($TIME/(24*60*60)) . " days, "; |
299 |
|
$foo .= ($TIME/(60*60))%24 . " hours, "; |
300 |
|
$foo .= ($TIME/60)%60 . " mins "; |
301 |
|
$foo .= $TIME%60 . " seconds"; |
302 |
|
|
303 |
|
$TIME = $foo; |
304 |
|
|
305 |
|
|
306 |
|
# |
307 |
|
# Print the results |
308 |
|
# |
309 |
|
print <<E_O_INFO; |
310 |
|
Total number of songs: $COUNT |
311 |
|
Total size of archive: $sizeTotal ($SIZE bytes) |
312 |
|
Total playlength : $TIME |
313 |
|
E_O_INFO |
314 |
|
|
315 |
} |
} |
316 |
|
|