def add_root_elements(self, handler):
super(RssCustomPodcastsFeed, self).add_root_elements(handler)
emission = self.feed.get('emission')
+ if emission and emission.image and emission.image.url:
+ image_url = emission.image.url
+ else:
+ image_url = '/static/img/logo-panik-500.png'
+ image_url = urlparse.urljoin(self.feed['link'], image_url)
handler.startElement('image', {})
if emission:
handler.addQuickElement('title', emission.title)
else:
handler.addQuickElement('title', 'Radio Panik')
- if emission and emission.image and emission.image.url:
- handler.addQuickElement('url', urlparse.urljoin(self.feed['link'], emission.image.url))
- else:
- handler.addQuickElement('url', urlparse.urljoin(self.feed['link'], '/static/img/logo-panik-500.png'))
+ handler.addQuickElement('url', image_url)
handler.endElement('image')
+ handler.addQuickElement('itunes:image', None, {'href': image_url})
+ if emission and emission.subtitle:
+ handler.addQuickElement('itunes:subtitle', emission.subtitle)
def root_attributes(self):
attrs = super(RssCustomPodcastsFeed, self).root_attributes()
attrs['xmlns:dc'] = 'http://purl.org/dc/elements/1.1/'
+ attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
return attrs
def add_item_elements(self, handler, item):
super(RssCustomPodcastsFeed, self).add_item_elements(handler, item)
+ explicit = 'no'
for tag in item.get('tags') or []:
handler.addQuickElement('dc:subject', tag)
+ if tag == 'explicit':
+ explicit = 'yes'
+ if item.get('tags'):
+ handler.addQuickElement('itunes:keywords', ','.join(item.get('tags')))
+ handler.addQuickElement('itunes:explicit', explicit)
+ episode = item.get('episode')
+ if episode and episode.image and episode.image.url:
+ image_url = urlparse.urljoin(self.feed['link'], episode.image.url)
+ handler.addQuickElement('itunes:image', None, {'href': image_url})
+ soundfile = item.get('soundfile')
+ if soundfile.duration:
+ handler.addQuickElement('itunes:duration', '%02d:%02d:%02d' % (
+ soundfile.duration / 3600,
+ soundfile.duration % 3600 / 60,
+ soundfile.duration % 60))
+
class PodcastsFeed(Feed):
title = 'Radio Panik - Podcasts'
return item.creation_timestamp
def item_extra_kwargs(self, item):
- return {'tags': [x.name for x in item.episode.tags.all()]}
+ return {'tags': [x.name for x in item.episode.tags.all()],
+ 'soundfile': item,
+ 'episode': item.episode}
podcasts_feed = PodcastsFeed()
atom_news_feed = AtomNewsFeed()
-class EmissionPodcastsFeed(Feed):
+class EmissionPodcastsFeed(PodcastsFeed):
description_template = 'feed/soundfile.html'
feed_type = RssCustomPodcastsFeed
podcastable=True,
episode__emission__slug=self.emission.slug).order_by('-creation_timestamp')[:20]
- def item_title(self, item):
- if item.fragment:
- return '%s - %s' % (item.title, item.episode.title)
- return item.episode.title
-
- def item_link(self, item):
- return item.episode.get_absolute_url()
-
- def item_enclosure_url(self, item):
- current_site = Site.objects.get(id=settings.SITE_ID)
- return add_domain(current_site.domain, item.get_format_url('mp3'))
-
- def item_enclosure_length(self, item):
- sound_path = item.get_format_path('mp3')
- try:
- return os.stat(sound_path)[stat.ST_SIZE]
- except OSError:
- return 0
-
- def item_enclosure_mime_type(self, item):
- return 'audio/mpeg'
-
- def item_pubdate(self, item):
- return item.creation_timestamp
-
- def item_extra_kwargs(self, item):
- return {'tags': [x.name for x in item.episode.tags.all()]}
-
emission_podcasts_feed = EmissionPodcastsFeed()