Changeset - 9381e607cd90
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 6 months ago 2023-10-13 01:41:20
ben@sturm.com.au
Automatically generate feed enclosure URL prefix
2 files changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
www/podjango/feeds.py
Show inline comments
...
 
@@ -17,7 +17,8 @@
 
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 
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
 

	
www/podjango/urls.py
Show inline comments
...
 
@@ -33,8 +33,8 @@ app_name = 'podjango'
 
urlpatterns = [
 
    url(r'^$', frontpage.view),
 
    url(r'^cast/', include('podjango.apps.cast.urls')),
 
    url(r'^feeds/cast-ogg/$', Mp3CastFeed(), name='feed-ogg'),
 
    url(r'^feeds/cast-mp3/$', OggCastFeed(), name='feed-mp3'),
 
    url(r'^feeds/cast-ogg/$', OggCastFeed(), name='feed-ogg'),
 
    url(r'^feeds/cast-mp3/$', Mp3CastFeed(), name='feed-mp3'),
 
    url(r'^feeds/$', view, name='feeds'),
 
]
 

	
0 comments (0 inline, 0 general)