broadcasts.slt2.rss 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #{
  2. local function date_rfc_822(time)
  3. if not time then time = os.time() end
  4. return os.date('%a, %d %b %Y %H:%M:%S %z', time)
  5. end
  6. local function x(name,value)
  7. if value then
  8. return '<'..name..'>'.. value:escape_xml() ..'</'..name..'>'
  9. else
  10. return ''
  11. end
  12. end
  13. assert(podcast, 'podcast')
  14. assert(podcast.id, 'podcast id')
  15. -- at first sort forward, oldest first (to get a meaningful, global episode counter):
  16. local bcs_all = podcast:broadcasts(function(a,b) return a < b end)
  17. local bcs = {}
  18. for num,bc in ipairs(bcs_all) do
  19. if 'file' == lfs.attributes(bc:enclosure():filename('mp3'), 'mode') then
  20. bc.number = num -- add an episode counter
  21. table.insert(bcs, bc)
  22. -- io.stderr:write(' +', num, ' ', bc.id, "\n")
  23. -- io.stderr:write('*')
  24. -- else
  25. -- io.stderr:write('.')
  26. end
  27. end
  28. -- io.stderr:write("\n")
  29. bcs_all = nil
  30. local bc_most_recent = nil
  31. -- then sort reverse, most recent first as rss wants it:
  32. table.sort(bcs, function(a,b) return a > b end)
  33. if #bcs then bc_most_recent = bcs[1] end
  34. }<?xml version="1.0" encoding="UTF-8"?>
  35. <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom">
  36. <channel>
  37. <link>#{= podcast:url('rss') }</link>
  38. <atom:link href="#{= podcast:url('rss') }" rel="self" type="application/rss+xml" />
  39. <title>📻 #{= podcast.title }</title>
  40. <itunes:subtitle>#{= podcast.subtitle }</itunes:subtitle>
  41. <description>#{= podcast.subtitle }</description>
  42. <itunes:summary>#{= podcast.subtitle }</itunes:summary>
  43. #{ 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 -->
  44. <image>
  45. <link>#{= podcast:url('rss') }</link>
  46. <title>📻 #{= podcast.title }</title>
  47. <url>#{= bc_most_recent:pbmi().DC_image }</url>
  48. </image>
  49. #{ if bc_most_recent:pbmi().DC_image then }
  50. <itunes:image href="#{= bc_most_recent:pbmi().DC_image }"/>
  51. #{ end }
  52. #{ end } <itunes:explicit>no</itunes:explicit>
  53. <language>de</language>
  54. <lastBuildDate>#{= date_rfc_822() }</lastBuildDate>
  55. <pubDate>#{= date_rfc_822() }</pubDate>
  56. #{
  57. for _,bc in ipairs(bcs) do
  58. local start = assert(bc:dtstart())
  59. local end_ = assert(bc:dtend())
  60. } <item>
  61. <title>##{= bc.number } #{= bc:pbmi().DC_title:escape_xml() }</title>
  62. #{= x('itunes:subtitle', bc:pbmi().DC_title_episode) }
  63. <description>#{= bc:pbmi().DC_description:escape_xml() }</description>
  64. #{ if bc:pbmi().DC_image and bc:pbmi().DC_image:len() > 0 then }
  65. <itunes:image href="#{= bc:pbmi().DC_image }"/>
  66. #{ end }
  67. <pubDate>#{= date_rfc_822(start) }</pubDate>
  68. <guid isPermaLink="true">#{= bc:url() }</guid>
  69. <itunes:duration>#{= os.difftime(end_,start) }</itunes:duration>
  70. <itunes:explicit>clean</itunes:explicit>
  71. #{= x('itunes:author', bc:pbmi().DC_creator) }
  72. <link>#{= bc:url() }</link>
  73. #{ if 'mp3' == bc:enclosure().state then
  74. local file_size = lfs.attributes(bc:enclosure():filename('mp3'), 'size')
  75. } <enclosure type="audio/mpeg" url="#{= bc:enclosure():url('mp3') }" length="#{= file_size }"/>
  76. #{ end } </item>
  77. #{ end } </channel>
  78. </rss>