summaryrefslogtreecommitdiff
path: root/modules/url_titles.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2009-12-23 15:42:47 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2009-12-23 15:42:47 +0100
commitca704f2f01495153c4ad8b2721a99afcb6654576 (patch)
treecb4f25ba1c7a2d22e2e7eca5f955f6e856e21da8 /modules/url_titles.py
parentf1ab2a9437d876e82e5c22fd622b94f60e554be1 (diff)
Print image sizes.
Diffstat (limited to 'modules/url_titles.py')
-rw-r--r--modules/url_titles.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/url_titles.py b/modules/url_titles.py
index 0f7d64a..7297d4d 100644
--- a/modules/url_titles.py
+++ b/modules/url_titles.py
@@ -5,6 +5,7 @@ info = {
}
import re, urllib2, htmlentitydefs, gzip, cStringIO, spotimeta
+from PIL import ImageFile
class Module:
re_http = re.compile(r'(http://[^\ ]+)')
@@ -95,6 +96,25 @@ class Module:
buf = u.read(1024)
if m:
titles.append(m.groups()[0])
+ elif u.headers['content-type'] in ('image/gif', 'image/png', 'image/jpeg'):
+ def pretty_size(size):
+ suffixes = (('B', 2**10), ('KiB', 2**20), ('MiB', 2**30), ('GiB', 2**40), ('TiB', 2**50))
+ for suf, lim in suffixes:
+ if size > lim:
+ continue
+ else:
+ return '%s %s' % (str(round(size/float(lim/2**10), 2)), suf)
+ p = ImageFile.Parser()
+ size = 0
+ while 1:
+ s = u.read(1024)
+ size += len(s)
+ if not s:
+ break
+ p.feed(s)
+ im = p.close()
+ titles.append('%s image: %dx%d (%s)' % ((im.format,) + tuple(im.size) + (pretty_size(size),)))
+ del im
u.close()
if len(titles) == 1:
s = format_text(titles[0])