Sélectionner une révision Git
Bifurcation depuis
Alexandre MORIGNOT / PlayBot
Le projet source a une visibilité limitée.
-
Loïc DEFRANCE a rédigéLoïc DEFRANCE a rédigé
spotify.pm 926 o
package PlayBot::sites::spotify;
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use FindBin;
my $conf;
my $endpoint = "https://api.spotify.com/v1/tracks/";
sub regex
{
return qr#(?:^|[^!])https?://(open|play).spotify.com/track/([a-zA-Z0-9_-]+)#;
}
sub get {
shift;
my $id = shift;
my $ua = LWP::UserAgent->new(
timeout => 30,
env_proxy => 1,
);
my $response = $ua->get($endpoint
.$id);
die($response->status_line) unless ($response->is_success);
my $content = decode_json($response->decoded_content);
# die "video not found" if (not scalar @{ $content->{items} });
my %infos;
$infos{'title'} = $content->{'name'};
$infos{'duration'} = $content->{'duration_ms'} / 1000;
$infos{'site'} = 'spotify';
$infos{'url'} = 'https://open.spotify/track/'.$id;
$infos{'author'} = $content->{'artists'}->[0]->{'name'};
return %infos;
}
1;