diff --git a/PlayBot/sites/facebook.pm b/PlayBot/sites/facebook.pm new file mode 100644 index 0000000000000000000000000000000000000000..ca7564a223313373633342c070241688b4e78852 --- /dev/null +++ b/PlayBot/sites/facebook.pm @@ -0,0 +1,58 @@ +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; diff --git a/PlayBot/utils/db/chan.pm b/PlayBot/utils/db/chan.pm index 3a6c412255784c9ce1910fe41cca8689ee38fbf8..6e8506b923ecc161df4821023412a4103cb6b1fa 100644 --- a/PlayBot/utils/db/chan.pm +++ b/PlayBot/utils/db/chan.pm @@ -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)