musicstats.phps

<html>
<body>
<?
// musicstats.php
// I don't really remember what it does, but it's something to do with scene mp3-releases stats at least... A whole bunch of you figure it out!
// hellfairy - http://packy.se/
error_reporting(E_ALL);
include '/var/www/timer.php';

function mksize($bytes, $suf=10)
{
  $suffix = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "NB", "DB");
  $pos = 0;
  while ($bytes >= 1024) {
  if ($pos == $suf) { break; }
    $bytes /= 1024;
    $pos++;
  }
  $result=number_format($bytes,2).' '.$suffix[$pos];
  return $result;
}

$start = gettimeofday();
$cfg['dir'] = '/mnt/smb/industrial_electronic_synth_goth';

$tmp = scandir($cfg['dir']);

$num = count($tmp);
for($i=0;$i<$num;$i++)
{
  if(($tmp[$i]!='.'&&$tmp[$i]!='..')&&(is_dir($cfg['dir']."/".$tmp[$i])))
  {
    $group=strtoupper(substr(strrchr($tmp[$i], "-"), 1));
    $rels[$group]++;
    $relstatstmp=scandir($cfg['dir']."/".$tmp[$i]);
    $groupfiles[$group]=$groupfiles[$group]+(count($relstatstmp)-2);
    foreach($relstatstmp as $file)
    {
      if($file!='.'&&$file!='..')
        $groupbytes[$group]=$groupbytes[$group]+filesize($cfg['dir'].'/'.$tmp[$i].'/'.$file);
    }
  }
}

array_multisort($rels, SORT_NUMERIC, SORT_DESC);

$out="contents of <b>".$cfg['dir']."</b><br>\n";
$out.="objects: ".(count($tmp)-2)."<br>\n";
$out.="groups: ".count($rels)."<br>\n";
$out.="size: ".mksize(array_sum($groupbytes),3)."<br><br>\n";

$out.="<table cellspacing=0 cellpadding=4><tr bgcolor=silver><td>group</td><td>releases</td><td>total size</td><td>total files</td></tr>";
foreach(array_keys($rels) as $rel)
{
  $out.="<tr><td>".$rel."</td><td>".$rels[$rel]."</td><td>".mksize($groupbytes[$rel],2)."</td><td>".number_format($groupfiles[$rel])."</td></tr>\n";
}
$out.="</table><br><br>";

$time = function_timer($start, gettimeofday(), 1000, 1);
$out.="time: ".$time."ms";

echo $out;
?>

</body>
</html>