Permalink
Browse files

Added 'facebook'.

  • Loading branch information...
marcomontalbano committed Sep 14, 2018
1 parent 304cf65 commit 502319e6343ce98df98307d2b992698a836a1456
View
@@ -1,2 +1,3 @@
NODE_ENV=development
CLOUDINARY_CLOUD_NAME=
FACEBOOK_ACCESS_TOKEN=
Binary file not shown.
View
@@ -85,6 +85,7 @@ <h2>Features</h2>
<p>List of supported video providers:</p>
<div class="providers">
<div class="provider"><i class="fas fa-check"></i><span>Youtube</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Facebook (low-quality)</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Dailymotion</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Vimeo</span></div>
</div>
@@ -0,0 +1,29 @@
import VideoProvider from '../VideoProvider';
import fetch from 'node-fetch';
const { FACEBOOK_ACCESS_TOKEN } = process.env;
// https://www.facebook.com/backintimetheparty/videos/1588846901182916/
export default class Facebook extends VideoProvider {
static get regex() {
return [
// - //www.facebook.com/backintimetheparty/videos/1588846901182916/
/https?\:\/\/www\.facebook\.com\/[\w]+\/videos\/([0-9]+)/,
// - //www.facebook.com/backintimetheparty/videos/description/1588846901182916/
/https?\:\/\/www\.facebook\.com\/[\w]+\/videos[\w/-]+\/([0-9]+)/,
];
}
getThumbnail_asUrl() {
// unfortunately the FACEBOOK_ACCESS_TOKEN is temporally and there is no way to get a quality thumbnail without a valid token.
if (FACEBOOK_ACCESS_TOKEN) {
return fetch(`https://graph.facebook.com/${this.getId()}?access_token=${FACEBOOK_ACCESS_TOKEN}&fields=title,description,updated_time,id,thumbnails`)
.then(response => response.json())
.then(json => json.thumbnails.data.filter(t => t.is_preferred)[0].uri)
}
return new Promise(resolve => resolve(`https://graph.facebook.com/${this.getId()}/picture`));
}
}
@@ -0,0 +1,21 @@
import Facebook from './Facebook';
describe('Facebook', () => {
it('"regex" must be correct.', () => {
expect(Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/1588846901182916/')).toBe('1588846901182916');
expect(Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/description/1588846901182916/')).toBe('1588846901182916');
});
it('all methods must work.', () => {
const url = 'https://www.facebook.com/backintimetheparty/videos/1588846901182916/';
const video = new Facebook(url);
// static methods
expect(Facebook.check(url)).toBe(true);
// instance methods
expect(video.getId()).toBe('1588846901182916');
expect(video.providerName).toBe('facebook');
expect(video.url).toBe(url);
});
})
@@ -43,9 +43,12 @@ export default class VideoProvider {
}
fetchCloudinary(url) {
const cloudinaryUrl = `http://res.cloudinary.com/${CLOUDINARY_CLOUD_NAME}/image/fetch/h_720/l_video_to_markdown:${this.providerName}_play,g_center/${url}`;
this.log('fetchCloudinary', cloudinaryUrl);
return fetch(cloudinaryUrl)
let fetchUrl = url;
if (CLOUDINARY_CLOUD_NAME) {
fetchUrl = `http://res.cloudinary.com/${CLOUDINARY_CLOUD_NAME}/image/fetch/h_720/l_video_to_markdown:${this.providerName}_play,g_center/${encodeURIComponent(url)}`;
}
this.log('fetchCloudinary', fetchUrl);
return fetch(fetchUrl)
.then(response => response.buffer())
}
@@ -2,6 +2,7 @@ export default class VideoWrapper {
static get videoProviders() {
return [
require('./Providers/Dailymotion'),
require('./Providers/Facebook'),
require('./Providers/Youtube'),
require('./Providers/Vimeo'),
];
@@ -5,5 +5,6 @@ describe('VideoWrapper', () => {
expect(VideoWrapper.create('https://www.dailymotion.com/video/x3ke49').providerName).toBe('dailymotion');
expect(VideoWrapper.create('https://vimeo.com/263856289').providerName).toBe('vimeo');
expect(VideoWrapper.create('https://www.youtube.com/watch?v=oRdzL2DX0yU').providerName).toBe('youtube');
expect(VideoWrapper.create('https://www.facebook.com/backintimetheparty/videos/1588846901182916/').providerName).toBe('facebook');
});
});
@@ -74,7 +74,7 @@ form {
.providers {
@include grid-row();
.provider {
@include grid-column((xxsmall: 1 of 1, small: 1 of 2, large: 1 of 3));
@include grid-column((xxsmall: 1 of 1, small: 1 of 2, large: 1 of 3, xlarge: 1 of 4));
cursor: default;
display: block;
.fa-check {

0 comments on commit 502319e

Please sign in to comment.