detect id3 tags in files with no extension or other ext

Locked
kerk
User
Posts: 4
Joined: Mon Sep 05, 2011 11:25 pm
Are you a spambot?: no

detect id3 tags in files with no extension or other ext

Post by kerk » Tue Sep 06, 2011 12:01 am

Hi all =)
I have used getid3() in my script (file manager)
its perfect, thanks for your work!
but...
my script store uploaded files on the server in FS structure like this:
files/u/s/e/r/i/d/fileID_unix_timestamp.dlfile (vBulletin like attachment structure)
snap260.png
snap260.png (1.59 KiB) Viewed 10015 times
snap259.png
snap259.png (2.21 KiB) Viewed 10015 times
and store the real information about this file in the Data Base (MySQL) - real filename, stored filename, filesize, real file extension (mp3 for example) etc
in basically the getid3() read information good, but sometimes (i can't understand why) the array $ThisFileInfo['comments_html'] is empty with stored file extension (.dlfile - not mp3) =\
i found the solution (ugly =\), to copy file with real extension in the temp dir =>
read ID3 info (getid3()) =>
store info into array $ThisFileInfo['comments_html'] =>
delete temp file =>
print id3 info on the page or store this info into DB
=
can someone explain, why this happens? =)

James Heinrich
getID3() v1 developer
Posts: 1477
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: detect id3 tags in files with no extension or other ext

Post by James Heinrich » Tue Sep 06, 2011 2:04 am

Tag metadata (ID3v2, ID3v1, APE, Lyrics3) should always be read. The file may not be detected as an mp3 file if it sufficiently corrupted (random null or garbage data at beginning of file, or between end of ID3v2 and beginning of audio data). Unfortunately this kind of corruption is very common (see "Known Bugs/Issues in other programs" at the end of the readme).

getID3 hacks around this problem of "undetectable" file formats by doing a brute force scan of the file under the assumption that it's a broken MP3 file if the filename ends in ".mp3" (actually .mp3 or .mp2 or .mp1 or .mpa). See function GetFileFormat() in getid3.php (around lines 1130-1165 in v1.9.1).

kerk
User
Posts: 4
Joined: Mon Sep 05, 2011 11:25 pm
Are you a spambot?: no

Re: detect id3 tags in files with no extension or other ext

Post by kerk » Tue Sep 06, 2011 4:50 am

thank you for replay, James =)
==
before open a new thread I have carefully examined the files and getid3.php getid3.lib.php including you specified function (GetFileFormat())
and have no idea, how to make the function work =)
ok, i show you small debug in the screen (my english is very bad)...

Code: Select all

$getID3 = new getID3;
$FullFileName = 'K:/MUSIC/Galka/A.Celentano - Susanna.mp3';
$ThisFileInfo = $getID3->analyze($FullFileName);
getid3_lib::CopyTagsToComments($ThisFileInfo);
print '<pre>';
print_r($ThisFileInfo);
print '</pre>';
snap261.png
snap261.png (9.49 KiB) Viewed 10012 times
and now, i rename the file and run the script again....

Code: Select all

$getID3 = new getID3;
$FullFileName = 'K:/MUSIC/Galka/A.Celentano - Susanna.dlfile';
$ThisFileInfo = $getID3->analyze($FullFileName);
getid3_lib::CopyTagsToComments($ThisFileInfo);
print '<pre>';
print_r($ThisFileInfo);
print '</pre>';
snap262.png
snap262.png (7.06 KiB) Viewed 10012 times
it is same file, but only renamed =)
the getid3() read info from file, not by extension, right?
where i'm wrong? =)

James Heinrich
getID3() v1 developer
Posts: 1477
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: detect id3 tags in files with no extension or other ext

Post by James Heinrich » Tue Sep 06, 2011 11:11 am

If you look at the two files: the one on the left was encoded by a "bad" version of LAME (v3.92 DLL) and the one on the right was encoded with a fixed version (v3.93).
corrupt_mp3a.gif
corrupt_mp3a.gif (71.24 KiB) Viewed 10008 times
You can see the beginning of the "bad" file consists of nothing but nulls (00) for the entire first frame of the file (417 bytes), but the "good" file starts with the MP3 header (FF FB 94 44 in this case), and also contains other data in the Xing/LAME header section. Because there's nothing at the beginning of the bad file, it's impossible to know what kind of file it is. What getID3 does when checking files is basically this:

Code: Select all

foreach (<known file types>) {
  if (<first few bytes of file> = <known file pattern>) {
    return analyze_file_as(found_file_type);
  }
}
// failed to match any known file types
if (<filename> like ".mp3") {
  return analyze_file_as(MP3);
} else {
  return false;
}

kerk
User
Posts: 4
Joined: Mon Sep 05, 2011 11:25 pm
Are you a spambot?: no

Re: detect id3 tags in files with no extension or other ext

Post by kerk » Tue Sep 06, 2011 4:12 pm

yes, i see this function =)
but if function modified like this:

Code: Select all

foreach (<known file types>) {
  if (<first few bytes of file> = <known file pattern>) {
    return analyze_file_as(found_file_type);
  }
}
// failed to match any known file types
if (<filename> like ".mp3") {
  return analyze_file_as(MP3);
}
else if(preg_match('#\.dlfile$#i', $filename))
{
  $GetFileFormatArray = $this->GetFileFormatArray();
  $info = $GetFileFormatArray['mp3'];
  $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
  return $info;
} else {
  return false;
}
this returned correct tags and all data...
and...
snap263.png
snap263.png (17.26 KiB) Viewed 10007 times
beginning of the file looks correct, no "zero" bytes
if you want, you can analize one of this "bad" files (uploaded to depositfiles)
http://depositfiles.com/files/g40jakm3v
thanks for your replies =)

James Heinrich
getID3() v1 developer
Posts: 1477
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: detect id3 tags in files with no extension or other ext

Post by James Heinrich » Tue Sep 06, 2011 5:19 pm

By "beginning of file", I mean after the ID3v2 tag is removed from the beginning (and ID3v1/APE/Lyrics3 from the end).

As I suspected, if you look at the returned warning for that file:
Unknown data before synch (ID3v2 header ends at 3635, then 626 bytes garbage, synch detected at 4261). This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.

kerk
User
Posts: 4
Joined: Mon Sep 05, 2011 11:25 pm
Are you a spambot?: no

Re: detect id3 tags in files with no extension or other ext

Post by kerk » Tue Sep 06, 2011 6:34 pm

ok, you are right =)
i will copy file to tmp location with real ext and then process with getid3()
thanks again
kerk

Locked