Author: tack
Date: Wed Mar 21 20:29:08 2007
New Revision: 2580

Modified:
   trunk/metadata/src/audio/eyeD3/tag.py

Log:
Don't be so zealous in searching for an mp3 frame header when the file
extension is not mp3 -- significantly reduces false positives for non-mp3
files.


Modified: trunk/metadata/src/audio/eyeD3/tag.py
==============================================================================
--- trunk/metadata/src/audio/eyeD3/tag.py       (original)
+++ trunk/metadata/src/audio/eyeD3/tag.py       Wed Mar 21 20:29:08 2007
@@ -1573,10 +1573,6 @@
    def __init__(self, fileName, tagVersion = ID3_ANY_VERSION):
       TagFile.__init__(self, fileName);
 
-      # isMp3File is naive checks file extension only.
-      #if not isMp3File(fileName):
-      #   raise self.invalidFileExc;
-
       # Parse ID3 tag.
       f = file(self.fileName, "rb");
       tag = Tag();
@@ -1598,12 +1594,20 @@
                                            "frame");
       header = mp3.Header();
       frameHead = header.find(bString)[0]
+
       # Keep reading until we find a valid mp3 frame header, but give up if we
-      # don't find one within the first 300KB.
+      # don't find one within the first X KB, where X is 300KB if the file
+      # extension indicates the file may be an MP3, and 128 bytes otherwise.
       offset = n_chunks = 0
+      if isMp3File(fileName):
+         chunk_size = 32768
+         chunk_limit = 10
+      else:
+         chunk_size = 128
+         chunk_limit = 1
 
-      while not frameHead and n_chunks < 10:
-         bString = bString[-3:] + f.read(32768)
+      while not frameHead and n_chunks < chunk_limit:
+         bString = bString[-3:] + f.read(chunk_size)
          n_chunks += 1
          if len(bString) <= 3:
             break
@@ -1615,7 +1619,7 @@
 
       # Seek back just before frame header, for Xing header detection.
       try:
-          f.seek(-4 + (offset - 32768 + 4) * (n_chunks > 0), 1)
+          f.seek(-4 + (offset - chunk_size + 4) * (n_chunks > 0), 1)
       except IOError:
          raise InvalidAudioFormatException("Unable to find a valid mp3 frame")
         

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to