View file dcsiza/mp3info.php

File size: 4.71Kb
<?php
////////////////////////////////////////////////////////////////////////////
//                                                                        //
//         Автор скрипта: Корнилов Александр Евгеньевич aka GrOb          //
//                E-mail: [email protected]                                   //
//              WAP SAIT: http://grob.com.ru                              //
//                                                                        //
////////////////////////////////////////////////////////////////////////////
function formattime($time) {

        $hours = floor(($time/60)/60);
        $minutes = floor(($time / 60)-($hours*60));
        $seconds = floor($time - (($minutes * 60)+(($hours*60)*60)));
        if ($seconds<10) {$seconds="0".$seconds;}
        if ($minutes<10) {$minutes="0".$minutes;}
        if ($hours!=0) {
                if ($hours<10) {
                       $hours="0".$hours;
                }
                return $hours.':'.$minutes.':'.$seconds.conv;
        }
        else {
                return $minutes.':'.$seconds;
        }
}
function bitrate1($mysting)
{
        $mysting=str_replace(0x10,32,$mysting);
        $mysting=str_replace(0x20,40,$mysting);
        $mysting=str_replace(0x30,48,$mysting);
        $mysting=str_replace(0x40,56,$mysting);
        $mysting=str_replace(0x50,64,$mysting);
        $mysting=str_replace(0x60,80,$mysting);
        $mysting=str_replace(0x70,96,$mysting);
        $mysting=str_replace(0x80,112,$mysting);
        $mysting=str_replace(0x90,128,$mysting);
        $mysting=str_replace(0xA0,160,$mysting);
        $mysting=str_replace(0xB0,192,$mysting);
        $mysting=str_replace(0xC0,224,$mysting);
        $mysting=str_replace(0xD0,256,$mysting);
        $mysting=str_replace(0xE0,320,$mysting);
        return $mysting;
}
function bitrate2($mysting)
{
        $mysting=str_replace(0x10,8,$mysting);
        $mysting=str_replace(0x20,16,$mysting);
        $mysting=str_replace(0x30,24,$mysting);
        $mysting=str_replace(0x40,32,$mysting);
        $mysting=str_replace(0x50,40,$mysting);
        $mysting=str_replace(0x60,48,$mysting);
        $mysting=str_replace(0x70,56,$mysting);
        $mysting=str_replace(0x80,64,$mysting);
        $mysting=str_replace(0x90,80,$mysting);
        $mysting=str_replace(0xA0,96,$mysting);
        $mysting=str_replace(0xB0,112,$mysting);
        $mysting=str_replace(0xC0,128,$mysting);
        $mysting=str_replace(0xD0,144,$mysting);
        $mysting=str_replace(0xE0,160,$mysting);
        return $mysting;
}
function freq1($mysting)
{
        $mysting=str_replace(0x00,44.1,$mysting);
        $mysting=str_replace(0x04,48,$mysting);
        $mysting=str_replace(0x08,32,$mysting);

        return $mysting;
}
function freq2($mysting)
{
        $mysting=str_replace(0x00,22.05,$mysting);
        $mysting=str_replace(0x04,24,$mysting);
        $mysting=str_replace(0x08,16,$mysting);

        return $mysting;
}
function misc($mysting)
{
        $mysting=str_replace(0x00,'Стерео',$mysting);
        $mysting=str_replace(0x40,'Стерео',$mysting);
        $mysting=str_replace(0x60,'Двухканальный',$mysting);
        $mysting=str_replace(0x80,'Моно',$mysting);
        return $mysting;
}
function getinfo($filename) {
                $done=false;
                $file=fopen("$filename","r");
                $point=0;
                while ((!feof($file)) and (!$done)){
                        fseek($file, $point);
                        $data=fread($file,2);
                        $data=unpack ("Cint/Cint2",$data);
                        if (($data[int] == 0xFF) and ($data[int2] < 0xFF) and ($data[int2]>=0xF0)) {
                                $done=true;
                                $id3=$point;
                        }
                $point++;
                }
        $filesize=filesize($filename);
        $filesize=$filesize - $id3;
        fseek($file, $id3);
        $bindata = fread($file, 4);
        fclose($file);
        if(! ($bindata = unpack('nint/C2', $bindata)) ) return false;
        if (($bindata[int] & 0xFFF0) != 0xFFF0) return false;
        if (($bindata[int] & 0x08) == 0x08) {
                $info[bitrate] = bitrate1($bindata[1] & 0xF0);
                $info[frequency] = freq1($bindata[1] & 0x0C);
                $info[stereo] = misc($bindata[2] & 0xC0);
                $info[time] = ($filesize / (bitrate1($bindata[1] & 0xF0) * 1000 / 8));
        }

        if (($bindata[int] & 0x08) == 0x00) {
                $info[bitrate] = bitrate2($bindata[1] & 0xF0);
                $info[frequency] = freq2($bindata[1] & 0x0C);
                $info[stereo] = misc($bindata[2] & 0xC0);
                $info[time] = $filesize / (bitrate2($bindata[1] & 0xF0) * 1000 / 8);
        }

        return $info;
        }
?>