-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Facebook video, closes #9
- Loading branch information
Jan Henning Thorsen
committed
Sep 17, 2020
1 parent
e71c8f1
commit ddfa18b
Showing
4 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package LinkEmbedder::Link::Facebook; | ||
use Mojo::Base 'LinkEmbedder::Link'; | ||
|
||
use Mojo::Util; | ||
|
||
has provider_name => 'Facebook'; | ||
has provider_url => sub { Mojo::URL->new('https://facebook.com') }; | ||
|
||
sub learn_p { | ||
my $self = shift; | ||
my $path = $self->url->path; | ||
return $self->_learn_from_video_p if $path->[0] and $path->[0] eq 'watch'; | ||
return $self->_learn_from_video_p if $path->[1] and $path->[1] eq 'videos'; | ||
return $self->SUPER::learn_p(@_); | ||
} | ||
|
||
sub _learn_from_video_p { | ||
my $self = shift; | ||
$self->template([__PACKAGE__, 'iframe.html.ep']); | ||
$self->type('rich'); | ||
return Mojo::Promise->resolve($self); | ||
} | ||
|
||
1; | ||
|
||
__DATA__ | ||
@@ iframe.html.ep | ||
<iframe class="le-rich le-provider-facebook" width="476" height="476" style="border:0;width:100%" frameborder="0" allowfullscreen src="https://www.facebook.com/plugins/video.php?<%== Mojo::Util::url_escape($l->url) %>&show_text=0&width=476"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use Mojo::Base -strict; | ||
use Test::More; | ||
use LinkEmbedder; | ||
|
||
plan skip_all => 'TEST_ONLINE=1' unless $ENV{TEST_ONLINE}; | ||
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS; | ||
|
||
my @urls = ( | ||
'https://www.facebook.com/watch/?v=2170684279662399', | ||
'https://www.facebook.com/HachikoDistrict/videos/2170684279662399/', | ||
); | ||
|
||
for my $url (@urls) { | ||
my $encoded_url = Mojo::Util::url_escape($url); | ||
|
||
LinkEmbedder->new->test_ok( | ||
$url => { | ||
provider_name => 'Facebook', | ||
provider_url => 'https://facebook.com', | ||
type => 'rich', | ||
version => '1.0', | ||
cache_age => 0, | ||
html => | ||
qr{<iframe class="le-rich le-provider-facebook" .* src="https://www\.facebook\.com/plugins/video\.php\?$encoded_url}, | ||
} | ||
); | ||
} | ||
|
||
done_testing; |