From: Oleg Broytman Date: Mon, 3 Jan 2011 00:07:46 +0000 (+0000) Subject: Get favicon even if it's of a wrong type. X-Git-Tag: v4.5.3~72 X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=commitdiff_plain;h=8ce74f839238093d7278aa041ff55dbcb7abd3a0 Get favicon even if it's of a wrong type. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@304 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- diff --git a/Robots/bkmk_rsimple.py b/Robots/bkmk_rsimple.py index 41fa2b3..c2733a1 100644 --- a/Robots/bkmk_rsimple.py +++ b/Robots/bkmk_rsimple.py @@ -206,19 +206,23 @@ class robot_simple(Robot): except: etype, emsg, tb = sys.exc_info() self.log(" no icon : %s %s" % (etype, emsg)) - etype = None - emsg = None - tb = None + etype = emsg = tb = None icons[icon] = None else: content_type = headers["Content-Type"] - if content_type.startswith("image/"): + if content_type.startswith("application/") \ + or content_type.startswith("image/") \ + or content_type.startswith("text/plain"): icon_file = open(icon_fname, "rb") icon_data = icon_file.read() icon_file.close() bookmark.icon_href = icon - bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data)) self.log(" got icon : %s" % content_type) + if content_type.startswith("application/") \ + or content_type.startswith("text/plain"): + self.log(" got non-image icon, assume x-icon") + content_type = 'image/x-icon' + bookmark.icon = "data:%s;base64,%s" % (content_type, b64encode(icon_data)) icons[icon] = (content_type, bookmark.icon) else: self.log(" no icon : bad content type '%s'" % content_type) diff --git a/doc/ANNOUNCE b/doc/ANNOUNCE index 15efd76..968d81e 100644 --- a/doc/ANNOUNCE +++ b/doc/ANNOUNCE @@ -9,6 +9,10 @@ WHAT'S NEW in version 4.3.1 (2011-??-??). Get favicon before HTML redirect (refresh). +Get favicon even if it's of a wrong type; many sites return favicon as +text/plain or application/*; the only exception is text/html which is usually +an error page instead of error 404. + WHAT'S NEW in version 4.3.0 (2011-01-01).