Last active
March 9, 2017 02:40
-
-
Save jgaskins/72cfc3960339579c0b0f40f5d09be14c to your computer and use it in GitHub Desktop.
Parse a Podcast feed into episodes
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
class Episode | |
def self.from_rss_feed(url) | |
xml = Nokogiri.parse(Net::HTTP.get(URI(url))) | |
xml.xpath('//channel/item').map do |item| | |
new( | |
title: item.at_xpath('title').text, | |
subtitle: item.at_xpath('itunes:subtitle').text, | |
link: item.at_xpath('link').text, | |
audio_url: item.at_xpath('enclosure')[:url], | |
duration: item.at_xpath('itunes:duration').text | |
) | |
end | |
end | |
def initialize(title:, subtitle:, link:, audio_url:, duration:) | |
@title = title | |
@subtitle = subtitle | |
@link = link | |
@audio_url = audio_url | |
@duration = duration | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment