Sélectionner une révision Git
-
Alexandre Morignot a rédigé
If the external id is precised, it will be used to dynamically retrieves the URL when printing this content. This is useful for some source that change the content's URL (like soundcloud). Fuck soundcloud.
Alexandre Morignot a rédigéIf the external id is precised, it will be used to dynamically retrieves the URL when printing this content. This is useful for some source that change the content's URL (like soundcloud). Fuck soundcloud.
print.pm 3,00 Kio
package PlayBot::utils::print;
use strict;
use warnings;
use IRC::Utils qw(YELLOW ORANGE GREEN NORMAL LIGHT_BLUE GREY);
# Used to print a content.
# The public subroutine is print($content).
# arg :
# - $content : a ref to a hash with the following keys :
# - author
# - duration (in seconds)
# - external_id (optional)
# - id
# - site (if external_id)
# - tags : a ref to a list of tags
# - title
# - url
# returns :
# - a string well formated
sub print
{
my ($content) = @_;
if (defined($content->{external_id}) and defined($content->{site}))
{
my $site = 'PlayBot::sites::'.$content->{site};
eval "require $site";
eval { $content->{url} = $site->get_url($content->{external_id}) };
# TOOD: log if $@
}
my $msg = YELLOW.'['.$content->{'id'}.'] '.GREEN.$content->{'title'};
if (defined $content->{'author'})
{
$msg .= ' | '.$content->{'author'};
}
if (defined $content->{'duration'})
{
my $h = int($content->{'duration'} / 3600);
my $m = int(($content->{'duration'} % 3600) / 60);
my $s = int(($content->{'duration'} % 3600) % 60);
$msg .= LIGHT_BLUE.' (';
$msg .= sprintf("%02d:", $h) if ($h > 0);
$msg .= sprintf("%02d:", $m);
$msg .= sprintf("%02d", $s);
$msg .= ')'.NORMAL;
}
$msg .= ' => '.$content->{'url'}.ORANGE if (defined $content->{'url'});
if (defined $content->{'tags'})
{
$msg .= ' '.$_ foreach (@{$content->{'tags'}});
}
$msg .= GREY;
return $msg;
}
sub stats
{
# a utils::db::stats object;
my $stats = shift;