From ab0a1ac7a26b0d19e04e4f04a1dd883d3e851bea Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sat, 7 Apr 2018 02:12:01 +0200 Subject: [PATCH] Refactor and expose internal method --- packages/metascraper-video-provider/index.js | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/metascraper-video-provider/index.js b/packages/metascraper-video-provider/index.js index ecd7cb1fe..d29e2a0e6 100644 --- a/packages/metascraper-video-provider/index.js +++ b/packages/metascraper-video-provider/index.js @@ -10,21 +10,28 @@ const PREFERRED_VIDEO_QUALITY = [ 'mobile' ] +const getVideoUrl = async ({ + browserless, + url, + preferredVideoQuality = PREFERRED_VIDEO_QUALITY +}) => { + const videoQualities = await getSocialVideoUrl({ url, browserless }) + const videoQuality = preferredVideoQuality.find(videoQuality => isUrl(videoQualities[videoQuality])) + return videoQualities[videoQuality] +} + module.exports = (opts = {}) => { - const { launchOpts = {}, preferredVideoQuality = PREFERRED_VIDEO_QUALITY } = opts + const { launchOpts = {}, preferredVideoQuality } = opts - const getVideoUrl = async ({ url }) => { + const fn = async ({url}) => { const browserless = await createBrowserless(launchOpts) - - const videoQualities = await getSocialVideoUrl({ url, browserless }) - const videoQuality = preferredVideoQuality.find(videoQuality => isUrl(videoQualities[videoQuality])) - const result = videoQualities[videoQuality] - + const result = await getVideoUrl({url, browserless, preferredVideoQuality}) const browserInstance = await browserless.browser await browserInstance.close() - return result } - return { video: getVideoUrl } + return { video: fn } } + +module.exports.getVideoUrl = getVideoUrl