Push-Nachrichten von MacTechNews.de
Würden Sie gerne aktuelle Nachrichten aus der Apple-Welt direkt über Push-Nachrichten erhalten?
Forum>Entwickler>was macht iTunes anders mit den ID3-Tags als andere Programme?

was macht iTunes anders mit den ID3-Tags als andere Programme?

iBook.Fan
iBook.Fan22.02.0618:25
hab hier ein problem, an dem ich heute schon fast verzweifelt bin...
also, ich habe 2 mp3 dateien, und möchte gerne per php die id3-tags auslesen, soweit so gut... bei der einen test mp3 (nicht mit iTunes erstellt) werden die tags richtig ausgegeben, bei der anderen test mp3 (mit iTunes erstellt) bekomme ich keine informationen... in beiden dateien befinden sich id3v2.2 tags...
hier der code der mp3.php (diese datei wird aufgerufen):
<?php
$mp3_source = "./test1.mp3";
include("mphp3.php");
$info = New mphp3();
$infoload($mp3_source);
echo "<br />Title: ".$infov2_title;
echo "<br />Artist: ".$infov2_artist;
echo "<br />Album: ".$infov2_album;
echo "<br />Year: ".$infov2_year;
echo "<br />Comment: ".$infov2_comment;
echo "<br />TracK: ".$infov2_track;
echo "<br />Genre: ".$infov2_genre;
?>

und hier die mphp3.php (momentan nicht selber geschrieben, bin ja noch beim einarbeiten in den bereich id3-tag):
<?php

# Mphp3, Version 1.0b [January-07-2005]
#
# A PHP Class for obtaining Information from a mp3 File.
# For more Information check out en_readme.html (or de_readme.html for
# german version) or visit the Website:
#
#
#
# Developed 2002 by Patrick Borgeat [cReA|BMB], webmaster@crea-bmb.de


