summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Multi/Anime.pm26
-rw-r--r--lib/Multi/Core.pm13
-rw-r--r--lib/Multi/IRC.pm14
-rw-r--r--lib/Multi/Image.pm13
-rw-r--r--lib/Multi/Maintenance.pm8
5 files changed, 42 insertions, 32 deletions
diff --git a/lib/Multi/Anime.pm b/lib/Multi/Anime.pm
index 42bd52bf..0a7f5a08 100644
--- a/lib/Multi/Anime.pm
+++ b/lib/Multi/Anime.pm
@@ -66,6 +66,17 @@ sub spawn {
timeoutdelay => 0.4, # $delay = $msgdelay ^ (1 + $tm*$timeoutdelay)
maxtimeoutdelay => 2*3600, # two hours
cachetime => 30*24*3600, # one month
+ # AniDB anime types:
+ types => [
+ [ 'unknown', 'unknown', ],
+ [ 'TV', 'TV Series' ],
+ [ 'OVA', 'OVA' ],
+ [ 'Movie', 'Movie' ],
+ [ 'unknown', 'Other' ],
+ [ 'unknown', 'Web' ],
+ [ 'TV Special', 'TV Special' ],
+ [ 'unknown', 'Music Video' ],
+ ],
@_,
w => undef,
@@ -125,7 +136,7 @@ sub cmd_anime { # cmd, arg
}
if(@push) {
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = $s{anime} ? @{$s{anime}} : ();
push @q, grep {
@@ -143,7 +154,7 @@ sub cmd_anime { # cmd, arg
sub nextcmd {
return if $_[HEAP]{lm};
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
my @q = $s{anime} ? @{$s{anime}} : ();
undef $s;
@@ -188,8 +199,8 @@ sub nextcmd {
$_.'='.$cmd{$_}
} keys %cmd);
$_[HEAP]{w}->put({ payload => [ $cmd ]});
- $VNDB::DEBUG && printf " > %s\n", $cmd;
-
+
+ #$_[KERNEL]->call(core => log => 3, '> %s', $cmd);
$_[KERNEL]->delay(receivepacket => $_[HEAP]{timeout}, { payload => [ $_[HEAP]{tag}.' 100 TIMEOUT' ] });
$_[HEAP]{lm} = time;
}
@@ -208,7 +219,6 @@ sub receivepacket { # input, wheelid
} else {
$_[KERNEL]->call(core => log => 3, 'Received from AniDB after %.2fs: %d %s',
time-$_[HEAP]{lm}, $code, $msg);
- $VNDB::DEBUG && print ' < '.join("\n < ", @r)."\n";
}
# just handle anime data, even if the tag is not correct
@@ -263,8 +273,8 @@ sub updateanime { # aid, data|'notfound'
$_ =~ s/`/'/g;
}
$col[3] = $1 if $col[3] =~ /^([0-9]+)/; # remove multi-year stuff
- for(0..$#$VNDB::ANITYPE) {
- $col[4] = $_ if lc($VNDB::ANITYPE->[$_][1]) eq lc($col[4]);
+ for(0..$#{$_[HEAP]{types}}) {
+ $col[4] = $_ if lc($_[HEAP]{types}[$_][1]) eq lc($col[4]);
}
$col[4] = 0 if $col[4] !~ /^[0-9]+$/;
$col[2] = '' if $col[2] =~ /^0,/;
@@ -286,7 +296,7 @@ sub updateanime { # aid, data|'notfound'
undef, @col) if $r < 1;
# remove from queue
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = grep $_ != $_[ARG0], ($s{anime} ? @{$s{anime}} : ());
$s{anime} = \@q;
diff --git a/lib/Multi/Core.pm b/lib/Multi/Core.pm
index 74706910..7b2ae24b 100644
--- a/lib/Multi/Core.pm
+++ b/lib/Multi/Core.pm
@@ -56,7 +56,7 @@ sub heartbeat { # last beat
sub queue { # cmd
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = ( ($s{queue} ? @{$s{queue}} : ()), $_[ARG0] );
$s{queue} = \@q;
@@ -70,7 +70,7 @@ sub queue { # cmd
sub prepare { # determines whether to execute a new cmd
return if $Multi::STOP || $_[HEAP]{running};
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_SH);
if($s{queue} && @{$s{queue}}) {
$_[KERNEL]->yield(execute => $s{queue}[0]);
@@ -100,7 +100,7 @@ sub finish { # cmd
$_[KERNEL]->call(core => log => 2, "Unqueuing '%s' after %.2fs.",
$_[ARG0], tv_interval($_[HEAP]{starttime}));
- my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
+ my $s = tie my %s, 'Tie::ShareLite', -key => $VNDB::S{sharedmem_key}, -create => 'yes', -destroy => 'no', -mode => 0666;
$s->lock(LOCK_EX);
my @q = grep { $_ ne $_[ARG0] } $s{queue} ? @{$s{queue}} : ();
$s{queue} = \@q;
@@ -111,19 +111,16 @@ sub finish { # cmd
sub log { # level, msg
- return if $_[ARG0] > $Multi::LOGLVL;
+ return if $_[ARG0] > $VNDB::M{log_level};
(my $p = eval { $_[SENDER][2]{$_[CALLER_STATE]}[0] } || '') =~ s/^Multi:://;
my $msg = sprintf '(%s) %s::%s: %s',
(qw|WRN ACT DBG|)[$_[ARG0]-1], $p, $_[CALLER_STATE],
$_[ARG2] ? sprintf($_[ARG1], @_[ARG2..$#_]) : $_[ARG1];
- open(my $F, '>>', $Multi::LOGDIR.'/multi.log');
+ open(my $F, '>>', $VNDB::M{log_dir}.'/multi.log');
printf $F "[%s] %s\n", scalar localtime, $msg;
close $F;
-
- # (debug) log to stdout as well...
- $VNDB::DEBUG && printf "[%s] %s\n", scalar localtime, $msg;
}
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index 4a60f324..224b35d4 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -61,7 +61,7 @@ sub _start {
$_[HEAP]{irc}->plugin_add(
Logger => POE::Component::IRC::Plugin::Logger->new(
- Path => $Multi::LOGDIR,
+ Path => $VNDB::M{log_dir},
Private => 0,
Public => 1,
));
@@ -70,7 +70,7 @@ sub _start {
);
$_[HEAP]{irc}->plugin_add(
CTCP => POE::Component::IRC::Plugin::CTCP->new(
- version => $_[HEAP]{o}{ircname}.' v'.$VNDB::VERSION,
+ version => $_[HEAP]{o}{ircname}.' v'.$VNDB::S{version},
userinfo => $_[HEAP]{o}{ircname},
));
if($_[HEAP]{o}{pass}) {
@@ -175,9 +175,9 @@ sub vndbid { # dest, msg, force
# nf (normal format): x+ : x, id, title
# sf (sub format): x+.+ : x, id, subid, title, action2, title2
# ef (extended format): x+.+ : x, id, subid, action, title, action2, title2
- my $nf = BOLD.RED.'['.NORMAL.BOLD.'%s%d' .RED.']' .NORMAL.' %s ' .RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d'.NORMAL;
- my $sf = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']' .NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d.%3$d'.NORMAL;
- my $ef = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']'.NORMAL.RED.' %s'.NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::VNDBopts{root_url}.'/%1$s%2$d.%3$d'.NORMAL;
+ my $nf = BOLD.RED.'['.NORMAL.BOLD.'%s%d' .RED.']' .NORMAL.' %s ' .RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d'.NORMAL;
+ my $sf = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']' .NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d.%3$d'.NORMAL;
+ my $ef = BOLD.RED.'['.NORMAL.BOLD.'%s%d.%d'.RED.']'.NORMAL.RED.' %s'.NORMAL.' %s '.RED.'%s'.NORMAL.' %s '.RED.'@'.NORMAL.LIGHT_GREY.' '.$VNDB::S{url}.'/%1$s%2$d.%3$d'.NORMAL;
# get a list of possible IDs (a la sub summary in defs.pl)
my @id; # [ type, id, ref ]
@@ -272,7 +272,7 @@ sub shutdown {
sub cmd_info {
$_[KERNEL]->post(circ => privmsg => $_[DEST],
- 'Hello, I am HMX-12 Multi v'.$VNDB::VERSION.' made by the great Yorhel!');
+ 'Hello, I am HMX-12 Multi v'.$VNDB::S{version}.' made by the great Yorhel!');
}
@@ -316,7 +316,7 @@ sub cmd_vn { # $arg = search string
sprintf 'No results found for %s', $_[ARG]) if !@$res;
return $_[KERNEL]->post(circ => privmsg => $_[DEST],
sprintf 'Too many results found, see %s/v/search?q=%s',
- $VNDB::VNDBopts{root_url}, uri_escape_utf8($_[ARG])) if @$res > 5;
+ $VNDB::S{url}, uri_escape_utf8($_[ARG])) if @$res > 5;
$_[KERNEL]->yield(vndbid => $_[DEST], join(' ', map 'v'.$_->[0], @$res), 1);
}
diff --git a/lib/Multi/Image.pm b/lib/Multi/Image.pm
index fb712afd..fe3d411e 100644
--- a/lib/Multi/Image.pm
+++ b/lib/Multi/Image.pm
@@ -25,6 +25,9 @@ sub spawn {
heap => {
cvsize => [ 256, 400 ],
scrsize => [ 136, 102 ],
+ cvpath => $VNDB::ROOT.'/static/cv',
+ sfpath => $VNDB::ROOT.'/static/sf',
+ stpath => $VNDB::ROOT.'/static/st',
},
);
}
@@ -60,7 +63,7 @@ sub cmd_coverimage {
sub cv_process { # id
my $start = time;
- my $img = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{imgpath}, $_[ARG0]%100, $_[ARG0];
+ my $img = sprintf '%s/%02d/%d.jpg', $_[HEAP]{cvpath}, $_[ARG0]%100, $_[ARG0];
my $os = -s $img;
my $im = Image::Magick->new;
@@ -150,8 +153,8 @@ sub cmd_screenshot {
sub scr_process { # id
my $start = time;
- my $sf = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{sfpath}, $_[ARG0]%100, $_[ARG0];
- my $st = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $_[ARG0]%100, $_[ARG0];
+ my $sf = sprintf '%s/%02d/%d.jpg', $_[HEAP]{sfpath}, $_[ARG0]%100, $_[ARG0];
+ my $st = sprintf '%s/%02d/%d.jpg', $_[HEAP]{stpath}, $_[ARG0]%100, $_[ARG0];
# convert/compress full-size image
my $os = -s $sf;
@@ -208,8 +211,8 @@ sub scr_clean {
my($bytes, $items, $id) = (0, 0, 0);
while(($id) = $q->fetchrow_array) {
- my $f = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $id%100, $id;
- my $t = sprintf '%s/%02d/%d.jpg', $VNDB::VNDBopts{stpath}, $id%100, $id;
+ my $f = sprintf '%s/%02d/%d.jpg', $_[HEAP]{sfpath}, $id%100, $id;
+ my $t = sprintf '%s/%02d/%d.jpg', $_[HEAP]{stpath}, $id%100, $id;
$bytes += -s $f;
$bytes += -s $t;
$items++;
diff --git a/lib/Multi/Maintenance.pm b/lib/Multi/Maintenance.pm
index b5d51ea3..3c2cd042 100644
--- a/lib/Multi/Maintenance.pm
+++ b/lib/Multi/Maintenance.pm
@@ -114,10 +114,10 @@ sub unkanime {
sub logrotate {
- my $dir = sprintf '%s/old', $Multi::LOGDIR;
+ my $dir = sprintf '%s/old', $VNDB::M{log_dir};
mkdir $dir if !-d $dir;
- for (glob sprintf '%s/*', $Multi::LOGDIR) {
+ for (glob sprintf '%s/*', $VNDB::M{log_dir}) {
next if /^\./ || /~$/ || !-f;
my $f = /([^\/]+)$/ ? $1 : $_;
my $n = sprintf '%s/%s.%04d-%02d-%02d.gz', $dir, $f, (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3];
@@ -125,12 +125,12 @@ sub logrotate {
$_[KERNEL]->call(core => log => 1, 'Logs already rotated earlier today!');
return;
}
- open my $I, '<', sprintf '%s/%s', $Multi::LOGDIR, $f;
+ open my $I, '<', sprintf '%s/%s', $VNDB::M{log_dir}, $f;
open my $O, '>:gzip', $n;
print $O $_ while <$I>;
close $O;
close $I;
- open $I, '>', sprintf '%s/%s', $Multi::LOGDIR, $f;
+ open $I, '>', sprintf '%s/%s', $VNDB::M{log_dir}, $f;
close $I;
}
}