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

Merge branch 'master' into 'master'

Facebook video support

Note : must add a 'facebook_access_token' entry in the configuration for
the module to work properly.

See merge request !4
parents 8601bd9b 84f57180
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package PlayBot::sites::facebook;
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use FindBin;
my $conf;
my $endpoint = "https://graph.facebook.com/v2.5/";
BEGIN {
chdir "$FindBin::Bin/";
local $/;
open CONF, '<', 'playbot.conf';
my $json = <CONF>;
$conf = decode_json($json);
}
sub regex
{
return qr#(?:^|[^!])https?://(?:www.|)facebook.com/(?:video.php\?v=|.*/videos/)([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
.'?access_token='.$conf->{'facebook_access_token'}
.'&fields=title,from,permalink_url,length');
die($response->status_line) unless ($response->is_success);
my $content = decode_json($response->decoded_content);
die "Fuck Facebook." if (exists $content->{'error'} );
my %infos;
$infos{'title'} = $content->{'title'};
if (!exists $content->{'title'}) {
$infos{'title'} = 'Untitled';
}
$infos{'duration'} = $content->{'length'};
$infos{'site'} = 'facebook';
$infos{'url'} = 'https://www.facebook.com'.$content->{'permalink_url'};
$infos{'author'} = $content->{'from'}->{'name'};
return %infos;
}
1;
......@@ -32,7 +32,13 @@ around 'BUILDARGS' => sub
if (not $row)
{
$sites = ['dailymotion', 'mixcloud', 'soundcloud', 'youtube', 'spotify', 'deezer'];
$sites = ['dailymotion',
'mixcloud',
'soundcloud',
'youtube',
'spotify',
'deezer',
'facebook'];
$sth = $dbh->prepare('
insert into playbot_config (name, sites)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter