diff --git a/www/podjango/feeds.py b/www/podjango/feeds.py index d66fbb35d0fa5291cf2fa76e851b3b2324d58165..cc0c301115ec1af36024ef0cf33b3245bc0e7c1c 100644 --- a/www/podjango/feeds.py +++ b/www/podjango/feeds.py @@ -17,7 +17,8 @@ # "AGPLv3". If not, see . # -from django.contrib.syndication.views import Feed +from django.contrib.sites.shortcuts import get_current_site +from django.contrib.syndication.views import add_domain, Feed from django.utils.feedgenerator import Rss201rev2Feed #from podjango.apps.staff.models import Person from podjango.apps.cast.models import Cast @@ -181,8 +182,19 @@ class CastFeed(CastFeedBase): author_name = "Free as in Freedom" title_template = "feeds/podcast_title.html" description_template = "feeds/podcast_description.html" + + def get_feed(self, obj, request): + # Enclosure (media) URLs don't automatically get the protocol and + # domain, but these are required for the podcast to work + # properly. added. This provides current_site and is_secure to the feed + # so that we have it in context for use in `item_enclosure_url`. + self.current_site = get_current_site(request) + self.is_secure = request.is_secure() + return super().get_feed(obj, request) + def items(self): return Cast.objects.filter(pub_date__lte=datetime.now()).order_by('-pub_date') + def item_pubdate(self, item): return item.pub_date @@ -221,14 +233,14 @@ class CastFeed(CastFeedBase): class Mp3CastFeed(CastFeed): def item_enclosure_mime_type(self): return "audio/mpeg" def item_enclosure_url(self, item): - return item.mp3_path + return add_domain(self.current_site.domain, item.mp3_path, self.is_secure) def item_enclosure_length(self, item): return item.mp3_length class OggCastFeed(CastFeed): def item_enclosure_mime_type(self): return "audio/ogg" def item_enclosure_url(self, item): - return item.ogg_path + return add_domain(self.current_site.domain, item.ogg_path, self.is_secure) def item_enclosure_length(self, item): return item.ogg_length