From b39320a498a480e46a7e46311611f593a0898158 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Stefan=20K=C3=B6gl?=
Date: Tue, 28 Dec 2010 20:26:27 +0200
Subject: [PATCH] add option to inline logos
---
feedservice/feeddownloader.py | 15 +++++++++++++--
feedservice/index.html | 9 ++++++++-
feedservice/main.py | 10 +++++++++-
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/feedservice/feeddownloader.py b/feedservice/feeddownloader.py
index fb63bd8..a535251 100644
--- a/feedservice/feeddownloader.py
+++ b/feedservice/feeddownloader.py
@@ -25,6 +25,7 @@ import sys
import datetime
import hashlib
import urllib2
+import base64
#import socket
import feedcore
@@ -133,7 +134,7 @@ def get_episode_metadata(entry, files):
return d
-def parse_feed(feed_url):
+def parse_feed(feed_url, inline_logo):
try:
fetcher.fetch(feed_url)
@@ -152,7 +153,11 @@ def parse_feed(feed_url):
podcast['author'] = feed.feed.get('author', feed.feed.get('itunes_author', ''))
podcast['language'] = feed.feed.get('language', '')
- podcast['logo'] = get_podcast_logo(feed)
+ logo_url = get_podcast_logo(feed)
+ podcast['logo'] = logo_url
+ if inline_logo and logo_url:
+ podcast['logo_data'] = get_data_uri(logo_url)
+
#update_feed_tags(podcast, get_feed_tags(feed.feed))
podcast['episodes'] = []
@@ -186,3 +191,9 @@ def get_podcast_logo(feed):
cover_art = yturl
return cover_art
+
+def get_data_uri(url):
+ content = urllib2.urlopen(url).read()
+ 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 a2ad57a..d4c4152 100644
--- a/feedservice/index.html
+++ b/feedservice/index.html
@@ -12,9 +12,16 @@
returning the simplified contents as JSON.
Usage
+ Parameters to /parse
+
+ - 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).
+
+
+
Examples:
- GET /parse?url=http://feeds.feedburner.com/linuxoutlaws
+ 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
diff --git a/feedservice/main.py b/feedservice/main.py
index 748a768..21f8006 100644
--- a/feedservice/main.py
+++ b/feedservice/main.py
@@ -13,14 +13,22 @@ 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')
+
if urls:
- podcasts = map(feeddownloader.parse_feed, urls)
+ podcasts = [feeddownloader.parse_feed(url, inline_logo) 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'):
+ try:
+ return int(self.request.get(param, default))
+ except:
+ return 0
+
application = webapp.WSGIApplication([
('/', MainPage),
('/parse', Parse)
--
2.11.4.GIT