diff options
author | Wojciech Polak <polak@gnu.org> | 2010-12-02 17:51:04 +0100 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2010-12-02 18:21:32 +0100 |
commit | 4254de32a2976ec660739b48f5d02e9a84aaa1ba (patch) | |
tree | 42880770841bf6c06a446c85d3499f208c314045 | |
parent | 7127f7e06c93bcee98e9d277c7ca1ea29dd8bffd (diff) | |
download | glifestream-4254de32a2976ec660739b48f5d02e9a84aaa1ba.tar.gz glifestream-4254de32a2976ec660739b48f5d02e9a84aaa1ba.tar.bz2 |
Use bigger YouTube thumbnails.
-rw-r--r-- | apis/youtube.py | 11 | ||||
-rw-r--r-- | filters/expand.py | 6 | ||||
-rw-r--r-- | stream/media.py | 9 |
3 files changed, 17 insertions, 9 deletions
diff --git a/apis/youtube.py b/apis/youtube.py index d3b1df0..69da734 100644 --- a/apis/youtube.py +++ b/apis/youtube.py @@ -39,9 +39,16 @@ class API (webfeed.API): vid = None if vid and 'media_thumbnail' in ent and len (ent.media_thumbnail): - tn = ent.media_thumbnail[0] + if len (ent.media_thumbnail) > 4 and \ + 'hqdefault' in ent.media_thumbnail[4]['url']: + tn = ent.media_thumbnail[4] + tn['width'], tn['height'] = 200, 150 + else: + tn = ent.media_thumbnail[0] + if self.service.public: - tn['url'] = media.save_image (tn['url']) + tn['url'] = media.save_image (tn['url'], downscale=True, + size=(200, 150)) e.link = e.link.replace ('&feature=youtube_gdata', '') e.content = """<table class="vc"><tr><td><div id="youtube-%s" class="play-video"><a href="%s" rel="nofollow"><img src="%s" width="%s" height="%s" alt="YouTube Video" /></a><div class="playbutton"></div></div></td></tr></table>""" % (vid, e.link, tn['url'], tn['width'], tn['height']) diff --git a/filters/expand.py b/filters/expand.py index cdb07a5..b5042bf 100644 --- a/filters/expand.py +++ b/filters/expand.py @@ -106,9 +106,9 @@ def __sv_youtube (m): ltag = rest.find ('<') if rest else -1 rest = rest[ltag:] if ltag != -1 else '' link = 'http://www.youtube.com/watch?v=%s' % id - imgurl = 'http://i.ytimg.com/vi/%s/default.jpg' % id - imgurl = media.save_image (imgurl) - return '<table class="vc"><tr><td><div id="youtube-%s" class="play-video"><a href="%s" rel="nofollow"><img src="%s" width="120" height="90" alt="YouTube Video" /></a><div class="playbutton"></div></div></td></tr></table>%s' % (id, link, imgurl, rest) + imgurl = 'http://i.ytimg.com/vi/%s/hqdefault.jpg' % id + imgurl = media.save_image (imgurl, downscale=True, size=(200, 150)) + return '<table class="vc"><tr><td><div id="youtube-%s" class="play-video"><a href="%s" rel="nofollow"><img src="%s" width="200" height="150" alt="YouTube Video" /></a><div class="playbutton"></div></div></td></tr></table>%s' % (id, link, imgurl, rest) def __sv_vimeo (m): from glifestream.apis import vimeo diff --git a/stream/media.py b/stream/media.py index 152ab2c..a67dc0f 100644 --- a/stream/media.py +++ b/stream/media.py @@ -52,7 +52,8 @@ def get_thumb_info (hash): 'rel': 'thumbs/%s%s' % (prefix, hash), 'internal': '[GLS-THUMBS]/%s' % hash, } -def save_image (url, direct_image=True, force=False, downscale=False): +def save_image (url, direct_image=True, force=False, downscale=False, + size=None): if settings.BASE_URL in url: return url thumb = get_thumb_info (hashlib.sha1 (url).hexdigest ()) @@ -76,17 +77,17 @@ def save_image (url, direct_image=True, force=False, downscale=False): os.remove (tmp) return url if downscale: - downscale_image (tmp) + downscale_image (tmp, size=size) shutil.move (tmp, thumb['local']) except: if not stale: return url return thumb['internal'] -def downscale_image (filename): +def downscale_image (filename, size=None): if not Image: return - size = 400, 175 + size = size or (400, 175) try: im = Image.open (filename) w, h = im.size |