|
2 | 2 | # encoding: utf-8 |
3 | 3 |
|
4 | 4 | module Fosdem |
| 5 | + def podcast_feed(params = {}) |
| 6 | + require 'builder' |
| 7 | + |
| 8 | + # Extract parameters |
| 9 | + events = params[:events] || [] |
| 10 | + excerpt_limit = params.fetch(:excerpt_limit) |
| 11 | + |
| 12 | + # Define how to find webm video once and reuse |
| 13 | + webm_link = lambda do |e| |
| 14 | + e[:links].find { |link| link[:title].start_with?('Video (WEBM)') } |
| 15 | + end |
| 16 | + |
| 17 | + # Filter and sort events by video publish date |
| 18 | + events.select!(&webm_link) |
| 19 | + events = events.sort_by do |e| |
| 20 | + webm_link.call(e)[:created_at] or |
| 21 | + raise RuntimeError.new("Cannot build Podcast RSS feed: event with id #{e[:event_id]} has a webm video link with no created_at attr") |
| 22 | + end.reverse |
| 23 | + |
| 24 | + # Check config attributes |
| 25 | + if @site.config[:base_url].nil? |
| 26 | + raise RuntimeError.new('Cannot build RSS feed: site configuration has no base_url') |
| 27 | + end |
| 28 | + |
| 29 | + last_update = webm_link.call(events.first)[:created_at] |
| 30 | + last_update = Date.parse(last_update).rfc822() # rss preferred format |
| 31 | + |
| 32 | + buffer = '' |
| 33 | + xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2) |
| 34 | + |
| 35 | + year = days.first[:conference_day].year.to_s |
| 36 | + title = "FOSDEM #{year}" |
| 37 | + description = 'Video recordings of FOSDEM talks - new episodes are released when videos become available. '\ |
| 38 | + 'FOSDEM is a free event for software developers to meet, share ideas and collaborate. '\ |
| 39 | + 'Every year, thousands of developers of free and open source software from all over the world gather at the event in Brussels.' |
| 40 | + organization = 'FOSDEM VZW' |
| 41 | + author_email = 'info@fosdem.org' |
| 42 | + author_email_rfc = "#{author_email} (FOSDEM Info)" |
| 43 | + root_url = @site.config[:base_url] |
| 44 | + year_url = root_url + "/#{year}" |
| 45 | + podcast_image = "#{year_url}/support/promote/box.png" |
| 46 | + |
| 47 | + # Build feed |
| 48 | + xml.instruct! |
| 49 | + xml.rss(version: '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom', |
| 50 | + 'xmlns:itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd', |
| 51 | + 'xmlns:podcast' => 'https://podcastindex.org/namespace/1.0') do |
| 52 | + xml.channel do |
| 53 | + xml.link "#{year_url}/" |
| 54 | + # http://validator.w3.org/appc/docs/warning/MissingAtomSelfLink.html |
| 55 | + xml.atom :link, href: root_url + @item.path, rel: 'self', type: 'application/rss+xml' |
| 56 | + xml.title title |
| 57 | + xml.description description |
| 58 | + xml.language 'en-us' |
| 59 | + xml.copyright "#{year} #{organization}" |
| 60 | + xml.podcast :locked, 'yes' |
| 61 | + xml.podcast :funding, |
| 62 | + 'While FOSDEM is primarily funded by sponsors and the sale of t-shirts, '\ |
| 63 | + 'we also gratefully accept voluntary donations.', |
| 64 | + url: "#{year_url}/support/donate/" |
| 65 | + xml.lastBuildDate(last_update) |
| 66 | + xml.pubDate(last_update) |
| 67 | + xml.ttl('1800') |
| 68 | + xml.image do |
| 69 | + xml.url podcast_image |
| 70 | + xml.title title |
| 71 | + xml.link "#{year_url}/" |
| 72 | + end |
| 73 | + xml.itunes :type, 'episodic' |
| 74 | + xml.itunes :subtitle, "All the recordings from this year's event in Brussels." |
| 75 | + xml.itunes :category, text: 'Technology' |
| 76 | + xml.itunes :author, organization |
| 77 | + xml.itunes :summary, description |
| 78 | + xml.itunes :image, href: podcast_image |
| 79 | + xml.itunes :owner do |
| 80 | + xml.itunes :name, organization |
| 81 | + xml.itunes :email, author_email |
| 82 | + end |
| 83 | + |
| 84 | + # Add event recordings as podcast items |
| 85 | + events.each do |e| |
| 86 | + video_link = webm_link.call(e) |
| 87 | + excerpt = excerpt_words(html_to_text(e[:abstract]), excerpt_limit) |
| 88 | + url = url_for(e) |
| 89 | + next if url.nil? |
| 90 | + |
| 91 | + xml.item do |
| 92 | + xml.title e[:title] |
| 93 | + xml.guid url |
| 94 | + xml.pubDate Date.parse(video_link[:created_at]).rfc822() |
| 95 | + xml.author author_email_rfc |
| 96 | + xml.link url |
| 97 | + xml.description excerpt |
| 98 | + xml.enclosure url: video_link[:url], type: 'video/webm' |
| 99 | + xml.podcast :transcript, url: video_link[:url].sub(/.av1.webm$/, '.vtt'), type: 'text/vtt' |
| 100 | + xml.itunes :episodetype, 'full' |
| 101 | + xml.itunes :author, organization |
| 102 | + unless e[:subtitle].to_s.strip.empty? |
| 103 | + xml.itunes :subtitle, e[:subtitle] |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + buffer |
| 111 | + end |
| 112 | + |
5 | 113 | def rss_feed(params = {}) |
6 | 114 | require 'builder' |
7 | 115 |
|
|
0 commit comments