Media RSS parsing in Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • subeen
    New Member
    • Aug 2007
    • 8

    Media RSS parsing in Perl

    Hi,

    I am trying to parse a rss similar to the one found here (in example) http://www.feedforall.com/mediarss.htm

    <!-- Snipped for Brevity -->
    Code:
    <item>
    <title>FeedForAll's Show Tunes and Song</title>
    <link>http://www.feedforall.com/songs.htm</link>
    <description>FeedForAll cool show tunes and lyrics. </description>
    <media:group>
    <media:content url="http://www.feedorall.com/sample.mp3" fileSize="122345" type="audio/mpeg" isDefault="true" expression="sample" bitrate="128" framerate="24" duration="98" height="220" width="300" />
    <media:adult> false </media:adult>
    <media:title> FeedForAll file sample </media:title>
    <media:hash> dfdec888b72151965a34b4b59031290a </media:hash>
    <media:player url="http://www.feedforall.com/player" height="220" width="300" />
    <media:credit role="author"> J Housley </media:credit>
    <media:text type="plain"> FeedForAll supports name space extentions, specifically Yahoo's media RSS </media:text>
    </media:group>
    </item>
    <!--Snipped for Brevity-->

    Now I want to get media:title, media:player url etc. I am trying to use XML::RSS, but no luck yet :(

    Please help.

    Thanks,
    Subeen.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by subeen
    Hi,

    I am trying to parse a rss similar to the one found here (in example) http://www.feedforall.com/mediarss.htm

    <!-- Snipped for Brevity -->
    Code:
    <item>
    <title>FeedForAll's Show Tunes and Song</title>
    <link>http://www.feedforall.com/songs.htm</link>
    <description>FeedForAll cool show tunes and lyrics. </description>
    <media:group>
    <media:content url="http://www.feedorall.com/sample.mp3" fileSize="122345" type="audio/mpeg" isDefault="true" expression="sample" bitrate="128" framerate="24" duration="98" height="220" width="300" />
    <media:adult> false </media:adult>
    <media:title> FeedForAll file sample </media:title>
    <media:hash> dfdec888b72151965a34b4b59031290a </media:hash>
    <media:player url="http://www.feedforall.com/player" height="220" width="300" />
    <media:credit role="author"> J Housley </media:credit>
    <media:text type="plain"> FeedForAll supports name space extentions, specifically Yahoo's media RSS </media:text>
    </media:group>
    </item>
    <!--Snipped for Brevity-->

    Now I want to get media:title, media:player url etc. I am trying to use XML::RSS, but no luck yet :(

    Please help.

    Thanks,
    Subeen.
    Could you please post your code so that we can see what you have been trying thus far? Also, when posting your code, please do not forget the code tags as explained in the REPLY GUIDELINES to the right of the reply window.

    Regards,

    Jeff

    Comment

    • subeen
      New Member
      • Aug 2007
      • 8

      #3
      Here is what I am trying to do:
      Code:
      $rss->parse($raw);
      foreach my $item (@{$rss->{'items'}})
      {
      	$title = $item->{'title'};
      	$media_keywords = $item->{'media:keywords'};
      	print $title, "\n";
      	print $media_keywords, "\n";
      }
      It prints the title, but doesn't print the keywords.

      Comment

      • subeen
        New Member
        • Aug 2007
        • 8

        #4
        I have changed the code.

        Code:
        $rss->add_module(prefix=>'dc', uri=>"http://purl.org/dc/terms/");
        $rss->add_module(prefix=>'media', uri=>"http://search.yahoo.com/mrss");
        $rss->parse($raw);
        
        foreach my $item (@{$rss->{'items'}})
        {
            $title = $item->{'title'};
            $media_keywords = $item->{'media'}->{'keywords'};
            $media_player_url = $item->{'media'}->{'player'}->{'url'};
            print $title, "\n";
            print $media_keywords, "\n";
            print $media_player_url, "\n";
        }
        Now it prints the title & keywords, but doesn't print the media player url.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by subeen
          I have changed the code.

          Code:
          $rss->add_module(prefix=>'dc', uri=>"http://purl.org/dc/terms/");
          $rss->add_module(prefix=>'media', uri=>"http://search.yahoo.com/mrss");
          $rss->parse($raw);
          
          foreach my $item (@{$rss->{'items'}})
          {
              $title = $item->{'title'};
              $media_keywords = $item->{'media'}->{'keywords'};
              $media_player_url = $item->{'media'}->{'player'}->{'url'};
              print $title, "\n";
              print $media_keywords, "\n";
              print $media_player_url, "\n";
          }
          Now it prints the title & keywords, but doesn't print the media player url.
          Unfortunately, I know nothing about this module, but have you tried running the media player line as:

          [code=perl]
          $media_player_u rl = $item->{'media'}->{'player'};
          [/code]

          and see what it returns? I would play with it and see what happens. It may just be a formatting issue of the command.

          Regards,

          Jeff

          Comment

          Working...