ruby / rss

RSS reading and writing
BSD 2-Clause "Simplified" License
185 stars 36 forks source link

Is there any way to access unparsed tags? #45

Closed timuckun closed 1 year ago

timuckun commented 1 year ago

I have the following code

MINDSCAPE_FEED='https://rss.art19.com/sean-carrolls-mindscape'
URI.open(MINDSCAPE_FEED) do |rss|

  feed = RSS::Parser.parse(rss, ignore_unknown_element=true)

  puts "Title: #{feed.channel.title}"
  feed.items.each do |item|
    puts item.itunes_episode_type
  end
end

Is there any way to access the itunes::episodeType attribute? More generically is there a way to access tags that the parser doesn't know about?

olleolleolle commented 1 year ago

I learned a little more about itunes:episodeType at Apple's Help Page for their podcast RSS extensions.

Not answering your question: but guessing at a solution that changes the ruby/rss implementation!

Perhaps adding episodeType to the item section of the itunes-specific code in this repo would be a way to get the data? https://github.com/ruby/rss/blob/master/lib/rss/itunes.rb#L267 - I am suggesting that this list of tags could be extended to also know about the episodeType?

Hope this helps - and do make a PR if you feel you want to pursue it.

Here is an executable little script to work on this: ```rb require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'pry' end require 'open-uri' require 'pry' require 'rss' require 'uri' MINDSCAPE_FEED = 'https://rss.art19.com/sean-carrolls-mindscape' URI.open(MINDSCAPE_FEED) do |rss| feed = RSS::Parser.parse(rss, ignore_unknown_element = true) puts "Title: #{feed.channel.title}" feed.items.each do |item| binding.pry puts item.itunes_episode_type end end ``` Executable script
timuckun commented 1 year ago

I think that if there was a way to access a tag by name it would be a more generic solution so that the code doesn't have to change every time somebody decides to add a tag to their RSS feed.

Maybe even adding a hook where I could write a couple of lines of code would be OK.

kou commented 1 year ago

I've implemented it and released a new version.

We'll not provide accessors for unknown tags. It's by design.