Use the magic module for better (content based) MIME type guessing if mimetypes does not return a type. diff -up eyeD3-0.6.17/README~ eyeD3-0.6.17/README --- eyeD3-0.6.17/README~ 2009-02-02 05:54:52.000000000 +0200 +++ eyeD3-0.6.17/README 2010-05-25 19:43:21.000000000 +0300 @@ -20,6 +20,7 @@ See the NEWS (NEWS) and/or ChangeLog (Ch Requirements ============ - Python (http://www.python.org/) >= 2.3 + - python-magic (http://www.darwinsys.com/file/, optional) Installation ============ diff -up eyeD3-0.6.17/src/eyeD3/frames.py~ eyeD3-0.6.17/src/eyeD3/frames.py --- eyeD3-0.6.17/src/eyeD3/frames.py~ 2009-02-02 05:54:52.000000000 +0200 +++ eyeD3-0.6.17/src/eyeD3/frames.py 2010-05-25 19:39:13.000000000 +0300 @@ -18,7 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ################################################################################ -import sys, os, os.path, re, zlib, StringIO, time, mimetypes; +import sys, os, os.path, re, zlib, StringIO, time; from StringIO import StringIO; from utils import *; from binfuncs import *; @@ -1274,12 +1274,12 @@ class ImageFrame(Frame): # Load img fp = file(imgFile, "rb"); imgData = fp.read(); - mt = mimetypes.guess_type(imgFile); - if not mt[0]: + mt = guess_mime_type(imgFile); + if not mt: raise FrameException("Unable to guess mime-type for %s" % (imgFile)); frameData = DEFAULT_ENCODING; - frameData += mt[0] + "\x00"; + frameData += mt + "\x00"; frameData += bin2bytes(dec2bin(type, 8)); frameData += desc.encode(id3EncodingToString(encoding)) + "\x00"; frameData += imgData; @@ -1528,11 +1528,10 @@ class ObjectFrame(Frame): if mime: print("Using specified mime type %s" % mime); else: - mt = mimetypes.guess_type(objFile); - if not mt[0]: + mime = guess_mime_type(objFile); + if not mime: raise FrameException("Unable to guess mime-type for %s" % objFile); - mime = mt[0]; print("Guessing mime type %s" % mime); frameData = DEFAULT_ENCODING; diff -up eyeD3-0.6.17/src/eyeD3/tag.py~ eyeD3-0.6.17/src/eyeD3/tag.py --- eyeD3-0.6.17/src/eyeD3/tag.py~ 2009-02-02 05:54:52.000000000 +0200 +++ eyeD3-0.6.17/src/eyeD3/tag.py 2010-05-25 19:39:54.000000000 +0300 @@ -17,7 +17,6 @@ # ################################################################################ import re, os, string, stat, shutil, tempfile, binascii; -import mimetypes; from stat import *; from eyeD3 import *; import eyeD3.utils; @@ -1700,7 +1699,7 @@ class Mp3AudioFile(TagFile): ################################################################################ def isMp3File(fileName): - (type, enc) = mimetypes.guess_type(fileName); + type = eyeD3.utils.guess_mime_type(fileName); return type == "audio/mpeg"; ################################################################################ diff -up eyeD3-0.6.17/src/eyeD3/utils.py~ eyeD3-0.6.17/src/eyeD3/utils.py --- eyeD3-0.6.17/src/eyeD3/utils.py~ 2009-02-02 05:54:52.000000000 +0200 +++ eyeD3-0.6.17/src/eyeD3/utils.py 2010-05-25 19:47:58.000000000 +0300 @@ -180,3 +180,23 @@ def format_time_delta(td): if days: tstr = "%d days %s" % (days, tstr) return tstr + +################################################################################ +# MIME type guessing + +import mimetypes +try: + import magic + _magic = magic.open(magic.MAGIC_SYMLINK | magic.MAGIC_MIME) + _magic.load() +except: + _magic = None + +def guess_mime_type(filename): + mime = mimetypes.guess_type(filename)[0] + if not mime and _magic and os.path.isfile(filename): + mime = _magic.file(filename) + if mime: + mime = mime.split(";")[0] + return mime +