http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11713
Revision: 11713 Author: drtrigon Date: 2013-07-05 19:13:00 +0000 (Fri, 05 Jul 2013) Log Message: ----------- bug fix; libmagic (python-magic) has problems with at least 1 jpeg that all other software has not
Modified Paths: -------------- trunk/pywikipedia/catimages.py
Modified: trunk/pywikipedia/catimages.py =================================================================== --- trunk/pywikipedia/catimages.py 2013-07-05 01:17:44 UTC (rev 11712) +++ trunk/pywikipedia/catimages.py 2013-07-05 19:13:00 UTC (rev 11713) @@ -50,7 +50,7 @@ import re, urllib2, os, locale, sys, datetime, math, shutil, mimetypes, shelve import StringIO, json # fallback: simplejson from subprocess import Popen, PIPE -import Image +import Image, imghdr #import ImageFilter
scriptdir = os.path.dirname(sys.argv[0]) @@ -3083,6 +3083,10 @@ m = magic.open(magic.MAGIC_MIME) # or 'magic.MAGIC_NONE' m.load() file_mime = re.split('[/;\s]', m.file(file_name)) + file_imgh = ['image', imghdr.what(file_name)] # alternative MIME ... + if file_imgh[1] and (not (file_imgh == file_mime[:2])): + pywikibot.warning(u'Issue in MIME type detection! Preferring imghdr result %s over libmagic %s!' % (file_imgh, file_mime)) + file_mime = file_imgh + file_mime[2:] mime = mimetypes.guess_all_extensions('%s/%s' % tuple(file_mime[0:2])) if mime and (os.path.splitext(file_name)[1].lower() not in mime): pywikibot.warning(u'File extension does not match MIME type! File extension should be %s.' % mime)
pywikipedia-svn@lists.wikimedia.org