Mediarss support for xml::feedpp
version 0.02
use XML::FeedPP; my $feed = XML::FeedPP->new('http://a.media.rss/source'); my $media = XML::FeedPP::MediaRSS->new($feed); for my $i ( $feed->get_item ) { for my $content ( $media->for_item($i) ) { die "18 or over" if $content->{adult}; } }
XML::FeedPP does not support Yahoo's MediaRSS extension, and it shouldn't. It's only supported in some formats, and XML::FeedPP is a lowest-common-denominator kind of module. That said, sometimes you need to consume feeds with MediaRSS in them.
You have to pass in an XML::FeedPP object. \*(C`XML::FeedPP::MediaRSS\*(C' isn't a subclass of XML::FeedPP - it has one, and inspects its dirty innards (which is somewhat safe since they're produced by XML::TreePP) to find media content.
Pass in a feed item (the things returned by \*(C`$feed->get_item\*(C') and get back a list of \*(L"XML::FeedPP::MediaRSS::Content\*(R" objects.
1 or ''
A hash of all the ratings found, schema => rating.
A hash of all titles found, type => value.
An arrayref of all the keywords found. The comma-delimiting is undone and duplicates are removed.
All thumnails found, from most specific (deepest) to least specific. This means that if the channel has a thumbnail and the item has a thumbnail, you'll get the item first, then the channel. If there are multiple thumbnails at the same level, you'll get them in document order. Time coding is not considered. They look like this:
{ url => '...', width => 400, height => 300, time => 'timecode' }
Hash of scheme => plain contents of tag
Deepest only.
{ algorithm => 'md5', checksum => 'dfdec888b72151965a34b4b59031290a', }
Deepest only.
{ url => '...', height => 300, width => 400 }
Hash of scheme to role-hash, like this:
{ 'urn:ebu' => { actor => [ 'Julia Roberts', 'Tom Hanks', ], director => [ 'Stevan Spielberg', ] } }
Deepest only.
{ url => '...', text => '2005 Foobar Media' }
A list of text objects in document order, like this:
[ { type => 'plain', lang => 'en', start => 'timecode', end => 'timecode', text => 'The actual value', }, ]
{ allow => (1|0), type => (country|uri|sharing) list => [ ... ] | 'all' | 'none' }
If allow is false, that means deny.
Deepest only.
{ starRating => { average => 3.5, count => 20, min => 1, max => 10, }, statistics => { views => 5, favorites => 5, }, tags => { news => 5, abc => 3, reuters => undef, }, }
Simple list of strings.
Hash of key-value pairs. Deepest only.
Simple list of strings
Simple list of strings
Deepest only.
{ state => 'status', reason => 'reason' }
List of pricing structures, which are hashes with the keys \*(C`currency\*(C' (optional), \*(C`info\*(C' (optional), \*(C`type\*(C' (optional), and \*(C`price\*(C' (optional). If none of these is present for a given price tag, we're going to pretend it doesn't exist.
Hash of type, href, and name. Deepest only.
Only one per language as per the spec.
{ 'en_us' => { href => 'http://www.example.org/subtitle.smil', type => 'application/smil', } }
Deepest only, hash of type and href.
\s-1NOT\s0 \s-1SUPPORTED\s0, mostly cause I don't need it and I don't feel like reading the geoRSS spec right now. Patches welcome!
value of the status attribute for the deepest rights element.
Deepest only, list of hashes with keys title, description, start_time, and end_time.
This software hasn't yet been tested beyond the examples provided in the mRSS spec. Failing tests (even better, with patches that fix the failures) are very welcome! Fork and send a pull request on \*(L"\s-1GITHUB\s0\*(R".
These are blessed hashes, but you're allowed to look inside them. In fact, you're really supposed to. It's okay, don't be nervous.
The mapping from the MediaRSS spec (<http://video.search.yahoo.com/mrss>) to this hash is really straightforward. See the \*(L"\s-1KEYS\s0\*(R" section for more detail. The shallowness-rules talked about in the spec are applied, e.g. specifiers at higher levels are applied to lower level objects unless they have a more specific rule.
You don't have to (get to?) deal with media groups. All the content for an item gets flattened into one list. Future versions of this module may add support for media groups under a different method name (\*(C`groups_for_item\*(C') if anyone ever sends me a patch or I can ever find an actual use for it.
The MediaRSS spec says some things about order being dependent on document order. We go by the order we get things from XML::FeedPP's hashes, which will only be the same as document order if you \*(C`use_ixhash => 1\*(C' in the feed. And even then, content in media:groups will come before content outside them.
This module only supports reading MediaRSS information from a feed, not adding it. I might add this someday, but of course patches are welcome in the meantime.
This project is hosted on github at http://github.com/frodwith/XML-FeedPP-MediaRSS <http://github.com/frodwith/XML-FeedPP-MediaRSS>.
Paul Driver <[email protected]>
This software is copyright (c) 2011 by Paul Driver <[email protected]>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.