Skip to content

Instantly share code, notes, and snippets.

@h-lame
Created August 1, 2010 20:04
Show Gist options
  • Save h-lame/503706 to your computer and use it in GitHub Desktop.
Save h-lame/503706 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'date'
#location = 'http://www.howdoesitfeel.co.uk/podcast.html'
location = './podcast.html'
podcast_page = Nokogiri::HTML(open(location))
titles = podcast_page.xpath(%q{//p[strong[contains(text(), 'HDIF Podcast')]]})
entries = titles.map do |title_elem|
title = title_elem.text
date = Date.strptime(title.split(' - ').last, '%d/%m/%y')
mp3_link = title_elem.xpath('./following-sibling::p[contains(text(), \'mp3\')]/a/@href').first.value
{:title => title, :date => date, :url => mp3_link}
end
puts %Q{<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>HDIF Podcast</title>
<link>http://www.howdoesitfeel.co.uk/podcast.html</link>
<ttl>40</ttl>
<language>en-gb</language>
<itunes:subtitle>The HDIF podcast</itunes:subtitle>
<itunes:author>Ian Watson</itunes:author>
<itunes:summary>I recently discovered that I had Garageband on my computer and that it could record podcasts, so I thought I'd give it a go. Here's the HDIF Podcast, a mix of indiepop and soul, with rambling commentary from yours truly.</itunes:summary>
<description>I recently discovered that I had Garageband on my computer and that it could record podcasts, so I thought I'd give it a go. Here's the HDIF Podcast, a mix of indiepop and soul, with rambling commentary from yours truly.</description>
<itunes:owner>
<itunes:name>Ian Watson</itunes:name>
<itunes:email>howdoesitfeel@btinternet.com</itunes:email>
</itunes:owner>
<itunes:image href="http://www.howdoesitfeel.co.uk/kissgoodnight62.jpg" />
<itunes:category text="Music" />
#{
entries.map do |entry|
%Q{ <item>
<title>#{entry[:title]}</title>
<itunes:subtitle>#{entry[:title]}</itunes:subtitle>
<pubDate>#{entry[:date].to_time.strftime('%a, %d %b %Y %H:%M:%S GMT')}</pubDate>
<guid>#{entry[:url]}</guid>
<link>#{entry[:url]}</link>
<enclosure url="#{entry[:url]}" type="audio/mpeg" length="100"/>
<itunes:keywords>music, indiepop</itunes:keywords>
</item>
}
end.join("\n")
}
</channel>
</rss>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment