<?php |
include_once '../start.php'; |
require_once('../include/getid3/getid3.php'); |
|
|
function getMp3Info ( $url ){ |
if($url){ |
|
|
$t = microtime(true); |
$tmpname = tempnam('/tmp6','getid3'); |
|
$tmp = fopen($tmpname, 'wb'); |
if (!$tmp) |
return -1; |
|
$source = fopen($url, 'rb'); |
if (!$source) { |
fclose($tmp); |
unlink($tmpname); |
return -2; |
} |
|
$startRead = 32*1024; |
|
|
$lastbites = $startRead; |
while($lastbites > 0 && !feof($tmp) && $frame = fread($source, $lastbites)) { |
fwrite($tmp, $frame); |
$lastbites -= strlen($frame); |
} |
$getID3 = new getID3; |
$getID3->analyze($tmpname); |
|
if (@$getID3->info['id3v2']['tag_offset_end'] > 0 && $getID3->info['id3v2']['tag_offset_end'] > $startRead) { |
$lastbites = intval($getID3->info['id3v2']['tag_offset_start']) + $getID3->info['id3v2']['tag_offset_end'] - $startRead; |
while($lastbites > 0 && !feof($tmp) && $frame = fread($source, $lastbites)) { |
fwrite($tmp, $frame); |
$lastbites -= strlen($frame); |
} |
|
fwrite($tmp, $frame); |
} |
|
$getID3 = new getID3; |
$getID3->analyze($tmpname); |
fclose($tmp); |
fclose($source); |
unlink($tmpname); |
echo microtime(true) - $t; |
return $getID3->info; |
|
} |
} |