Skip to content
Extraits de code Groupes Projets
Valider 12b0109c rédigé par Alexandre MORIGNOT's avatar Alexandre MORIGNOT
Parcourir les fichiers

Merge branch 'master' into 'master'

Spotify support



See merge request !1
parents 8a94628c 0cf164a3
Branches
Étiquettes
1 requête de fusion!1Spotify support
package PlayBot::sites::deezer;
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use FindBin;
my $conf;
my $endpoint = "https://api.deezer.com/track/";
sub regex
{
return qr#(?:^|[^!])https?://(?:www.)?deezer.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->{'title'};
$infos{'duration'} = $content->{'duration'};
$infos{'site'} = 'deezer';
$infos{'url'} = 'https://www.deezer.com/track/'.$id;
$infos{'author'} = $content->{'artist'}->{'name'};
return %infos;
}
1;
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.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;
...@@ -32,7 +32,7 @@ around 'BUILDARGS' => sub ...@@ -32,7 +32,7 @@ around 'BUILDARGS' => sub
if (not $row) if (not $row)
{ {
$sites = ['dailymotion', 'mixcloud', 'soundcloud', 'youtube']; $sites = ['dailymotion', 'mixcloud', 'soundcloud', 'youtube', 'spotify', 'deezer'];
$sth = $dbh->prepare(' $sth = $dbh->prepare('
insert into playbot_config (name, sites) insert into playbot_config (name, sites)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter