PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

id3_get_frame_long_name> <ob_iconv_handler
Last updated: Sun, 25 Nov 2007

view this page in

ID3 Függvények

Bevezetés

Ezek a függvények lehetővé teszik, hogy olvasd és kezeld az ID3 tageket. Az ID3 tageket MP3 fájlokban használják a dal címének, az előadó adatainak, az albumnak, a műfajnak, az évnek és a szám sorszámának tárolására.

A 0.2-es verzióban lehetőség nyílt szöveges keretek kinyerésére ID3 v2.2+ tagekből is.

Követelmények

Az itt leírt függvények használatához semmilyen külső függvénykönyvtár megléte nem szükségeltetik.

Telepítés

id3 része a PECL-nek és a PEAR telepítővel telepíthető. A PHP id3 támogatással való fordításhoz töltsd le a forráskódot, rakd a php-src/ext/id3 könyvtárba és fordítsd a PHP-t az --enable-id3 opcióval.

Futásidejű beállítások

Ez a kiterjesztés semmilyen konfigurációs beállításokat nem definiál a php.ini állományban.

Erőforrás típusok

Ez a kiterjesztés semmilyen erőforrás típust nem definiál.

Előre definált konstansok

Az id3 függvények vagy engedik, hogy megadd a tag verziót, vagy visszaadják a tag verziószámát. A verziószám megadásához használd a következő konstansok valamelyikét.

ID3_V1_0 (integer)
Az ID3_V1_0-át használd akkor, ha ID3 V1.0 tagekkel dolgozol. Ezek a tagek tartalmazhatnak címet, előadót, albumot, műfajt, évet és megjegyzést.
ID3_V1_1 (integer)
Az ID3_V1_1-et használd akkor, ha ID3 V1.1 tagekkel dolgozol. Ezek a tagek tartalmazhatják az összes információt, amire a v1.0 képes és a szám sorszámát.
ID3_V2_1 (integer)
Az ID3_V2_1-et használd akkor, ha ID3 V2.1 tagekkel dolgozol.
ID3_V2_2 (integer)
Az ID3_V2_2-őt használd akkor, ha ID3 V2.2 tagekkel dolgozol.
ID3_V2_3 (integer)
Az ID3_V2_3-at használd akkor, ha ID3 V2.3 tagekkel dolgozol.
ID3_V2_4 (integer)
Az ID3_V2_4-et használd akkor, ha ID3 V2.4 tagekkel dolgozol.
ID3_BEST (integer)
Az ID3_BEST-et használd akkor, ha azt szeretnéd, hogy a függvények döntsék el, mely verziót kellene használni.

Table of Contents



id3_get_frame_long_name> <ob_iconv_handler
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
id3
regindk at gmail dot com
29-Dec-2006 09:54
Using the ID3 extension you might be interested in some more functionality for working with MP3-files that is missing in the PHP C-modules.

Such as extracting for instance the first 10 seconds of a song, merging MP3 files, calculating the exact length of the MP3 file.

The following class in pure PHP is available for that:
http://www.sourcerally.net/Scripts/20-PHP-MP3-Class
jbwalker at telus dot net
15-Nov-2006 02:58
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.

<?php
 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
       
$tagLen = 1024; # or whatever you like >your actual
       
$Header = substr($Header,0,6).setHexTagLen($tagLen);
       
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");
?>

The setHexTagLen can be figured out from the calcDecTagLen but here's some sample code.

<?php
function setHexTagLen($int) {
   
$n = pow(128,3);
   
$intVar = $int;
   
$m = "";
    for (
$i=0;$i<4;$i++) {
       
$m .= chr(floor($intVar/$n));
       
$intVar = $intVar % $n;
       
$n=$n/128;
        }
    return
$m;
}
?>
wmd at wazee dot org
11-Jul-2004 05:31
There are several highly developed id3 reader classes written in php that include id3v2 support, and support for other file formats (not just mpeg & id3). I recommend http://getid3.sourceforge.net/ as well as the id3 reader class integrated in the Zina is not Andromeda project (http://pancake.org/zina.html)

id3_get_frame_long_name> <ob_iconv_handler
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites