function get_id3($track, $id3tag = null)
{
    global $basedir;
    if (is_numeric($track)) {
        // track_id is given
        $ad_link = track_relative_path($track);
        $audio_file = $basedir . $ad_link;
    } else {
        // path is given
        $track = urldecode($track);
        $track = str_replace("___", "/", $track);
        $audio_file = $track;
    }
    $getID3 = new getID3();
    $fileinfo = $getID3->analyze($audio_file);
    // associate object attributes
    $arr["tag"]["artist"] = html_entity_decode($fileinfo["tags_html"]["id3v2"]["artist"][0], ENT_COMPAT, "UTF-8");
    $arr["tag"]["album"] = html_entity_decode($fileinfo["tags_html"]["id3v2"]["album"][0], ENT_COMPAT, "UTF-8");
    $arr["tag"]["title"] = html_entity_decode($fileinfo["tags_html"]["id3v2"]["title"][0], ENT_COMPAT, "UTF-8");
    $arr["tag"]["composer"] = html_entity_decode($fileinfo["tags_html"]["id3v2"]["composer"][0], ENT_COMPAT, "UTF-8");
    $arr["tag"]["track_number"] = $fileinfo["tags_html"]["id3v2"]["track_number"][0];
    $arr["tag"]["year"] = $fileinfo["tags_html"]["id3v2"]["year"][0];
    $id3genre = $fileinfo["tags_html"]["id3v2"]["content_type"][0];
    $query = "SELECT id FROM genre WHERE genre = \"{$id3genre}\"";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    $genre = mysql_fetch_assoc($result);
    if (strlen($genre) > 0) {
        $genre1 = $genre["id"];
    }
    $arr["tag"]["genre1"] = $genre1;
    $arr["tag"]["genre2"] = $fileinfo["tags_html"]["id3v2"]["content_type"][1];
    $arr["fileformat"] = $fileinfo["fileformat"];
    $arr["filepath"] = $fileinfo["filepath"];
    $arr["filenamepath"] = $fileinfo["filenamepath"];
    $arr["filename"] = $fileinfo["filename"];
    $arr["filesize"] = $fileinfo["filesize"];
    $arr["playtime_seconds"] = $fileinfo["playtime_seconds"];
    $arr["playtime_string"] = $fileinfo["playtime_string"];
    $arr["bitrate"] = $fileinfo["bitrate"];
    if (isset($id3tag)) {
        $info[$id3tag] = $arr[$id3tag];
        return $info;
    } else {
        return $arr;
    }
}
function get_audio_data($track_id)
{
    global $basedir;
    if ($track_id == "current") {
        $track_id = get_current_track_id();
    }
    header('Content-Type: audio/mp3');
    $t_artist = get_db_track_info("artist", $track_id);
    $t_title = get_db_track_info("title", $track_id);
    $filename = $t_artist . " - " . $t_title . ".mp3";
    header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
    // header("Content-Disposition: inline; filename=\"".$filename."\"");
    $ad_link = track_relative_path($track_id);
    $audio_file = $basedir . $ad_link;
    $fp = fopen($audio_file, "r");
    $inhalt = fread($fp, filesize($audio_file));
    fclose($fp);
    echo $inhalt;
}
function show_trackrow($rownum, $row, $showrownum, $showartist, $showtitle, $showcomposer, $showgenre, $showlang, $showyear, $showrating, $showbpm, $showsource, $showcreated, $showmodified, $showlength, $showedit, $showdownload, $playtp, $showtoplaylist, $showremove)
{
    list($id, $artist, $title, $composer, $length, $genre1, $year, $type, $rating) = split("\t", $row);
    if (strlen($year) > 2) {
        $yearstr = "'" . substr($year, 2, 2);
    } else {
        $yearstr = $year;
    }
    if ($showrownum) {
        print "<td class=\"rownum\">" . ($rownum + 1) . ".</td>";
    }
    if ($showartist) {
        print "<td class=\"trklst\">{$artist}</td>";
    }
    if ($showtitle) {
        print "<td class=\"trklst\">{$title}</td>";
    }
    if ($showcomposer) {
        print "<td class=\"trklst\">{$composer}</td>";
    }
    if ($showgenre) {
        print "<td class=\"trklst\">&nbsp;";
        if (strlen($genre1) > 0) {
            print_genre_string($genre1);
        }
        if (strlen($genre1) > 0 && strlen($genre2) > 0) {
            print "<br>";
        }
        if (strlen($genre2) > 0) {
            print "&nbsp;";
            print_genre_string($genre2);
        }
        print "</td>";
    }
    if ($showrating) {
        print "<td class=\"trklst\">&nbsp;";
        print_rating_string($rating);
        print "</td>";
    }
    if ($showlang) {
        print "<td class=\"trklst\">&nbsp;" . language_string($lang) . " </td>";
    }
    if ($showyear) {
        print "<td class=\"trklst\">&nbsp;" . $yearstr . " </td>";
    }
    if ($showlength) {
        print "<td class=\"trklst\">&nbsp;" . seconds2time($length) . " </td>";
    }
    if ($showedit) {
        print "<td class=\"trklst\">&nbsp;<a href=\"gdedittrack.php?id=" . $id . "\" target=\"_blank\">" . "<img border=\"0\" src=\"img/edit-c.gif\" title=\"Edit\"></a></td>";
    }
    if ($showdownload) {
        # Download mp3
        # types: playtp = dl or pl
        if (strcmp($playtp, "dl") == 0) {
            print "<td class=\"trklst\">&nbsp;<a href=\"" . track_relative_path($id) . "\">" . "<img border=\"0\" src=\"img/dl.gif\" title=\"Download\"></a>{$mp3path}</td>";
        } else {
            # all other playtypes handled by "gdaction.php"
            print "<td class=\"trklst\">&nbsp;<a href=\"gdaction.php?action=dlplay&amp;method={$playtp}&amp;trackid={$id}\">" . "<img border=\"0\" src=\"img/dl.gif\" alt=\"download and play\"></a></td>";
            //        print "<td class=\"trklst\">&nbsp;<a href=\"javascript:popUp('gdaction.php?action=dlplay&amp;method=$playtp&amp;trackid=$id')\">"
            //		     ."<img border=\"0\" src=\"img/dl.gif\" alt=\"download and play\"></a></td>";
        }
    }
    if ($showtoplaylist) {
        # append to playlist
        print "<td class=\"trklst\">&nbsp;<a href=\"javascript:popUp('gdaction.php?action=addtopl&amp;trackid={$id}')\">" . "<img border=\"0\" src=\"img/tri-r.png\" title=\"append to playlist\"></a></td>";
    }
    if ($showremove) {
        # append to playlist
        print "<td class=\"trklst\">&nbsp;<a href=\"?removeitem={$rownum}\">" . "<img border=\"0\" src=\"img/remove.png\" alt=\"remove item\"></a></td>";
    }
    # goto playlist item
    print "<td class=\"trklst\">&nbsp;<a href=\"?gotoitem={$rownum}\">" . "<img border=\"0\" src=\"img/pl.png\" alt=\"jump\"></a></td>";
}