class mphp3
{
function mphp3($favtag = 2)
{

$thisbittable = array(0,1,2,3,4);
$thisfreqtable = array(0,1,2,3);
$thismodetable = array(0,1,2,3,4);
$thisvertable = array("MPEG 2.5","","MPEG 2","MPEG 1");
$thislaytable = array("","Layer III","Layer II","Layer I");
$thisemptable = array("none","50/15 ms","","CCIT J.17");
$thischantable = array("Stereo","Joint Stereo","Stereo (Dual Channel)","Mono");

$thisfavtag = $favtag;

$thisgentable = array( 'Blues','Classic Rock','Country','Dance','Disco','Funk','Grunge', #6
'Hip-Hop','Jazz','Metal','New Age','Oldies','Other','Pop','R&B','Rap', #15
'Reggae','Rock','Techno','Industrial','Alternative','Ska','Death Metal', #22
'Pranks','Soundtrack','Euro-Techno','Ambient','Trip-Hop','Vocal', #28
'Jazz+Funk','Fusion','Trance','Classical','Instrumental','Acid','House', #35
'Game','Sound Clip','Gospel','Noise','AlternRock','Bass','Soul','Punk','Space', #44
'Mediative','Instrumental Pop','Instrumental Rock','Ethnic','Gothic','Darkwave', #50
'Techno-Industrial','Electronic','Pop-Folk','Eurodance','Dream','Southern Rock','Comedy','Cult', #58
'Gangsta','Top 40','Christian Rap','Pop/Funk','Jungle','Native American','Cabaret', #65
'New Wave','Psychadelic','Rave','Showtunes','Trailer','Lo-Fi','Tribal','Acid Punk', #73
'Acid Jazz','Polka','Retro','Musical','Rock & Roll','Hard Rock', #79
'Folk','Folk-Rock','National Folk','Swing','Fast Fusion','Beobob','Latin','Revival','Celtic', #88
'Bluegrass','Avantgarde','Gothic Rock','Progressive Rock','Psychedelic Rock','Symphonic Rock', #94
'Slow Rock','Big Band','Chorus','Easy Listening','Acoustic','Humour','Speech','Chanson','Opera', #103
'Chamber Music','Sonata','Symphony','Booty Brass','Primus','Porn Groove','Satire','Slow Jam', #111
'Club','Tango','Samba','Folklore','Ballad','Power Ballad','Rhytmic Soul','Freestyle','Duet', #120
'Punk Rock','Drum Solo','A Capela','Euro-House','Dance Hall'); #125

$thisid3v2types = array( 'TALB' => 'TEXT', 'TBPM' => 'TEXT', 'TCOM' => 'TEXT', 'TCON' => 'GENR',
'TCOP' => 'TEXT', 'TDAT' => 'TEXT', 'TDLY' => 'TEXT', 'TENC' => 'TEXT',
'TEXT' => 'TEXT', 'TFLT' => 'TEXT', 'TIME' => 'TEXT', 'TIT1' => 'TEXT',
'TIT2' => 'TEXT', 'TIT3' => 'TEXT', 'TKEY' => 'TEXT', 'TLAN' => 'TEXT',
'TLEN' => 'TEXT', 'TMED' => 'TEXT', 'TOAL' => 'TEXT', 'TOFN' => 'TEXT',
'TOLY' => 'TEXT', 'TOPE' => 'TEXT', 'TORY' => 'TEXT', 'TOWN' => 'TEXT',
'TPE1' => 'TEXT', 'TPE2' => 'TEXT', 'TPE3' => 'TEXT', 'TPE4' => 'TEXT',
'TPOS' => 'TEXT', 'TPUB' => 'TEXT', 'TRCK' => 'TEXT', 'TRDA' => 'TEXT',
'TRSN' => 'TEXT', 'TRSO' => 'TEXT', 'TSIZ' => 'TEXT', 'TSRC' => 'TEXT',
'TSSE' => 'TEXT', 'TYER' => 'TEXT', 'TXXX' => 'TEXT', 'COMM' => 'COMM');

$thisbittable[0] = array(0,32,64,96,128,160,192,224,256,288,320,352,384,416,448);
$thisbittable[1] = array(0,32,48,56,64,80,96,112,128,160,192,224,256,320,384);
$thisbittable[2] = array(0,32,40,48,56,64,80,96,112,128,160,192,224,256,320);
$thisbittable[3] = array(0,32,48,56,64,80,96,112,128,144,160,176,192,224,256);
$thisbittable[4] = array(0,8,16,24,32,40,48,56,64,80,96,112,128,144,160);

$thisfreqtable[0] = array(11025,12000,8000);
$thisfreqtable[2] = array(22050,24000,16000);
$thisfreqtable[3] = array(44100,48000,32000);

$thismodetable[3] = array("bands 4 - 31","bands 8 to 31","bands 12 to 31","bands 16 to 31");
$thismodetable[2] = array("bands 4 - 31","bands 8 to 31","bands 12 to 31","bands 16 to 31");
$thismodetable[1] = array("normal","Intensity Stereo","ms Stereo","Intensity Stereo / ms Stereo");
}

function load ($filename)
{
$thisfree();
@$fp = fopen($filename,"rb");
if(!$fp)
{
$thiserror = true;
$thiserrorstring = "COULD NOT OPEN FILE";
}

if($fp)
{
$thisfilename = $filename;
$thissize = filesize($filename);

$try_id3v2 = fread($fp,3);

if($try_id3v2 != "ID3"){fseek($fp,0);}

if($try_id3v2 == "ID3")
{
$idv2ver1 = ord(fread($fp,1));
$idv2ver2 = ord(fread($fp,1));
$thisid3v2version = "2.$idv2ver1.$idv2ver2";
$thisid3v2 = true;
$idv2headerflag = $thisgetbin($fp,1);
$idv2headerlen = bindec(substr($thisgetbin($fp),1).substr($thisgetbin($fp),1).substr($thisgetbin($fp),1).substr($thisgetbin($fp),1));

if($idv2ver1 >= 3)
{

$thisid3v2array = array();

$id3v2pos = 0;
$id3v2frameid = "XXXX";
$id3v2type = "XRAW";

while($id3v2pos < $idv2headerlen && $id3v2frameid != "" && ($id3v2pos + $id3v2framelen) < $thissize)
{
$id3v2frameid = trim(fread($fp,4));

$id3v2framelen = bindec(substr($thisgetbin($fp),0).substr($thisgetbin($fp),0).substr($thisgetbin($fp),0).substr($thisgetbin($fp),0));

#Seems to be a líttle confusing... Framelength should get encoded as Syncafe, but doesn't get (at least by Winamp) So this should work.

if(($id3v2pos + $id3v2framelen) < $thissize)
{
$id3v2frameflag = $thisgetbin($fp,2);
if($id3v2framelen <= 0){$id3v2framecontent = "";}
if($id3v2framelen > 0){$id3v2framecontent = fread($fp,$id3v2framelen);}
$id3v2pos = $id3v2pos + 10 + $id3v2framelen;

$id3v2type = $thisid3v2types[$id3v2frameid];


if($id3v2type == ""){$id3v2type = "XRAW";}

if($id3v2type == "XRAW")
{
$thisid3v2array[$id3v2frameid] = $id3v2framecontent;
}

if($id3v2type == "TEXT")
{
$thisid3v2array[$id3v2frameid] = trim(substr($id3v2framecontent,1));
}

if($id3v2type == "COMM")
{
$commstring = substr($id3v2framecontent,4);
$thisid3v2array[$id3v2frameid] = trim($commstring);
}

if($id3v2type == "GENR")
{
$id3v2framecontent = trim(substr($id3v2framecontent,1));
$genrfs = substr($id3v2framecontent,0,1);
if($genrfs == "(" )
{
$id3v2framecontent = substr($id3v2framecontent,1);
$number = $id3v2framecontent + 1 -1;
$thisid3v2array[$id3v2frameid] = $thisgentable[$number];
}

if($genrfs != "(" )
{
$thisid3v2array[$id3v2frameid] = $id3v2framecontent;
}

}

}
if(($id3v2pos + $id3v2framelen) >= $thissize){$thiserror = true;$thiserrorstring = "CORRUPT ID3V2 FRAME";}
}

$thisv2_artist = $thisid3v2array["TPE1"];
$thisv2_title = $thisid3v2array["TIT2"];
$thisv2_album = $thisid3v2array["TALB"];
$thisv2_year = $thisid3v2array["TYER"];
$thisv2_genre = $thisid3v2array["TCON"];
$thisv2_comment = $thisid3v2array["COMM"];
$thisv2_track = $thisid3v2array["TRCK"];
}

fseek($fp,$idv2headerlen+10);

}

$searchchar = 0;
$foundheader = false;
$thisvalue = false;
$seacrhi =0;

while($searchchar != 255 && !feof($fp) && $searchi <= 1*1024)
{
$searchchar = ord(fread($fp,1));
$searchi++;
}

$mpegfeof = feof($fp);
if($searchi > 8*1024){$mpegfeof = true;}

if(!$mpegfeof)
{
$thisvalid = true;
fseek($fp,-1,SEEK_CUR);

$binstring = $thisgetbin($fp,4);

$h_syn = bindec(substr($binstring,0,11));
$h_ver = bindec(substr($binstring,11,2));
$h_lay = bindec(substr($binstring,13,2));
$h_crc = bindec(substr($binstring,15,1));
$h_bit = bindec(substr($binstring,16,4));
$h_fre = bindec(substr($binstring,20,2));
$h_pad = bindec(substr($binstring,22,1));
$h_pri = bindec(substr($binstring,23,1));
$h_cha = bindec(substr($binstring,24,2));
$h_mex = bindec(substr($binstring,26,2));
$h_cpr = bindec(substr($binstring,28,1));
$h_org = bindec(substr($binstring,29,1));
$h_emp = bindec(substr($binstring,30,2));


$bitar = 5;

if($h_lay == 3 && $h_ver == 3)
{$bitar = 0;}

if($h_lay == 2 && $h_ver == 3)
{$bitar = 1;}

if($h_lay == 1 && $h_ver == 3)
{$bitar = 2;}

if(($h_ver == 0 || $h_ver == 2) && $h_lay == 3)
{$bitar = 3;}

if(($h_ver == 0 || $h_ver == 2) && ($h_lay == 2 || $h_lay == 1))
{$bitar = 4;}



if($h_syn != 2047 || $h_ver == 1 || $h_lay == 0 || $h_bit == 15 || $h_fre == 3 || $h_emp == 2 || $bitar == 5)
{
$thisvalid = false;
}

if($thisvalid)
{
$thisversion = $thisvertable[$h_ver];
$thislayer = $thislaytable[$h_lay];
$thisprotection = $h_crc;
$thisbitrate = $thisbittable[$bitar][$h_bit];
$thisfrequency = $thisfreqtable[$h_ver][$h_fre];
$thispadding = $h_pad;
$thisprivate = $h_pri;
$thischannel = $thischantable[$h_cha];
if($h_cha == 1){$thismode = $thismodetable[$h_lay][$h_mex];}
$thiscopyright = $h_cpr;
$thisoriginal = $h_org;
$thisemphasis = $thisemptable[$h_emp];


$thislength = floor($thissize / ($thisbitrate * (1000/8)));

$thislengthstring = floor($thislength/60).":".str_pad( ($thislength%60) ,2,"0",STR_PAD_LEFT);


fseek ($fp,-128,SEEK_END);
$s_id3v1 = fread($fp,128);

if(substr($s_id3v1,0,3) == "TAG")
{
$thisid3v1 = true;
$thisv1_title = trim(substr($s_id3v1,3,30));
$thisv1_artist = trim(substr($s_id3v1,33,30));
$thisv1_album = trim(substr($s_id3v1,63,30));
$thisv1_year = trim(substr($s_id3v1,93,4));
$thisv1_comment = trim(substr($s_id3v1,97,29));
$idv1track = ord(substr($s_id3v1,126));
if($idv1track != 0){$thisv1_track = $idv1track;}
$gchar = substr($s_id3v1,127,1);
$thisv1_genre = $thisgentable[ord($gchar)];
if($thisv1_genre == ""){$thisv1_genre = "Unknown";}

}

if($thisfavtag == 2)
{
$thistitle = $thisv2_title;
$thisartist = $thisv2_artist;
$thisalbum = $thisv2_album;
$thisyear = $thisv2_year;
$thiscomment = $thisv2_comment;
$thistrack = $thisv2_track;
$thisgenre = $thisv2_genre;

if($thistitle == ""){$thistitle = $thisv1_title;}
if($thisartist == ""){$thisartist = $thisv1_artist;}
if($thisalbum == ""){$thisalbum = $thisv1_album;}
if($thisyear == ""){$thisyear = $thisv1_year;}
if($thiscomment == ""){$thiscomment = $thisv1_comment;}
if($thistrack == ""){$thistrack = $thisv1_track;}
if($thisgenre == ""){$thisgenre = $thisv1_genre;}
}

if($thisfavtag == 1)
{
$thistitle = $thisv1_title;
$thisartist = $thisv1_artist;
$thisalbum = $thisv1_album;
$thisyear = $thisv1_year;
$thiscomment = $thisv1_comment;
$thistrack = $thisv1_track;
$thisgenre = $thisv1_genre;

if($thistitle == ""){$thistitle = $thisv2_title;}
if($thisartist == ""){$thisartist = $thisv2_artist;}
if($thisalbum == ""){$thisalbum = $thisv2_album;}
if($thisyear == ""){$thisyear = $thisv2_year;}
if($thiscomment == ""){$thiscomment = $thisv2_comment;}
if($thistrack == ""){$thistrack = $thisv2_track;}
if($thisgenre == ""){$thisgenre = $thisv2_genre;}
}

if($thistitle == "" || $thisartist == "")
{
$rawfile = array_pop(explode("/",$thisfilename));
$preonear = explode(".", trim($rawfile));
array_pop($preonear);
$fidarr = explode("-", implode(".", $preonear ) );
$fdartist = array_shift($fidarr);
$fdtitle = trim(implode("-",$fidarr));

if($thistitle == ""){$thistitle = $fdtitle;}
if($thisartist == ""){$thisartist = $fdartist;}
if($thistitle == ""){$thistitle = $thisartist;$thisartist = "";}
}
}

fclose($fp);
return $thisvalid;
}
if($mpegfeof)
{
$thisvalid = false;
}


}
}

function free()
{
unset( $thisfilename,
$thissize,
$thisvalid,

$thiserror,
$thiserrorstring,

$thisversion,
$thisfrequency,
$thislayer,
$thischannel,
$thismode,
$thisemphasis,
$thisprivate,
$thispadding,
$thisoriginal,
$thiscopyright,
$thisprotection,

$thisbitrate,
$thislength,
$thislengthstring,

$thisid3v1,
$thisv1_title,
$thisv1_artist,
$thisv1_album,
$thisv1_year,
$thisv1_comment,
$thisv1_track,
$thisv1_genre,

$thisid3v2,
$thisid3v2version,
$thisid3v2array,
$thisv2_title,
$thisv2_artist,
$thisv2_album,
$thisv2_year,
$thisv2_comment,
$thisv2_track,
$thisv2_genre,

$thistitle,
$thisartist,
$thisalbum,
$thisyear,
$thiscomment,
$thistrack,
$thisgenre

);
}

function getbin($fp,$len = 1)
{
$i = 0;
$retstr = "";
while($i < $len)
{

$retstr .= str_pad(decbin(ord(fread($fp,1))),8,"0",STR_PAD_LEFT);
$i++;
}
return $retstr;
}


}
?>

die frage ist nur, warum funktionierts mit mp3's die mit nem anderen programm erstellt wurden wunderbar, mit den aus iTunes aber nicht?
0

Kommentare

DASKAjA
DASKAjA09.03.0609:22
Auf deinem Mac gibt's ein schönes Kommandozeilenprogram, welches sich 'hexdump' schimpft. Damit kannst du dir ganze einfach ansehen was sich evtl. geändert haben sollte.
0
JustDoIt
JustDoIt28.03.0618:25
Schade das wir nicht erfahren haben wie es ausgegangen ist.
0

Kommentieren

Diese Diskussion ist bereits mehr als 3 Monate alt und kann daher nicht mehr kommentiert werden.