summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/docs/1116
-rw-r--r--lib/Multi/API.pm14
2 files changed, 29 insertions, 1 deletions
diff --git a/data/docs/11 b/data/docs/11
index 95259d61..b9f2bdb9 100644
--- a/data/docs/11
+++ b/data/docs/11
@@ -441,6 +441,21 @@ however still required.<br />
"original", string, original/official title, can be <b>null</b>.
</td>
</tr>
+ <tr>
+ <td>tags</td>
+ <td>tags</td>
+ <td>array of arrays</td>
+ <td>no</td>
+ <td>
+ (Possibly empty) list of tags linked to this VN. Each tag is represented as
+ an array with three elements:<br />
+ tag id (integer),<br />
+ score (number between 0 and 3),<br />
+ spoiler level (integer, 0=none, 1=minor, 2=major)<br />
+ Only tags with a positive score are included. Note that this list may be
+ relatively large - more than 50 tags for a VN is quite possible.
+ </td>
+ </tr>
</table>
<p>Sorting is possible on the 'id', 'title' and 'released' fields.</p><br />
@@ -1223,6 +1238,7 @@ however still required.<br />
<li>Added new 'get' types: votelist, vnlist and wishlist</li>
<li>Added 'set' command, with types: votelist, vnlist and wishlist</li>
<li>New error id: 'settype'</li>
+ <li>Added "tags" flag and member to "get vn"</li>
</ul>
<b>2.15</b>
<ul>
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index 491071a6..e09e368d 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -463,7 +463,7 @@ sub get_vn {
my $get = $_[ARG0];
return cerr $get->{c}, getinfo => "Unknown info flag '$_'", flag => $_
- for (grep !/^(basic|details|anime|relations)$/, @{$get->{info}});
+ for (grep !/^(basic|details|anime|relations|tags)$/, @{$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}};
@@ -576,6 +576,13 @@ sub get_vn_res {
$get->{relations} = 1;
}
+ elsif($get->{type} eq 'tags') {
+ for my $i (@{$get->{list}}) {
+ $i->{tags} = [ map [ $_->{id}*1, 1*sprintf('%.2f', $_->{score}), 1*sprintf('%.0f', $_->{spoiler}) ], grep $i->{id} == $_->{vid}, @$res ];
+ }
+ $get->{tags} = 1;
+ }
+
# fetch more results
my @ids = map $_->{latest}, @{$get->{list}};
my $ids = join ',', map '?', @ids;
@@ -590,6 +597,11 @@ sub get_vn_res {
JOIN vn v ON v.id = vl.vid2 JOIN vn_rev vr ON vr.id = v.latest WHERE vl.vid1 IN($ids) AND NOT v.hidden|,
\@ids, 'get_vn_res', { %$get, type => 'relations' });
+ @ids && !$get->{tags} && grep(/tags/, @{$get->{info}}) && return $_[KERNEL]->post(pg => query => qq|
+ SELECT vid, tag AS id, avg(CASE WHEN ignore THEN NULL ELSE vote END) as score, COALESCE(avg(CASE WHEN ignore THEN NULL ELSE spoiler END), 0) as spoiler
+ FROM tags_vn tv WHERE vid IN($ids) GROUP BY vid, id HAVING avg(CASE WHEN ignore THEN NULL ELSE vote END) > 0|,
+ [map $_->{id}, @{$get->{list}}], 'get_vn_res', { %$get, type => 'tags' });
+
# send results
delete $_->{latest} for @{$get->{list}};
$_[KERNEL]->yield(get_results => { %$get, type => 'vn' });