$this->error="Nosuchfile";
if($exitonerror)$this->exitonerror();
}
}
functionexitonerror(){
echo($this->error);
exit;
}
functionset_id3($title="",$author="",$album="",$year="",$comment="",$genre_id=0){
$this->error=false;
$this->wfh=fopen($this->file,"a");
fseek($this->wfh,-128,SEEK_END);
fwrite($this->wfh,pack("a3a30a30a30a4a30C1","TAG",$title,$author,$album,$year,$comment,$genre_id),128);
fclose($this->wfh);
}
functionget_id3(){
$this->id3_parsed=true;
fseek($this->fh,-128,SEEK_END);
$line=fread($this->fh,10000);
if(preg_match("/^TAG/",$line)){
$this->id3=unpack("a3tag/a30title/a30author/a30album/a4year/a30comment/C1genre_id",$line);
$this->id3["genre"]=$this->id3_genres_array[$this->id3]["genre_id"]];
return(true);
}else{
$this->error="noidv3tagfound";
return(false);
}
}
//get_info()helpermethods
functioncalculate_length($id3v2_tagsize=0){
$length=floor(($this->info["filesize"]-$id3v2_tagsize)/$this->info["bitrate"]*0.008);
$min=floor($length/60);
$min=strlen($min)==1?"0$min":$min;
$sec=$length`;
$sec=strlen($sec)==1?"0$sec":$sec;
return("$min:$sec");
}
functionget_info(){
// $this->get_id3v2header();
$second=$this->synchronize();
// echo("2ndbyte=$second<b>".decbin($second)."</b><br>");
$third=ord(fread($this->fh,1));
$fourth=ord(fread($this->fh,1));
$this->info["version_id"]=($second&16)>0?(($second&8)>0?1:2):(($second&8)>0?0:2.5);
$this->info["version"]=$this->info_versions[$this->info]["version_id"]];
$this->info["layer_id"]=($second&4)>0?(($second&2)>0?1:2):(($second&2)>0?3:0); ;
$this->info["layer"]=$this->info_layers[$this->info]["layer_id"]];
$this->info["protection"]=($second&1)>0?"noCRC":"CRC";
$this->info["bitrate"]=$this->info_bitrates[$this->info]["version_id"]][$this->info]["layer_id"]][($third&240)];
$this->info["sampling_rate"]=$this->info_sampling_rates[$this->info]["version_id"]][($third&12)];
if($exitonerror)$this->exitonerror();
}
}
functionexitonerror(){
echo($this->error);
exit;
}
functionset_id3($title="",$author="",$album="",$year="",$comment="",$genre_id=0){
$this->error=false;
$this->wfh=fopen($this->file,"a");
fseek($this->wfh,-128,SEEK_END);
fwrite($this->wfh,pack("a3a30a30a30a4a30C1","TAG",$title,$author,$album,$year,$comment,$genre_id),128);
fclose($this->wfh);
}
functionget_id3(){
$this->id3_parsed=true;
fseek($this->fh,-128,SEEK_END);
$line=fread($this->fh,10000);
if(preg_match("/^TAG/",$line)){
$this->id3=unpack("a3tag/a30title/a30author/a30album/a4year/a30comment/C1genre_id",$line);
$this->id3["genre"]=$this->id3_genres_array[$this->id3]["genre_id"]];
return(true);
}else{
$this->error="noidv3tagfound";
return(false);
}
}
//get_info()helpermethods
functioncalculate_length($id3v2_tagsize=0){
$length=floor(($this->info["filesize"]-$id3v2_tagsize)/$this->info["bitrate"]*0.008);
$min=floor($length/60);
$min=strlen($min)==1?"0$min":$min;
$sec=$length`;
$sec=strlen($sec)==1?"0$sec":$sec;
return("$min:$sec");
}
functionget_info(){
// $this->get_id3v2header();
$second=$this->synchronize();
// echo("2ndbyte=$second<b>".decbin($second)."</b><br>");
$third=ord(fread($this->fh,1));
$fourth=ord(fread($this->fh,1));
$this->info["version_id"]=($second&16)>0?(($second&8)>0?1:2):(($second&8)>0?0:2.5);
$this->info["version"]=$this->info_versions[$this->info]["version_id"]];
$this->info["layer_id"]=($second&4)>0?(($second&2)>0?1:2):(($second&2)>0?3:0); ;
$this->info["layer"]=$this->info_layers[$this->info]["layer_id"]];
$this->info["protection"]=($second&1)>0?"noCRC":"CRC";
$this->info["bitrate"]=$this->info_bitrates[$this->info]["version_id"]][$this->info]["layer_id"]][($third&240)];
$this->info["sampling_rate"]=$this->info_sampling_rates[$this->info]["version_id"]][($third&12)];