Page 1 of 1

List files with certain id3 tags

Posted: Sun Aug 06, 2006 10:22 pm
by toasty2
I am wanting to list mp3's in a directory, but ONLY if the artist is System of a Down, it reads the files' id3 tags, but I obviously messed up somewhere., since It displays a blank page.

Code: Select all

<?php

$path = "/homepages/21/d155481990/htdocs/server";

$dir_handle = @opendir($path) or die("Unable to open $path");

while ($file = readdir($dir_handle))
{
   if($file!="." && $file!=".." && $file!="songlist.php" && $file!="song.php" && $file!="music.html" && $file!="songdevlist.php" && $file!=null)


    $mp3 = $file; //MP3 file to be read


    $filesize = filesize($mp3);
    $file = fopen($mp3, "r");
    fseek($file, -128, SEEK_END);
   
    $tag = fread($file, 3);
   
   
    if($tag == "TAG")
    {
        $data["artist"] = trim(fread($file, 30));   
    }
    else
        die("");
   
    fclose($file);
        strtolower($mp3);
    while(list($key, $value) = each($data))
    {
       
        if ($data["artist"] == 'system of a down')
                        { print("$key: $value<br>\r\n"); }
       
    }
}
//closing the directory
closedir($dir_handle);
?>

And, I have several songs for that artist, and they are in the same directory and I am sure the songs have that artist in their id3 tags. I have a different script that will display the id3 tags of a specific file to verify it.

Posted: Sun Aug 06, 2006 10:32 pm
by feyd
Do these files use ID3v1 or ID3v2 or both? Btw.. you're missing some braces. They shouldn't cause a blank page (which you should check your errors logs for) but would mess up some of the logic you are trying to accomplish.

Posted: Sun Aug 06, 2006 10:41 pm
by Benjamin
This would cause a parse error I believe..

Code: Select all

if ($tag == "TAG")
    {
        $data["artist"] = trim(fread($file, 30));   
    }
    else
        die("");
Change to...

Code: Select all

if ($tag == "TAG")
    {
        $data["artist"] = trim(fread($file, 30));   
    } else 
    {
        die(""); 
    }

Posted: Mon Aug 07, 2006 11:05 am
by toasty2
I fixed the possible error, and I also put an error message in the die function, and now it always displays the error message. So, it's not reading the directory's files, at least not correctly.

Posted: Mon Aug 07, 2006 11:08 am
by toasty2
feyd wrote:Do these files use ID3v1 or ID3v2 or both?
They use possibly both, I haven't checked, but I'm not trying to get any extra ID tags in the files, just the artist one, which should be in it whether v1 or v2.

Posted: Mon Aug 07, 2006 11:28 am
by feyd
Your code only works with v1 tags. That's why I've asked.

Posted: Mon Aug 07, 2006 7:34 pm
by toasty2
Well, that code could list each of the files individually in its original form, but I tried to adapt it to its current forum to go through each mp3. If you'd like the original code (which isn't much different), just ask. I also implemented a directory listing script into that also, trying to get the combo to do what I wanted.

Posted: Mon Aug 07, 2006 8:00 pm
by feyd
it may be better to use strpos() instead of being literal.