Location: PHPKode > projects > Brunhilde Media Server > brunhilde/id3.php
<?php

### id3.php ###
// displays the id3 information about the chosen mp3

include("global.php");
include("mpeginfo.php");

$mpeginfo = new mpeginfo();
$file = stripslashes(rawurldecode($m3u));

// determines where the mp3 file is
if(isset($cdir)) { 
  $cdir = stripslashes($cdir);
  $cdir_url = rawurlencode($cdir);
  // while loops fix interesting lag related bug
  while(!($id3 = $mpeginfo->getinfo($MEDIA_DIR[$base][1].$cdir.$file))) {}
  }
else { while (!($id3 = $mpeginfo->getinfo($MEDIA_DIR[$base][1].$file))) {} }

// gets the layer and bitrate information
if(isset($cdir)) { while(!($header = $mpeginfo->headers($MEDIA_DIR[$base][1].$cdir.$file))) {} }
else { while(!($header = $mpeginfo->headers($MEDIA_DIR[$base][1].$file))) {} }

// gets the id3 variables from the tag

// if $ID3_VERSION = 1: first looks for an id3v1 variable, then
// falls back to an id3v2 variable
if($ID3_VERSION = 1) {
  if($id3['artist'] != "") { $artist = $id3['artist']; }
  else { $artist = $id3['TPE1']; }

  if($id3['album'] != "") { $album = $id3['album']; }
  else { $album = $id3['TALB']; }

  if($id3['year'] != "") { $year = $id3['year']; }
  else { $year = $id3['TYER']; }

  if($id3['track'] != "") { $track = $id3['track']; }
  else { $track = $id3['TRCK']; }

  if($id3['title'] != "") { $mp3_title = $id3['title']; }
  else { $mp3_title = $id3['TIT2']; }

  if($id3['genre'] != "") { $genre = $id3['genre']; }
  else { $genre = $id3['TCON']; }
  }


// if $ID3_VERSION = 2: first looks for an id3v2 variable, then
// falls back to an id3v1 variable
if($ID3_VERSION = 2) {
  if($id3['TPE1'] != "") { $artist = $id3['TPE1']; }
  else { $artist = $id3['artist']; }

  if($id3['TALB'] != "") { $album = $id3['TALB']; }
  else { $album = $id3['album']; }

  if($id3['TYER'] != "") { $year = $id3['TYER']; }
  else { $year = $id3['year']; }

  if($id3['TRCK'] != "") { $track = $id3['TRCK']; }
  else { $track = $id3['track']; }

  if($id3['TIT2'] != "") { $mp3_title = $id3['TIT2']; }
  else { $mp3_title = $id3['title']; }

  if($id3['TCON'] != "") { $genre = $id3['TCON']; }
  else { $genre = $id3['genre']; }
  }


// gets mpeg info from the file headers
$size = $mpeginfo->size;
$size_kb = intval($size / 1024);
$size_mb = intval($size_kb / 1024) .".". intval(($size_kb % 1024) / 10);
$layer = $header['layer'];
$bitrate = $header['bitrate'];
$samplerate = $header['samplerate'];
$playtime = intval($header['length']);
$playtime_minutes = sprintf("%d:%02d", $playtime/60, $playtime%60 );

// displays the id3 info in a pretty table
echo "<html>\n<head>\n<title>Brunhilde id3 form</title>\n</head>\n";

include("header.php");

echo "<p>\n";
echo "<table border=0 width=100% bgcolor=#ffffff cellpadding=0 cellspacing=0>\n";
echo "<tr><td>\n";
echo "<table border=0 width=100% cellpadding=2 cellspacing=1>\n";

echo "<tr $TITLE>\n";
echo "<td width=1% align=center>\n";
$file_url = rawurlencode(stripslashes($file));
echo "<a href=m3u.php?play=$file_url&base=$base><img src=$PLAY_ICON></a>\n";
echo "</td><td align=center>\n";
echo "<font size=4><B>&nbsp;Brunhilde id3 Tag Viewer:&nbsp;</B></font>\n";
echo "</td>\n";

echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Title:&nbsp;</B></font>\n";
echo "</td><td width=99%  $BODY align=center>\n";
if($mp3_title == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$mp3_title&nbsp;</font>\n"; }
echo "</td>\n";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Artist:&nbsp;</B></font>\n";
echo "</td><td width=99%  $BODY align=center>\n";
if($artist == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$artist&nbsp;</font>\n"; }
echo "</td>\n";
echo "</tr><tr>";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Album:&nbsp;</B></font>\n";
echo "</td><td width=99% $BODY align=center>";
if($album == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$album</font>"; }
echo "</td>";
echo "</tr><tr>";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Track&nbsp;#:&nbsp;</B></font>\n";
echo "</td><td width=99% $BODY align = center>\n";
if($track == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$track</font>"; }
echo "</td>\n";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Genre:&nbsp;</B></font>\n";
echo "</td><td width=97%  $BODY align=center>\n";
if($genre == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$genre&nbsp;</font>\n"; }
echo "</td>\n";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Year:&nbsp;</B></font>\n";
echo "</td><td width=1%  $BODY align=center>";
if($year == "") { echo "<font size=3>&nbsp;N/A</font>"; }
else { echo "<font size=3>&nbsp;$year&nbsp;</font>"; }
echo "</td>";
echo "</tr><tr $TITLE>\n";
echo "<td width=1% align=center>\n";
echo "<B>--------</B>";
echo "</td><td width=1% align=center>";
echo "<font size=4><B>&nbsp;File Info:&nbsp;</B></font>";
echo "</td>";
echo "</tr><tr>\n";

echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Size:&nbsp;</B></font>\n";
echo "</td><td width=1% $BODY align=center>";
echo "<font size=3>&nbsp;$size_mb&nbsp;mb&nbsp;&nbsp;($size&nbsp;bytes)&nbsp;</font>";
echo "</td>";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Compression:&nbsp;</B></font>\n";
echo "</td><td width=1% $BODY align=center>";
echo "<font size=3>&nbsp;mpeg layer $layer&nbsp;</font>";
echo "</td>";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Bitrate:&nbsp;</B></font>\n";
echo "</td><td width=1% $BODY align=center>";
echo "<font size=3>&nbsp;$bitrate&nbsp;kbps&nbsp;</font>";
echo "</td>";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Samplerate:&nbsp;</B></font>\n";
echo "</td><td width=1% $BODY align=center>";
echo "<font size=3>&nbsp;$samplerate&nbsp;kHz&nbsp;</font>";
echo "</td>";
echo "</tr><tr>\n";
echo "<td width=1% $TITLE align=center>\n";
echo "<font size=3><B>&nbsp;Playtime:&nbsp;</B></font>\n";
echo "</td><td width=1% $BODY align=center>";
echo "<font size=3>&nbsp;$playtime_minutes&nbsp;minutes&nbsp;($playtime&nbsp;seconds)&nbsp;</font>";
echo "</td>";

echo "</tr>\n";
echo "</table></td></tr></table></p><BR>";

include("footer.php");

echo "</html>";
exit;

?>
Return current item: Brunhilde Media Server