Skip to content

Instantly share code, notes, and snippets.

@tzangms
Created July 30, 2019 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzangms/0631f0826f1691824c81038342cdccaa to your computer and use it in GitHub Desktop.
Save tzangms/0631f0826f1691824c81038342cdccaa to your computer and use it in GitHub Desktop.
podcast feed
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
{% if podcast.new_feed_url %}<itunes:new-feed-url>{{ podcast.new_feed_url }}</itunes:new-feed-url>{% endif %}
<atom:link href="http://{{ request.get_host }}{{ podcast.get_absolute_url }}rss/" rel="self" type="application/rss+xml" />
<title><![CDATA[{{ podcast.title|striptags|fix_ampersands }}]]></title>
<link>http://{{ request.get_host }}{{ podcast.get_absolute_url }}</link>
<description><![CDATA[{{ podcast.description|striptags|fix_ampersands }}]]></description>
<language>zh-TW</language>
<lastBuildDate>{{ last_build_date|date:"r" }}</lastBuildDate>
<itunes:author><![CDATA[{{ podcast.user.profile.nickname }}]]></itunes:author>
<itunes:owner>
<itunes:name>{{ podcast.user.username }}</itunes:name>
<itunes:email>{{ podcast.user.email }} ({{ podcast.user.profile.nickname }})</itunes:email>
</itunes:owner>
<itunes:subtitle><![CDATA[{{ podcast.subtitle|striptags|fix_ampersands }}]]></itunes:subtitle>
<itunes:summary><![CDATA[{{ podcast.description|striptags|fix_ampersands }}]]></itunes:summary>
{% if podcast.cover %}<itunes:image href="{{ podcast.get_cover_url }}" />{% endif %}
{% if podcast.category %}<itunes:category text="{{ podcast.get_category_display }}" />{% endif %}
<itunes:explicit>{{ podcast.get_explicit_display|lower|default:"no" }}</itunes:explicit>
{% for episode in episodes %}
<item>
<title><![CDATA[{{ episode.title|striptags|fix_ampersands }}]]></title>
<link>http://{{ request.get_host }}{{ episode.get_absolute_url }}</link>
<description><![CDATA[{{ episode.description|striptags|fix_ampersands }}]]></description>
<author>{{ podcast.user.email }} ({{ podcast.user.email }})</author>
<enclosure url="http://{{ request.get_host }}{{ episode.get_file_url }}" length="{{ episode.size }}" type="audio/mpeg" />
<guid isPermaLink="true">http://myaudiocast.com{{ episode.get_absolute_url }}</guid>
<pubDate>{{ episode.created_at|date:"r" }}</pubDate>
<itunes:author>{{ podcast.user.username }}</itunes:author>
{% if episode.subtitle %}<itunes:subtitle>{{ episode.subtitle }}</itunes:subtitle>{% endif %}
<itunes:summary><![CDATA[{{ episode.description|striptags }}
Listen this on MyAudioCast: http://{{ request.get_host }}{{ episode.get_absolute_url }}]]></itunes:summary>
{% if episode.tags %}<itunes:keywords>{{ episode.tags.all|join:"," }}</itunes:keywords>{% endif %}
<itunes:explicit>{{ episode.get_explicit_display|lower|default:"no" }}</itunes:explicit>
{% if episode.block %}<itunes:block>yes</itunes:block>{% endif %}
</item>
{% endfor %}
</channel>
</rss>
def podcast_feed(request, slug):
podcast = get_object_or_404(Podcast, slug=slug)
episodes = Episode.objects.filter(podcast=podcast, enable=True)
translation.activate('en')
output = render_to_string('rss.html', {
'podcast': podcast,
'episodes': episodes,
'last_build_date': podcast.last_modified
}, context_instance=RequestContext(request))
translation.deactivate()
response = HttpResponse(output)
response['Content-Type'] = 'application/rss+xml'
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment