summaryrefslogtreecommitdiff
path: root/lib/Multi/API.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2014-03-10 11:55:04 +0100
committerYorhel <git@yorhel.nl>2014-03-10 11:56:25 +0100
commit721d0868f36da2412bad4a1efdbd1abac36812bd (patch)
tree9ede9993c80aceacc591c7a9d73bb2a9122fb7a3 /lib/Multi/API.pm
parente13c14cdcff2af652f248f0c9b59a8631d69ede5 (diff)
Multi::API: Expose popularity, rating and votecount
http://vndb.org/t5121
Diffstat (limited to 'lib/Multi/API.pm')
-rw-r--r--lib/Multi/API.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index 673605ae..4775db43 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -463,11 +463,12 @@ sub get_vn {
my $get = $_[ARG0];
return cerr $get->{c}, getinfo => "Unknown info flag '$_'", flag => $_
- for (grep !/^(basic|details|anime|relations|tags)$/, @{$get->{info}});
+ for (grep !/^(basic|details|anime|relations|tags|stats)$/, @{$get->{info}});
my $select = 'v.id, v.latest';
$select .= ', vr.title, vr.original, v.c_released, v.c_languages::text[], v.c_olang::text[], v.c_platforms' if grep /basic/, @{$get->{info}};
$select .= ', vr.image, vr.img_nsfw, vr.alias AS aliases, vr.length, vr.desc AS description, vr.l_wp, vr.l_encubed, vr.l_renai' if grep /details/, @{$get->{info}};
+ $select .= ', v.c_popularity, v.c_rating, v.c_votecount' if grep /stats/, @{$get->{info}};
my @placeholders;
my $where = encode_filters $get->{filters}, \&filtertosql, $get->{c}, \@placeholders, [
@@ -544,6 +545,11 @@ sub get_vn_res {
};
$_->{image} = $_->{image} ? sprintf '%s/cv/%02d/%d.jpg', $VNDB::S{url_static}, $_->{image}%100, $_->{image} : undef;
}
+ if(grep /stats/, @{$get->{info}}) {
+ $_->{popularity} = 1 * sprintf '%.2f', 100*delete($_->{c_popularity}) || 0;
+ $_->{rating} = 1 * sprintf '%.2f', 0.1*delete($_->{c_rating}) || 0;
+ $_->{votecount} = 1 * delete $_->{c_votecount};
+ }
}
$get->{more} = pop(@$res)&&1 if @$res > $get->{opt}{results};
$get->{list} = $res;