File size: 945 Bytes
b3787d8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import youtubeUrl from 'youtube-url';
import camelCaseRecursive from 'camelcase-keys-recursive';
import getYoutubeInfo from './getYoutubeInfo';
import getVimeoInfo from './getVimeoInfo';
import getVimeoId from './getVimeoId';
export default (videoUrl, cb) => {
if (youtubeUrl.valid(videoUrl)) {
getYoutubeInfo(videoUrl, (err, data) => {
if (err) {
cb(err);
return;
}
const videoData = camelCaseRecursive(data);
cb(null, videoData);
});
} else if (videoUrl.indexOf('vimeo.com') >= 0) {
const videoId = getVimeoId(videoUrl);
if (videoId) {
getVimeoInfo(videoId, (err, data) => {
if (err) {
cb(err);
return;
}
const videoData = {
thumbnailUrl: data.thumbnail_medium,
url: data.url,
title: data.title,
authorName: data.user_name,
};
cb(null, videoData);
});
}
}
};
|