summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-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])