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é
Note : must add a 'facebook_access_token' entry in the configuration for the module to work properly.
Loïc DEFRANCE a rédigéNote : must add a 'facebook_access_token' entry in the configuration for the module to work properly.
facebook.pm 1,22 Kio
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;