From 3efce1dc9e23411c71e846cd56e412dbc19448f0 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Stefan=20K=C3=B6gl?=
Date: Wed, 29 Dec 2010 14:06:14 +0200
Subject: [PATCH] allow scaling of inlined logos (param scale_logo)
---
feedservice/feeddownloader.py | 14 +++++++++++---
feedservice/index.html | 9 +++++----
feedservice/main.py | 10 ++++++----
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/feedservice/feeddownloader.py b/feedservice/feeddownloader.py
index a535251..6e9e1e3 100644
--- a/feedservice/feeddownloader.py
+++ b/feedservice/feeddownloader.py
@@ -28,6 +28,9 @@ import urllib2
import base64
#import socket
+from google.appengine.api import images
+
+
import feedcore
from utils import parse_time
import youtube
@@ -134,7 +137,7 @@ def get_episode_metadata(entry, files):
return d
-def parse_feed(feed_url, inline_logo):
+def parse_feed(feed_url, inline_logo, scale_to):
try:
fetcher.fetch(feed_url)
@@ -156,7 +159,7 @@ def parse_feed(feed_url, inline_logo):
logo_url = get_podcast_logo(feed)
podcast['logo'] = logo_url
if inline_logo and logo_url:
- podcast['logo_data'] = get_data_uri(logo_url)
+ podcast['logo_data'] = get_data_uri(logo_url, scale_to)
#update_feed_tags(podcast, get_feed_tags(feed.feed))
@@ -192,8 +195,13 @@ def get_podcast_logo(feed):
return cover_art
-def get_data_uri(url):
+
+def get_data_uri(url, size=None):
content = urllib2.urlopen(url).read()
+
+ if size:
+ content = images.resize(content, size, size)
+
mimetype = get_mimetype(None, url)
encoded = base64.b64encode(content)
return 'data:%s;base64,%s' % (mimetype, encoded)
diff --git a/feedservice/index.html b/feedservice/index.html
index d4c4152..582eebd 100644
--- a/feedservice/index.html
+++ b/feedservice/index.html
@@ -16,14 +16,15 @@
- url: The URL of the feed that should be parsed (required)
- inline_logo: If set to 1, the (unscaled) logos are included in the response as data URIs (default 0).
+ - scale_logo: If inline_logo is set to 1, scales the included logo to the given size. The resulting images is fitted into a square with the given side-length.
Examples:
-
- GET /parse?url=http://feeds.feedburner.com/linuxoutlaws&inline_logo=1
- GET /parse?url=http://leo.am/podcasts/floss&url=http://feeds.twit.tv/floss_video_large
-
+
+ GET /parse?url=http://feeds.feedburner.com/linuxoutlaws&inline_logo=1&scale_logo=30
+ GET /parse?url=http://leo.am/podcasts/floss&url=http://feeds.twit.tv/floss_video_large
+
If you intend to use this instance of the webservice in your
diff --git a/feedservice/main.py b/feedservice/main.py
index 21f8006..3348aff 100644
--- a/feedservice/main.py
+++ b/feedservice/main.py
@@ -13,21 +13,23 @@ class Parse(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
urls = self.request.get_all('url')
- inline_logo = self.is_set('inline_logo')
+ inline_logo = self.get_int('inline_logo')
+ scale_to = self.get_int('scale_logo', None)
if urls:
- podcasts = [feeddownloader.parse_feed(url, inline_logo) for url in urls]
+ podcasts = [feeddownloader.parse_feed(url, inline_logo, scale_to) for url in urls]
pretty = json.dumps(podcasts, sort_keys=True, indent=4)
self.response.out.write(pretty)
else:
self.response.set_status(400)
self.response.out.write('parameter url missing')
- def is_set(self, param, default='0'):
+ def get_int(self, param, default=0):
try:
return int(self.request.get(param, default))
except:
- return 0
+ return default
+
application = webapp.WSGIApplication([
('/', MainPage),
--
2.11.4.GIT