note 71191 added to ref.id3

From: Date: Wed, 15 Nov 2006 19:58:28 +0000
Subject: note 71191 added to ref.id3
Groups: php.notes 
Request: Send a blank email to php-notes+get-119757@lists.php.net to get a copy of this message
Windows XP users may be having trouble with routines provided here and may (as above) only have access to "read" classes. The following very simplified "write" can be used for replacing Windows Media Player file tags, and with care and adjustments, can be used more generally. define(_Title,"TIT2"); define(_Artist,"TPE1"); define(_Group,"TPE2"); define(_Album,"TALB"); define(_Genre,"TCON"); define(_TrackNo,"TRCK"); define(_Year,"TYER"); $frames = array(_Album=>"The Ultimate Experience", _TrackNo=>"1", _Title=>"All along the watchtower", _Artist=>"Jimi Hendrix", _Group=>"", _Year=>"19xx", _Genre=>"Rock"); #.......................................... # WRITE ID3 TAGS (Write MP3 [v1, v2] #.......................................... function writeTags($mp3) { $fl = file_get_contents($mp3); $Header = substr($fl,0,10); $tagLen = calcDecTagLen(substr($Header,6,4),$tagLen); $music = substr($fl,$tagLen+10,-128); # Can use input Header for output but you may # wish to change the output filename for testing file_put_contents($mp3,mkV2Tag($Header,$tagLen).$music.mkV1Tag()); } # Create the V2 tag function mkV2Tag($Hdr,$tagLen) { Global $frames; $null = chr(0); $nl3 = $null.$null.$null; # 0 bytes for flags and encoding $out = ""; foreach($frames as $ky=>$val) { $n=strlen($val)+1; $out.= $ky.mkFrmLen($n).$nl3.$val; } return $Hdr.str_pad($out,$tagLen,$null); } # Calculate Tag Length from bytes 6-10 of existing header function calcDecTagLen($word) { $m = 1; $int = 0; for ($i=strlen($word)-1;$i>-1;$i--) { $int +=$m*ord($word[$i]); $m=$m*128; } return $int; } # Make the 4 byte frame length value for the V2tag function mkFrmLen($int) { $hx = ""; while ($int>0) { $n = $int % 256; $hx = chr($n).$hx; $int=floor($int/256); } return str_pad($hx,4,chr(0),STR_PAD_LEFT); } # Create the 128 byte V1 tag function mkV1Tag() { Global $frames; $tagOut = "TAG". adj($frames[_Title]). adj($frames[_Artist]). adj($frames[_Album]). str_pad($frames[_Year],4). str_pad(" ",29," "). chr($frames[_TrackNo]). chr($n); return $tagOut; } # Pad the header to 30 characters function adj($str) { return substr(str_pad($str,30,chr(0)),0,30); } # This is a simple example for an mp3 in current folder writeTags("01-Cognac Blues.mp3"); ---- Server IP: 216.235.15.211 Probable Submitter: 207.81.127.107 ---- Manual Page -- http://www.php.net/manual/en/ref.id3.php Edit -- https://master.php.net/note/edit/71191 Del: integrated -- https://master.php.net/note/delete/71191/integrated Del: useless -- https://master.php.net/note/delete/71191/useless Del: bad code -- https://master.php.net/note/delete/71191/bad+code Del: spam -- https://master.php.net/note/delete/71191/spam Del: non-english -- https://master.php.net/note/delete/71191/non-english Del: in docs -- https://master.php.net/note/delete/71191/in+docs Del: other reasons-- https://master.php.net/note/delete/71191 Reject -- https://master.php.net/note/reject/71191 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119757) next »