Skip to content

Commit

Permalink
Refactor and expose internal method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 7, 2018
1 parent 51959cf commit ab0a1ac
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/metascraper-video-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ab0a1ac

Please sign in to comment.