123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #{
- local function date_rfc_822(time)
- if not time then time = os.time() end
- return os.date('%a, %d %b %Y %H:%M:%S %z', time)
- end
- local function x(name,value)
- if value then
- return '<'..name..'>'.. value:escape_xml() ..'</'..name..'>'
- else
- return ''
- end
- end
- assert(podcast, 'podcast')
- assert(podcast.id, 'podcast id')
- -- at first sort forward, oldest first (to get a meaningful, global episode counter):
- local bcs_all = podcast:broadcasts(function(a,b) return a < b end)
- local bcs = {}
- for num,bc in ipairs(bcs_all) do
- if 'file' == lfs.attributes(bc:enclosure():filename('mp3'), 'mode') then
- bc.number = num -- add an episode counter
- table.insert(bcs, bc)
- -- io.stderr:write(' +', num, ' ', bc.id, "\n")
- -- io.stderr:write('*')
- -- else
- -- io.stderr:write('.')
- end
- end
- -- io.stderr:write("\n")
- bcs_all = nil
- local bc_most_recent = nil
- -- then sort reverse, most recent first as rss wants it:
- table.sort(bcs, function(a,b) return a > b end)
- if #bcs then bc_most_recent = bcs[1] end
- }<?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>
- <link>#{= podcast:url('rss') }</link>
- <atom:link href="#{= podcast:url('rss') }" rel="self" type="application/rss+xml" />
- <title>📻 #{= podcast.title }</title>
- <itunes:subtitle>#{= podcast.subtitle }</itunes:subtitle>
- <description>#{= podcast.subtitle }</description>
- <itunes:summary>#{= podcast.subtitle }</itunes:summary>
- #{ if bc_most_recent and bc_most_recent:pbmi().DC_image and bc_most_recent:pbmi().DC_image:len() > 0 then } <!-- image of most recent enclosure -->
- <image>
- <link>#{= podcast:url('rss') }</link>
- <title>📻 #{= podcast.title }</title>
- <url>#{= bc_most_recent:pbmi().DC_image }</url>
- </image>
- #{ if bc_most_recent:pbmi().DC_image then }
- <itunes:image href="#{= bc_most_recent:pbmi().DC_image }"/>
- #{ end }
- #{ end } <itunes:explicit>no</itunes:explicit>
- <language>de</language>
- <lastBuildDate>#{= date_rfc_822() }</lastBuildDate>
- <pubDate>#{= date_rfc_822() }</pubDate>
- #{
- for _,bc in ipairs(bcs) do
- local start = assert(bc:dtstart())
- local end_ = assert(bc:dtend())
- } <item>
- <title>##{= bc.number } #{= bc:pbmi().DC_title:escape_xml() }</title>
- #{= x('itunes:subtitle', bc:pbmi().DC_title_episode) }
- <description>#{= bc:pbmi().DC_description:escape_xml() }</description>
- #{ if bc:pbmi().DC_image and bc:pbmi().DC_image:len() > 0 then }
- <itunes:image href="#{= bc:pbmi().DC_image }"/>
- #{ end }
- <pubDate>#{= date_rfc_822(start) }</pubDate>
- <guid isPermaLink="true">#{= bc:url() }</guid>
- <itunes:duration>#{= os.difftime(end_,start) }</itunes:duration>
- <itunes:explicit>clean</itunes:explicit>
- #{= x('itunes:author', bc:pbmi().DC_creator) }
- <link>#{= bc:url() }</link>
- #{ if 'mp3' == bc:enclosure().state then
- local file_size = lfs.attributes(bc:enclosure():filename('mp3'), 'size')
- } <enclosure type="audio/mpeg" url="#{= bc:enclosure():url('mp3') }" length="#{= file_size }"/>
- #{ end } </item>
- #{ end } </channel>
- </rss>
|