Forum Moderators: coopster

Message Too Old, No Replies

extracting ID3 tags from remote mp3s without complete download

         

formasfunction

3:52 am on Jan 23, 2008 (gmt 0)

10+ Year Member



I have a script that I'm using to extract the ID3 tags from mp3s on a remote server and, being unfamiliar with the nature of fopen, I'd like to know if it's downloading part of the file or the entire file before extraction. I'm only concerned with ID3v2, being that the info is at the beginning of the file, and I'm hoping to grab just the first ~128 of the file. By all appearances testing it on large remote files, it takes a fraction of the time for the tags to appear that it would normally take to download the whole song. Here's the relevant method, taken from [phpclasses.org...]

public function getInfo(){
if ($this->getPath()!= ''){
$mp3 = @fopen($this->getPath(),"r");
$header = @fread($mp3,10);
if (!$header) {
$this->last_error_num = 2;
return false;
die();
}
if (substr($header,0,3)!= "ID3"){
$this->last_error_num = 3;
return false;
die();
}
$header = bin2hex($header);
$version = base_convert(substr($header,6,2),16,10).".".base_convert(substr($header,8,2),16,10);
$flags = base_convert(substr($header,10,2),16,2);
$flags = str_pad($flags,8,0,STR_PAD_LEFT);
if ($flags[7] == 1){
//echo('with Unsynchronisation<br>');
}
if ($flags[6] == 1){
//echo('with Extended header<br>');
}
if ($flags[5] == 1){//Esperimental tag
$this->last_error_num = 4;
return false;
die();
}
$total = $this->get_frame_size(substr($header,12,8));
$text = @fread($mp3,$total);
fclose($mp3);
$this->extractTags($text,$this->_tags);
}
else{
$this->last_error_num = 1;//file not set
return false;
die();
}
return true;
}

vincevincevince

12:17 pm on Jan 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure the link is appropriate. Nevertheless, the code is only reading what it needs.