Permalink
Browse files

Site RSS now mRSS and serving jpgs as attached media. Fixes #54

  • Loading branch information...
1 parent d6d1db8 commit 16bd813cd8e780f4a112fe484519104f04afd6c4 @palewire palewire committed May 28, 2012
Showing with 61 additions and 12 deletions.
  1. +12 −12 archive/feeds.py
  2. +49 −0 toolbox/mrss.py
View
@@ -1,7 +1,9 @@
+from taggit.models import Tag
from django.db.models import Count
from archive.models import Update, Site
from django.utils import timezone
from django.shortcuts import get_object_or_404
+from toolbox.mrss import MediaRSSFeed
from django.template.defaultfilters import date as dateformat
from django.contrib.syndication.views import Feed, FeedDoesNotExist
@@ -36,28 +38,18 @@ class SiteFeed(Feed):
"""
The most recent pages from a site.
"""
+ feed_type = MediaRSSFeed
+
def get_object(self, request, pk):
- """
- Fetch the Site object.
- """
return get_object_or_404(Site, pk=pk)
def title(self, obj):
- """
- Set the feed title.
- """
return "%s screenshots by PastPages" % obj.name
def link(self, obj):
- """
- Set the feed link.
- """
return obj.get_absolute_url()
def items(self, obj):
- """
- Fetch the latest 10 screenshots
- """
return obj.screenshot_set.all()[:10]
def item_title(self, item):
@@ -71,3 +63,11 @@ def item_title(self, item):
def item_description(self, item):
return None
+
+ def item_extra_kwargs(self, item):
+ d = {}
+ if item.has_crop:
+ d['thumbnail_url'] = item.crop.url_300x251
+ d['content_url'] = item.crop.url
+ return d
+
View
@@ -0,0 +1,49 @@
+from django.utils.feedgenerator import Rss201rev2Feed
+
+
+class MediaRSSFeed(Rss201rev2Feed):
+ """Basic implementation of Yahoo Media RSS (mrss)
+ http://video.search.yahoo.com/mrss
+
+ Includes these elements in the Item feed:
+ media:content
+ url, width, height
+ media:thumbnail
+ url, width, height
+ media:description
+ media:title
+ media:keywords
+ """
+ def rss_attributes(self):
+ attrs = super(MediaRSSFeed, self).rss_attributes()
+ attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
+ attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
+ return attrs
+
+ def add_item_elements(self, handler, item):
+ """Callback to add elements to each item (item/entry) element."""
+ super(MediaRSSFeed, self).add_item_elements(handler, item)
+
+ if 'media:title' in item:
+ handler.addQuickElement(u"media:title", item['title'])
+ if 'media:description' in item:
+ handler.addQuickElement(u"media:description", item['description'])
+
+ if 'content_url' in item:
+ content = dict(url=item['content_url'])
+ if 'content_width' in item:
+ content['width'] = str(item['content_width'])
+ if 'content_height' in item:
+ content['height'] = str(item['content_height'])
+ handler.addQuickElement(u"media:content", '', content)
+
+ if 'thumbnail_url' in item:
+ thumbnail = dict(url=item['thumbnail_url'])
+ if 'thumbnail_width' in item:
+ thumbnail['width'] = str(item['thumbnail_width'])
+ if 'thumbnail_height' in item:
+ thumbnail['height'] = str(item['thumbnail_height'])
+ handler.addQuickElement(u"media:thumbnail", '', thumbnail)
+
+ if 'keywords' in item:
+ handler.addQuickElement(u"media:keywords", item['keywords'])

0 comments on commit 16bd813

Please sign in to comment.