Last active
December 10, 2015 11:18
-
-
Save timharding/4426461 to your computer and use it in GitHub Desktop.
A program that merges together the various archive and current
feeds for In Our Time with Melvyn Bragg and delivers one feed
with all the programmes ordered by broadcast date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a program that merges together the various archive and current | |
# feeds for In Our Time with Melvyn Bragg and delivers one feed | |
# with all the programmes ordered by broadcast date. | |
# this was very helpful | |
# http://www.subelsky.com/2007/08/roll-your-own-podcast-feed-with-rails.html | |
require 'rss' | |
require 'open-uri' | |
# take a list of feeds | |
urls = { | |
:iot => "http://downloads.bbc.co.uk/podcasts/radio4/iot/rss.xml", | |
:iotc => "http://downloads.bbc.co.uk/podcasts/radio4/iotc/rss.xml", | |
:ioth => "http://downloads.bbc.co.uk/podcasts/radio4/ioth/rss.xml", | |
:iotp => "http://downloads.bbc.co.uk/podcasts/radio4/iotp/rss.xml", | |
:iotr => "http://downloads.bbc.co.uk/podcasts/radio4/iotr/rss.xml", | |
:iots => "http://downloads.bbc.co.uk/podcasts/radio4/iots/rss.xml", | |
} | |
# handy for local testing, downloading the feeds is laggy | |
# download them | |
# urls.each_pair do |name, value| | |
# puts "#{name} => #{value}" | |
# system "curl #{value} > feeds/#{name}.xml" | |
# end | |
# urls = { | |
# :iot => "feeds/iot.xml" , | |
# :iotc => "feeds/iotc.xml", | |
# :ioth => "feeds/ioth.xml", | |
# :iotp => "feeds/iotp.xml", | |
# :iotr => "feeds/iotr.xml", | |
# :iots => "feeds/iots.xml" | |
# } | |
# grab all the items | |
feeds = {} | |
items = [] | |
urls.each_pair do |name, url| | |
open(url) do |rss| | |
feed = RSS::Parser.parse(rss) | |
feeds[name] = feed | |
items += feed.items | |
end | |
end | |
feed = feeds[:iot] | |
iotu_feed = RSS::Maker.make("2.0") do |maker| | |
channel = maker.channel | |
channel.title = feed.channel.title | |
channel.description = feed.channel.description | |
channel.link = feed.channel.link | |
channel.language = feed.channel.language | |
channel.copyright = feed.channel.copyright | |
channel.lastBuildDate = feed.channel.lastBuildDate | |
image = maker.image | |
image.url = feed.image.url | |
image.title = feed.image.title | |
channel.itunes_author = feed.channel.itunes_author | |
channel.itunes_owner.itunes_name = feed.channel.itunes_owner.itunes_name | |
channel.itunes_owner.itunes_email= feed.channel.itunes_owner.itunes_email | |
channel.itunes_keywords = feed.channel.itunes_keywords | |
channel.itunes_subtitle = feed.channel.itunes_subtitle | |
channel.itunes_summary = feed.channel.itunes_summary | |
# below is what iTunes uses for your "album art", different from RSS standard | |
channel.itunes_image = feed.channel.itunes_image.href | |
channel.itunes_explicit = "No" | |
# nested data that we don't need, let's call it too hard for now | |
# category = channel.itunes_categories.new_category | |
# category.text = feed.channel.itunes_categories.first.text ? | |
# category.new_itunes_category.text = "Literature" | |
maker.items.do_sort = true | |
items.each do |audio| | |
maker.items.new_item do |item| | |
item.title = audio.title | |
item.link = audio.link | |
item.itunes_keywords = audio.itunes_keywords | |
item.guid.content = audio.link | |
item.guid.isPermaLink = true | |
item.pubDate = audio.pubDate | |
item.description = audio.description | |
item.itunes_summary = audio.description | |
item.itunes_subtitle = audio.itunes_subtitle | |
item.itunes_explicit = "No" | |
item.itunes_author = audio.itunes_author | |
item.itunes_duration = audio.itunes_duration.value | |
item.enclosure.url = audio.link | |
item.enclosure.length = audio.enclosure.length | |
item.enclosure.type = 'audio/mpeg' | |
end | |
end | |
end | |
# publish them as an rss feed | |
puts iotu_feed.to_xml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment