I am trying to grab a piece of information about the length of a MP3 file from an RSS feed. Here is the Perl script I am hacking away at:
#!/usr/bin/perl use XML::Feed; use Data::Dumper; my $rssurl = "http://librivox.org/rss/4273"; my $feed = XML::Feed->parse(URI->new($rssurl)) or die XML::Feed->errstr; print $feed->title, "\n"; print $feed->description, "\n"; for my $entry ($feed->entries) { # print "entery is [$entry]\n"; # print Dumper( $entry ); print $entry->title, "\n"; print $entry->{'http://www.itunes.com/dtds/podcast-1.0.dtd +'}{'duration'} . "\n"; print $entry->duration . "\n"; }
When I run the script I get this output:
Conquest Over Time by SHAARA, Michael <p>Pat Travis, a spacer renowned for his luck, is suddenly quite o +ut of it. His job is to beat his competitors to sign newly-Contacted +human races to commercial contracts... But what can he do when he finds he's on a planet that consults as +trology for literally every major decision - and he has arrived on on +e of the worst-aspected days in history? Michael Shaara, later to write the Pulitzer-winning novel "The Kil +ler Angels", wrote this story for Fantastic Universe in 1956. (Summar +y by Mark F. Smith)</p> 1 - Section 1 Can't locate object method "duration" via package "XML::Feed::Entry::F +ormat::RSS" at ./get_feed.pl line 15.
If I add
print Dumper( $entry );
for debugging I can see this bit of data:
$VAR1 = bless( { 'entry' => { 'enclosure' => { 'length' => '9.6MB', 'url' => 'http://www. +archive.org/download/conquest_over_time_1005_librivox/conquestovertim +e_1_shaara_64kb.mp3', 'type' => 'audio/mpeg +' }, 'link' => 'http://www.archive.org/do +wnload/conquest_over_time_1005_librivox/conquestovertime_1_shaara_64k +b.mp3', 'item' => ' ', 'http://www.itunes.com/dtds/podcast- +1.0.dtd' => { + 'explicit' => 'No', + 'duration' => '00:20:00', + 'block' => 'No' + }, 'title' => '1 - Section 1' }, '_version' => '2.0' }, 'XML::Feed::Entry::Format::RSS' );
The piece of data I want is the duration '00:20:00'. How do I get that in my script? Thanks!

In reply to How to extract data from rss feed using XML::Feed by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.