$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents('http://getid3.org/demo/test.mp3', false, null, 0, 32768))) {
if (require_once('/path/to/getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
echo '<pre>'.print_r($ThisFileInfo, true).'</pre>';
}
unlink($filename);
}Lenton wrote:What do I need to change in this:
- Code: Select all
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents('http://getid3.org/demo/test.mp3'))) {
if (require_once('/path/to/getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
echo '<pre>'.print_r($ThisFileInfo, true).'</pre>';
}
unlink($filename);
}
to make it download the whole file?
<?php
$remoteFile = 'http://us.php.net/get/php-5.2.10.tar.bz2/from/this/mirror';
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
$contentLength = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
echo 'HTTP Status: ' . $status . "\n";
echo 'Content-Length: ' . $contentLength;
?>Your chunk of code is roughly equivalent to this in the above code examples:Windoves wrote:I found this on the interwebz... The only problem for me is, how do I get the bit rate and calculate the playtime?
file_get_contents('http://getid3.org/demo/test.mp3')<?php
$url='http://getid3.org/demo/test.mp3'; // define the remote mp3 file
if($url){
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents($url, false, null, 0, 300000))) {
if (require_once('getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
}
unlink($filename);
}
}
$bitratez=$ThisFileInfo[audio][bitrate]; // get the bitrate from the audio file
$headers = get_headers($url, 1); // Get the headers from the remote file
if ((!array_key_exists("Content-Length", $headers))) { return false; } // Get the content length from the remote file
$filesize= round($headers["Content-Length"]/1000); // Make the failesize into kilobytes & round it
$contentLengthKBITS=$filesize*8; // make kbytes into kbits
$bitrate=$bitratez/1000; //convert bits/sec to kbit/sec
$seconds=$contentLengthKBITS/$bitrate; // Calculate seconds in song
$playtime_mins = floor($seconds/60); // get the minutes of the playtime string
$playtime_secs = $seconds % 60; // get the seconds for the playtime string
if(strlen($playtime_secs)=='1'){$zero='0';} // if the string is a multiple of 10, we need to add a 0 for visual reasons
$playtime_secs = $zero.$playtime_secs; // add the zero if nessecary
$playtime_string=$playtime_mins.':'.$playtime_secs; // create the playtime string
echo $playtime_string;
?>
Windoves wrote:so I have made a patch for the playtime problem. Code is below:
mrgoe wrote:It gets just the headers, and not the actual "body" of the file. From this we can get the filesize without downloading the whole file.
Return to Support 1.x (resolved)
Users browsing this forum: No registered users and 1 guest