2023-10-05 08:17:55 +00:00
# Copyright (C) 2008, 2010 Bradley M. Kuhn <bkuhn@ebb.org>
# Copyright (C) 2006, 2007 Software Freedom Law Center, Inc.
#
# This software's license gives you freedom; you can copy, convey,
# propogate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
2023-10-19 06:21:53 +00:00
from datetime import datetime
2023-10-13 01:41:20 +00:00
from django . contrib . sites . shortcuts import get_current_site
2023-10-19 22:52:39 +00:00
from django . contrib . syndication . views import Feed , add_domain
2023-10-05 08:17:55 +00:00
from django . shortcuts import render
2023-10-19 22:52:39 +00:00
from django . utils . feedgenerator import Rss201rev2Feed
2023-10-05 08:17:55 +00:00
2023-10-19 06:21:53 +00:00
from . models import Cast
2023-10-05 08:17:55 +00:00
# FIXME: Settings here should not be hard-coded for given casts, but
# should instead have settings from the main screen.
2024-02-23 04:06:59 +00:00
2023-10-05 08:17:55 +00:00
class CastFeedBase ( Feed ) :
2024-02-23 04:06:59 +00:00
def copyright_holder ( self ) :
return " Bradley M. Kuhn, Karen M. Sandler "
2023-10-05 08:17:55 +00:00
2024-02-23 04:06:59 +00:00
def license_no_html ( self ) :
return " Licensed under a Creative Commons Attribution-Share Alike 3.0 USA License. "
2023-10-05 08:17:55 +00:00
def item_copyright ( self , item ) :
year = 2008
for attr in ( ' pub_date ' , ' date_created ' , ' date_last_modified ' ) :
if hasattr ( item , attr ) :
if hasattr ( getattr ( item , attr ) , ' year ' ) :
year = getattr ( getattr ( item , attr ) , ' year ' )
break
return ' Copyright (C) %d , %s . %s ' % ( year , self . copyright_holder ( ) , self . license_no_html ( ) )
def item_extra_kwargs ( self , item ) :
year = 2008
for attr in ( ' pub_date ' , ' date_created ' , ' date_last_modified ' ) :
if hasattr ( item , attr ) :
if hasattr ( getattr ( item , attr ) , ' year ' ) :
year = getattr ( getattr ( item , attr ) , ' year ' )
break
2024-02-23 04:02:04 +00:00
return { ' year ' : year }
2023-10-05 08:17:55 +00:00
def for_podcast_feed_extra_kwargs ( self , obj ) :
2024-02-23 04:02:04 +00:00
return {
' managingEditorNames ' : ' Bradley and Karen ' ,
2024-03-06 06:34:48 +00:00
' rssImage ' : { ' url ' : ' https://sfconservancy.org/static/podjango/img/cast/tcs_300x300.jpg ' ,
2024-02-23 04:02:04 +00:00
' width ' : ' 144 ' , ' height ' : ' 144 ' } ,
' webMaster ' : ' oggcast@faif.us (Bradley and Karen) ' ,
' dcCreator ' : ' oggcast@faif.us (Bradley and Karen) ' ,
' iTunesExplicit ' : ' No ' ,
' iTunesBlock ' : ' No ' ,
2024-03-06 06:34:48 +00:00
' iTunesImage ' : { ' url ' : ' https://sfconservancy.org/static/podjango/img/cast/tcs_300x300.jpg ' ,
2024-02-23 04:02:04 +00:00
' title ' : ' The Corresponding Source (formerly Free as in Freedom) ' ,
' link ' : self . author_link ,
' type ' : ' video/jpg ' } ,
' category ' : { ' name ' : ' Government & Organizations ' , ' scheme ' : ' http://www.itunes.com/dtds/podcast-1.0.dtd ' ,
' subcats ' : [ ' Non-Profit ' ] } ,
' keywords ' : ' open source, opensource, freesoftware, software freedom, legal, law, linux, free, license, gpl, lgpl, agpl, bsd ' ,
' iTunesAuthor ' : ' Software Freedom Conservancy ' ,
' iTunesSubtitle ' : ' Bi-Weekly Discussion of Legal, Policy, and Any other Issues in the Free, Libre, and Open Source Software (FLOSS) Community ' ,
' copyrightHolder ' : self . copyright_holder ( ) ,
' copyrightLicense ' : self . license_no_html ( ) ,
}
2023-10-05 08:17:55 +00:00
def for_podcast_item_extra_kwargs ( self , item ) :
2024-02-23 04:02:04 +00:00
return {
' duration ' : item . duration ,
' year ' : item . date_created . year ,
' dcCreator ' : ' oggcast@faif.us (Bradley and Karen) ' ,
' intheitembkuhn ' : item . __dict__ . __str__ ( ) ,
}
2023-10-05 08:17:55 +00:00
def podcast_helper_add_root_elements ( self , handler ) :
2024-02-23 04:02:04 +00:00
handler . addQuickElement ( ' managingEditor ' , self . feed [ ' author_email ' ]
2023-10-05 08:17:55 +00:00
+ ' ( ' + self . feed [ ' managingEditorNames ' ] + ' ) ' )
handler . startElement ( ' image ' , { } )
handler . addQuickElement ( ' url ' , self . feed [ ' rssImage ' ] [ ' url ' ] )
handler . addQuickElement ( ' title ' , self . feed [ ' author_name ' ] )
handler . addQuickElement ( ' link ' , self . feed [ ' link ' ] )
handler . addQuickElement ( ' width ' , self . feed [ ' rssImage ' ] [ ' width ' ] )
handler . addQuickElement ( ' height ' , self . feed [ ' rssImage ' ] [ ' height ' ] )
handler . endElement ( ' image ' )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( ' webMaster ' , self . feed [ ' webMaster ' ] )
# handler.addQuickElement('dc:creator', self.feed['dcCreator'])
handler . addQuickElement ( ' itunes:explicit ' , self . feed [ ' iTunesExplicit ' ] )
handler . addQuickElement ( ' itunes:block ' , self . feed [ ' iTunesBlock ' ] )
handler . addQuickElement ( ' generator ' , ' http://www.faif.us/code ' )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( ' media:thumbnail ' , ' ' , { ' url ' : self . feed [ ' rssImage ' ] [ ' url ' ] } )
handler . addQuickElement ( ' itunes:image ' , ' ' , { ' href ' : self . feed [ ' iTunesImage ' ] [ ' url ' ] } )
# handler.addQuickElement('itunes:link', '', { 'href' : self.feed['iTunesImage']['url'],
# 'type' : self.feed['iTunesImage']['type']})
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( " media:category " , self . feed [ ' category ' ] [ ' name ' ] ,
2024-02-23 04:02:04 +00:00
{ ' scheme ' : self . feed [ ' category ' ] [ ' scheme ' ] } )
if not ( self . feed [ ' category ' ] [ ' subcats ' ] and len ( self . feed [ ' category ' ] [ ' subcats ' ] ) > 0 ) :
handler . addQuickElement ( " itunes:category " , ' ' , { ' text ' : self . feed [ ' category ' ] [ ' name ' ] } )
2023-10-05 08:17:55 +00:00
else :
2024-02-23 04:02:04 +00:00
handler . startElement ( " itunes:category " , { ' text ' : self . feed [ ' category ' ] [ ' name ' ] } )
2023-10-05 08:17:55 +00:00
for cc in self . feed [ ' category ' ] [ ' subcats ' ] :
2024-02-23 04:02:04 +00:00
handler . addQuickElement ( " itunes:category " , ' ' , { ' text ' : cc } )
2023-10-05 08:17:55 +00:00
handler . endElement ( " itunes:category " )
handler . addQuickElement ( " media:keywords " , self . feed [ ' keywords ' ] . replace ( " " , " , " ) )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . startElement ( " itunes:owner " , { } )
handler . addQuickElement ( " itunes:email " , self . feed [ ' author_email ' ] )
handler . addQuickElement ( " itunes:name " , self . feed [ ' author_name ' ] )
handler . endElement ( " itunes:owner " )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( " itunes:summary " , self . feed [ ' description ' ] )
handler . addQuickElement ( " itunes:subtitle " , self . feed [ ' iTunesSubtitle ' ] )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( " itunes:author " , self . feed [ ' iTunesAuthor ' ] )
2024-02-23 04:02:04 +00:00
handler . addQuickElement ( ' atom:link ' , ' ' , { ' rel ' : " self " , ' href ' : self . feed [ ' feed_url ' ] ,
' type ' : " application/rss+xml " } )
2023-10-05 08:17:55 +00:00
years = { }
2024-02-23 04:06:59 +00:00
for ii in self . items :
years [ ii [ ' year ' ] ] = 1
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
copyrightString = " "
ll = years . keys ( )
sorted ( ll )
2024-02-23 04:06:59 +00:00
for yy in ll :
copyrightString + = " %d , " % yy
2023-10-05 08:17:55 +00:00
copyrightString + = " %s . %s " % ( self . feed [ ' copyrightHolder ' ] , self . feed [ ' copyrightLicense ' ] )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
handler . addQuickElement ( ' copyright ' , copyrightString )
handler . addQuickElement ( ' media:copyright ' , " Copyright (C) " + copyrightString )
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
def podcast_helper_add_item_elements ( self , handler , item ) :
handler . addQuickElement ( " itunes:explicit " , self . feed [ ' iTunesExplicit ' ] )
handler . addQuickElement ( " itunes:block " , self . feed [ ' iTunesBlock ' ] )
handler . addQuickElement ( " itunes:keywords " , self . feed [ ' keywords ' ] )
# handler.addQuickElement('dc:creator', self.feed['dcCreator'])
handler . addQuickElement ( " itunes:author " , item [ ' author_name ' ] )
handler . addQuickElement ( " itunes:duration " , item [ ' duration ' ] )
if ' enclosure ' in item :
2024-02-23 04:02:04 +00:00
handler . addQuickElement ( ' media:content ' , ' ' , { ' url ' : item [ ' enclosure ' ] . url ,
' fileSize ' : item [ ' enclosure ' ] . length ,
' type ' : item [ ' enclosure ' ] . mime_type } )
2023-10-05 08:17:55 +00:00
2024-02-23 04:06:59 +00:00
2023-10-05 08:17:55 +00:00
# http://www.feedforall.com/itune-tutorial-tags.htm
# http://www.feedforall.com/mediarss.htm
class iTunesFeedType ( Rss201rev2Feed ) :
def root_attributes ( self ) :
attrs = super ( ) . root_attributes ( )
attrs [ ' xmlns:itunes ' ] = ' http://www.itunes.com/dtds/podcast-1.0.dtd '
attrs [ ' xmlns:atom ' ] = ' http://www.w3.org/2005/Atom '
attrs [ ' xmlns:media ' ] = ' http://search.yahoo.com/mrss/ '
# attrs['xmlns:dc'] = "http://purl.org/dc/elements/1.1/"
return attrs
def add_root_elements ( self , handler ) :
super ( ) . add_root_elements ( handler )
podcast_helper_add_root_elements ( self , handler )
def add_item_elements ( self , handler , item ) :
super ( ) . add_item_elements ( handler , item )
podcast_helper_add_item_elements ( self , handler , item )
class CastFeed ( CastFeedBase ) :
feed_type = iTunesFeedType
2023-10-13 01:47:49 +00:00
title = " The Corresponding Source (formerly Free as in Freedom) "
2023-10-05 08:17:55 +00:00
link = " /cast/ "
description = " A bi-weekly discussion of legal, policy, and other issues in the open source and software freedom community (including occasional interviews) from Brooklyn, New York, USA. Presented by Karen Sandler and Bradley M. Kuhn. "
author_email = " podcast@faif.us "
author_link = " http://www.faif.us/ "
2023-10-13 01:47:49 +00:00
author_name = " Software Freedom Conservancy "
2023-10-05 08:17:55 +00:00
title_template = " feeds/podcast_title.html "
description_template = " feeds/podcast_description.html "
2023-10-13 01:41:20 +00:00
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 )
2023-10-05 08:17:55 +00:00
def items ( self ) :
return Cast . objects . filter ( pub_date__lte = datetime . now ( ) ) . order_by ( ' -pub_date ' )
2023-10-13 01:41:20 +00:00
2023-10-05 08:17:55 +00:00
def item_pubdate ( self , item ) :
return item . pub_date
def item_link ( self , item ) :
return item . get_absolute_url ( )
def item_author_email ( self , obj ) :
return " oggcast@faif.us "
def item_author_name ( self , obj ) :
2023-10-13 02:08:16 +00:00
return " Software Freedom Conservancy "
2023-10-05 08:17:55 +00:00
def item_author_link ( self , obj ) :
return " http://faif.us "
def item_categories ( self , item ) :
2024-02-23 04:02:04 +00:00
return ( ' Technology ' , )
2023-10-05 08:17:55 +00:00
2023-10-13 02:08:16 +00:00
def copyright_holder ( self ) : return " Software Freedom Conservancy "
2023-10-05 08:17:55 +00:00
def license_no_html ( self ) : return " Licensed under a Creative Commons Attribution-Share Alike 3.0 USA License. "
def feed_extra_kwargs ( self , obj ) :
return for_podcast_feed_extra_kwargs ( self , obj )
def item_extra_kwargs ( self , item ) :
return for_podcast_item_extra_kwargs ( self , item )
2024-02-23 04:02:04 +00:00
# FIXME:
2023-10-05 08:17:55 +00:00
# GUEST NAME GOES HERE!!!
#<itunes:author>
# If applicable, at the item level, this tag can contain information
# about the person(s) featured on a specific episode.
class Mp3CastFeed ( CastFeed ) :
2024-02-23 04:06:59 +00:00
def item_enclosure_mime_type ( self ) :
return " audio/mpeg "
2023-10-05 08:17:55 +00:00
def item_enclosure_url ( self , item ) :
2023-10-13 01:41:20 +00:00
return add_domain ( self . current_site . domain , item . mp3_path , self . is_secure )
2024-02-23 04:06:59 +00:00
2023-10-05 08:17:55 +00:00
def item_enclosure_length ( self , item ) :
return item . mp3_length
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
class OggCastFeed ( CastFeed ) :
2024-02-23 04:06:59 +00:00
def item_enclosure_mime_type ( self ) :
return " audio/ogg "
2023-10-05 08:17:55 +00:00
def item_enclosure_url ( self , item ) :
2023-10-13 01:41:20 +00:00
return add_domain ( self . current_site . domain , item . ogg_path , self . is_secure )
2024-02-23 04:06:59 +00:00
2023-10-05 08:17:55 +00:00
def item_enclosure_length ( self , item ) :
return item . ogg_length
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
feed_dict = {
' cast-ogg ' : OggCastFeed ,
' cast-mp3 ' : Mp3CastFeed ,
}
# make each feed know its canonical url
for k , v in feed_dict . items ( ) :
v . get_absolute_url = ' /feeds/ %s / ' % k
2024-02-23 04:02:04 +00:00
2023-10-05 08:17:55 +00:00
def view ( request ) :
""" Listing of all available feeds
"""
feeds = feed_dict . values ( )
return render ( request , " feeds.html " , { ' feeds ' : feeds } )