ruby / rss

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

Error parsing <itunes:duration> when value is an integer. #20

Closed jmsalcido closed 3 years ago

jmsalcido commented 4 years ago

The example docs of the podcast from itunes returns an integer value: https://help.apple.com/itc/podcasts_connect/#/itcbaf351599

When trying to parse a file with that format (anchor.fm uses the integer value) you receive an error: See:

I uploaded the sample file from Apple here: https://gist.github.com/jmsalcido/30d76adba744e4e445331a6710136476

Still their own file is invalid... so, not possible to reproduce it with it.

Anyway I have a rss feed from Anchor.fm, and received this error while parsing it on my rails app:

RSS::NotAvailableValueError: value <1947> of tag <duration> is not available.
from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/itunes.rb:345:in `rescue in content='
Caused by ArgumentError: must be one of HH:MM:SS, H:MM:SS, MM::SS, M:SS: "1947"
from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/itunes.rb:282:in `parse'
[7] pry(main)>

If you want to replicate it, you can use my RSS feed from anchor.fm: https://anchor.fm/s/a6578b8/podcast/rss

irb(main):005:0> open(url) {|rss| RSS::Parser.parse(rss) }
Traceback (most recent call last):
       16: from (irb):5
       15: from (irb):5:in `rescue in irb_binding'
       14: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/open-uri.rb:35:in `open'
       13: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/open-uri.rb:736:in `open'
       12: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/open-uri.rb:169:in `open_uri'
       11: from (irb):5:in `block in irb_binding'
       10: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/parser.rb:88:in `parse'
        9: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/forwardable.rb:230:in `parse'
        8: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/parser.rb:183:in `parse'
        7: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/rexmlparser.rb:18:in `_parse'
        6: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rexml-3.2.4/lib/rexml/document.rb:242:in `parse_stream'
        5: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rexml-3.2.4/lib/rexml/parsers/streamparser.rb:36:in `parse'
        4: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/parser.rb:377:in `tag_end'
        3: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/parser.rb:550:in `block in setup_next_element'
        2: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/itunes.rb:342:in `content='
        1: from /home/jmsalcido/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rss/itunes.rb:345:in `rescue in content='
RSS::NotAvailableValueError (value <1327> of tag <duration> is not available.)

Same error while using irb.

kou commented 4 years ago

https://gist.github.com/jmsalcido/30d76adba744e4e445331a6710136476 is an invalid XML.

kou commented 4 years ago

Could you try rss 0.2.9 gem?

kou commented 3 years ago

0.2.9 will resolve this.