Skip to content

Instantly share code, notes, and snippets.

@rahulbot
Forked from crm114/itunes_to_rss.rb
Created February 19, 2020 09:33
Show Gist options
  • Save rahulbot/bbc9750d8b1456bfd6de59231a2ac873 to your computer and use it in GitHub Desktop.
Save rahulbot/bbc9750d8b1456bfd6de59231a2ac873 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
require 'httparty'
require 'nokogiri'
require '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.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
feed_url = ItunesToRSS.extract 'https://podcasts.apple.com/us/podcast/the-glenn-beck-program/id620967489'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment