Skip to content

Commit

Permalink
finished spec testing
Browse files Browse the repository at this point in the history
  • Loading branch information
frodwith committed Mar 18, 2011
1 parent ba89902 commit dc02f55
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 22 deletions.
4 changes: 3 additions & 1 deletion dist.ini
Expand Up @@ -3,14 +3,16 @@ author = Paul Driver <frodwith@cpan.org>
license = Perl_5
copyright_holder = Paul Driver <frodwith@cpan.org>
copyright_year = 2011
version = 0.01

[@Basic]
[PodWeaver]
[PkgVersion]
[AutoPrereqs]
[ReadmeFromPod]

[Git::NextVersion]
first_version = 0.01

[Prereqs]
XML::FeedPP = 0

Expand Down
43 changes: 26 additions & 17 deletions lib/XML/FeedPP/MediaRSS.pm
Expand Up @@ -259,14 +259,14 @@ A list of text objects in document order, like this:
{
allow => (1|0),
type => (country|uri|sharing|all|none),
list => [ ... ]
type => (country|uri|sharing)
list => [ ... ] | 'all' | 'none'
}
If allow is false, that means deny. If type is all or none, list will not
be present.
If allow is false, that means deny.
=cut

if (my $restriction = $find->('restriction')) {
my %r = (allow => $restriction->{'-relationship'} eq 'allow');
my @list;
Expand All @@ -275,15 +275,16 @@ A list of text objects in document order, like this:
}

if (grep { $_ eq 'all' } @list) {
$r{type} = 'all';
$r{list} = 'all';
}
elsif (@list < 1 || grep { $_ eq 'none' } @list) {
$r{type} = 'none';
$r{list} = 'none';
}
else {
$r{type} = $restriction->{'-type'};
$r{list} = \@list;
}
$r{type} = $restriction->{'-type'};
$hash{restriction} = \%r;
}

=mediakey community
Expand All @@ -309,11 +310,12 @@ Deepest only.
}
=cut

if (my $community = $find->('community')) {
my %c;
if (my $starRating = $community->{'media:starRating'}) {
$c{starRating} = $make_hash->(
$starRating, [], [qw(average min max)]
$starRating, [], [qw(average min max count)]
);
}
if (my $stats = $community->{'media:statistics'}) {
Expand All @@ -322,7 +324,7 @@ Deepest only.
);
}
if (my $tags = $community->{'media:tags'}) {
for (split /,\s*/, $tags->{'#text'}) {
for (split /,\s*/, $tags) {
s/^\s+//;
s/\s+$//;
s/:\s+/:/g;
Expand Down Expand Up @@ -350,12 +352,12 @@ Simple list of strings.

=mediakey embed
Hash of key-value pairs.
Hash of key-value pairs. Deepest only.
=cut

for my $embed ($find->('embed')) {
for my $param (@{ _force_array($embed->{'media:param'}) }) {
for my $param (@{ _force_array($embed, 'media:param') }) {
$hash{embed}{$param->{'-name'}} = $param->{'#text'};
}
}
Expand Down Expand Up @@ -383,19 +385,20 @@ Deepest only.
=cut

if (my $status = $find->('status')) {
$hash{status} = $make_hash->($status, [qw(state reason)], []);
$hash{status} = $make_hash->($status, ['state'], ['reason']);
}

=mediakey price
List of pricing structures, which are hashes with the keys C<currency>
(optional), C<info> (optional), and C<price> (optional). If none of these is
present for a given price tag, we're going to pretend it doesn't exist.
(optional), C<info> (optional), C<type> (optional), and C<price> (optional).
If none of these is present for a given price tag, we're going to pretend it
doesn't exist.
=cut

for my $price ($find->('price')) {
my $p = $make_hash->($price, [], [qw(price info currency)]);
my $p = $make_hash->($price, [], [qw(price info currency type)]);
push (@{ $hash{price} }, $p) if keys %$p;
}

Expand Down Expand Up @@ -464,8 +467,8 @@ end_time.
push @{$hash{scenes}}, {
title => $scene->{sceneTitle},
description => $scene->{sceneDescription},
start_time => $scene->{startTime},
end_time => $scene->{endTime},
start_time => $scene->{sceneStartTime},
end_time => $scene->{sceneEndTime},
};
}
}
Expand Down Expand Up @@ -508,6 +511,12 @@ __END__
}
}
=head1 ALPHA
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</GITHUB>.
=head1 DESCRIPTION
XML::FeedPP does not support Yahoo's MediaRSS extension, and it shouldn't.
Expand Down
144 changes: 140 additions & 4 deletions t/spec.t
@@ -1,7 +1,7 @@
use warnings;
use strict;

use Test::More;
use Test::More tests => 5;
use Test::Deep;
use XML::FeedPP;
use XML::FeedPP::MediaRSS;
Expand All @@ -11,9 +11,6 @@ sub spec_ok {
my $feed = XML::FeedPP->new($xml, -type => 'string', use_ixhash => 1);
my $media = XML::FeedPP::MediaRSS->new($feed);
my @got = map { $media->for_item($_) } ($feed->get_item);
use Data::Dumper::Concise;
print Dumper \@got;
print Dumper $expected;
cmp_deeply(\@got, noclass($expected), $note);
}

Expand Down Expand Up @@ -366,3 +363,142 @@ XML
];
spec_ok($xml, $expected, 'Same song with multiple files at different bitrates and encodings. (Bittorrent example as well)');
}

{
my $xml = <<'XML';
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Song Site</title>
<description>mRSS example with new fields added in v1.5.0</description>
<item>
<link>http://www.foo.com</link>
<pubDate>Mon, 27 Aug 2001 16:08:56 PST</pubDate>
<media:content url="http://www.foo.com/video.mov" fileSize="2000" bitrate="128" type="video/quicktime" expression="full"/>
<media:community>
<media:starRating average="3.5" count="20" min="1" max="10"/>
<media:statistics views="5" favorites="5"/>
<media:tags>news: 5, abc:3</media:tags>
</media:community>
<media:comments>
<media:comment>comment1</media:comment>
<media:comment>comment2</media:comment>
</media:comments>
<media:embed url="http://www.foo.com/player.swf" width="512" height="323" >
<media:param name="type">application/x-shockwave-flash</media:param>
<media:param name="width">512</media:param>
<media:param name="height">323</media:param>
<media:param name="allowFullScreen">true</media:param>
<media:param name="flashVars">id=12345&vid=678912i&lang=en-us&intl=us&thumbUrl=http://www.foo.com/thumbnail.jpg</media:param>
</media:embed>
<media:responses>
<media:response>www.response1.com</media:response>
<media:response>www.response2.com</media:response>
</media:responses>
<media:backLinks>
<media:backLink>www.backLink1.com</media:backLink>
<media:backLink>www.backLink2.com</media:backLink>
</media:backLinks>
<media:status state="active"/>
<media:price type="rent" price="19.99" currency="EUR" />
<media:license type="text/html" href="http://www.licensehost.com/license"> Sample license for a video </media:license>
<media:subTitle type="application/smil" lang="en-us" href="http://www.foo.org/subtitle.smil" />
<media:peerLink type="application/x-bittorrent " href="http://www.foo.org/sampleFile.torrent" />
<media:location description="My house" start="00:01" end="01:00">
<georss:where>
<gml:Point>
<gml:pos>35.669998 139.770004</gml:pos>
</gml:Point>
</georss:where>
</media:location>
<media:restriction type="sharing" relationship="deny" />
<media:scenes>
<media:scene>
<sceneTitle>sceneTitle1</sceneTitle>
<sceneDescription>sceneDesc1</sceneDescription>
<sceneStartTime>00:15</sceneStartTime>
<sceneEndTime>00:45</sceneEndTime>
</media:scene>
</media:scenes>
</item>
</channel>
</rss>
XML
my $expected = [
{
url => 'http://www.foo.com/video.mov',
fileSize => 2000,
bitrate => 128,
type => 'video/quicktime',
expression => 'full',
community => {
starRating => {
average => 3.5,
count => 20,
min => 1,
max => 10,
},
statistics => {
views => 5,
favorites => 5,
},
tags => {
news => 5,
abc => 3,
}
},
comments => [
'comment1',
'comment2',
],
embed => {
type => 'application/x-shockwave-flash',
width => 512,
height => 323,
allowFullScreen => 'true',
flashVars => 'id=12345&vid=678912i&lang=en-us&intl=us&thumbUrl=http://www.foo.com/thumbnail.jpg',
},
responses => [
'www.response1.com',
'www.response2.com',
],
backLinks => [
'www.backLink1.com',
'www.backLink2.com',
],
status => { state => 'active' },
price => [
{ price => 19.99, type => 'rent', currency => 'EUR' }
],
license => {
type => 'text/html',
href => 'http://www.licensehost.com/license',
name => ' Sample license for a video ',
},
subTitle => {
'en-us' => {
type => 'application/smil',
href => 'http://www.foo.org/subtitle.smil',
}
},
peerLink => {
type => 'application/x-bittorrent ',
href => 'http://www.foo.org/sampleFile.torrent',
},
restriction => {
allow => bool(0),
type => 'sharing',
list => 'none',
},
scenes => [
{
title => 'sceneTitle1',
description => 'sceneDesc1',
start_time => '00:15',
end_time => '00:45',
}
],
}
];
spec_ok($xml, $expected, 'Example using all the new elements added mRSS version 1.5.0.');
}

0 comments on commit dc02f55

Please sign in to comment.