Skip to content

Instantly share code, notes, and snippets.

@crm114
Last active February 19, 2020 09:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save crm114/1d489e1c7b79b4cf107d to your computer and use it in GitHub Desktop.
Save crm114/1d489e1c7b79b4cf107d to your computer and use it in GitHub Desktop.
Get RSS feeds for iTunes Podcast links
# gem install httparty
# gem install nokogiri
# gem install feedjira
module ItunesToRSS
def self.extract(url)
headers = { 'User-Agent' => 'iTunes/10.1 (Windows; U; Microsoft Windows XP Home Edition Service Pack 2 (Build 2600)) DPI/96' }
base_url = 'http://itunes.apple.com/podcast/'
podcast_id = url.match(/id\d+/).to_s
itunes_response = HTTParty.get("#{base_url+podcast_id}", headers: headers)
if itunes_response.parsed_response.kind_of?(Hash)
detail_url = URI.extract(itunes_response.as_json.to_s).first
itunes_response = HTTParty.get(detail_url, headers: headers)
doc = Nokogiri::HTML(itunes_response.parsed_response)
feed_url = doc.css('button')[1].attributes['feed-url'].value
else
doc = Nokogiri::HTML(itunes_response.parsed_response)
feed_url = doc.css('button')[1].attributes['feed-url'].value
end
puts url
puts feed_url
return feed_url
end
end
# iTunes top 100 podcasts example
itunes_top100_url = 'https://itunes.apple.com/us/rss/toppodcasts/limit=100/explicit=true/xml'
top100 = Feedjira::Feed.fetch_and_parse itunes_top100_url
feeds = top100.entries.each do |entry|
url = entry.url
feed_url = ItunesToRSS.extract url
return { name: entry.title, feed_url: feed_url }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment