Skip to content

Commit

Permalink
Avoid extract video for non supported domains
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 12, 2018
1 parent ab464ac commit 19792e6
Show file tree
Hide file tree
Showing 4 changed files with 818 additions and 38 deletions.
6 changes: 6 additions & 0 deletions packages/metascraper-video-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

const { round, size, get, chain, find, isString } = require('lodash')
const { isUrl, titleize } = require('@metascraper/helpers')
const parseDomain = require('parse-domain')
const youtubedl = require('youtube-dl')
const { promisify } = require('util')
const path = require('path')

const providers = require('./providers')

const getInfo = promisify(youtubedl.getInfo)

let cachedVideoInfoUrl
let cachedVideoInfo

const isSupportedProvided = url => providers.includes(parseDomain(url).domain)

/**
* Get the video info.
* Avoid do more one request for the same URL.
*/
const getVideoInfo = async url => {
if (!isSupportedProvided(url)) return {}
if (url === cachedVideoInfoUrl) return cachedVideoInfo
try {
const info = await getInfo(url)
Expand Down
7 changes: 5 additions & 2 deletions packages/metascraper-video-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@metascraper/helpers": "^3.9.3",
"lodash": "~4.17.5",
"parse-domain": "~2.0.0",
"youtube-dl": "~1.12.2"
},
"devDependencies": {
Expand All @@ -26,13 +27,15 @@
"nyc": "latest",
"should": "latest",
"snap-shot": "latest",
"standard": "latest"
"standard": "latest",
"time-span": "latest"
},
"engines": {
"node": ">= 8"
},
"files": [
"index.js"
"index.js",
"providers.js"
],
"scripts": {
"test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc mocha test"
Expand Down
Loading

0 comments on commit 19792e6

Please sign in to comment.