Skip to content

Commit

Permalink
build: exit early under non supported URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 18, 2019
1 parent 3752548 commit 9d9d632
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const {
const getInfo = promisify(youtubedl.getInfo)

const REGEX_RATE_LIMIT = /429: Too Many Requests/i

const REGEX_UNSUPPORTED_URL = /Unsupported URL/i
const REGEX_ERR_MESSAGE = /ERROR: (.*);?/

const isTwitterRateLimit = (url, err) =>
const isTwitterRateLimit = (err, url) =>
isTwitterUrl(url) && REGEX_RATE_LIMIT.test(err.message)

const isUnsupportedUrl = err => REGEX_UNSUPPORTED_URL.test(err.message)

const getFlags = ({ url, agent, userAgent, cacheDir }) => {
const flags = [
'--no-warnings',
Expand Down Expand Up @@ -73,7 +75,8 @@ module.exports = ({ tunnel, onError, userAgent, cacheDir }) => {
const err = makeError({ rawError, url, flags })
debug('getInfo:err', err.message)
onError(err, url)
if (!tunnel && isTwitterRateLimit(url, err)) return data
if (isUnsupportedUrl(err)) return data
if (!tunnel && isTwitterRateLimit(err, url)) return data
retry.incr()
}
} while (isEmpty(data) && hasTunnelAvailable())
Expand Down
25 changes: 15 additions & 10 deletions packages/metascraper-media-provider/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ const snapshot = require('snap-shot')
const should = require('should')
const isCI = require('is-ci')

const { PROXIES = '' } = process.env

const metascraper = require('metascraper')([
require('..')(),
require('..')({
proxies: PROXIES.split(',')
}),
require('metascraper-publisher')(),
require('metascraper-author')(),
require('metascraper-date')(),
Expand Down Expand Up @@ -48,15 +52,16 @@ describe('metascraper-media-provider', () => {
})
})
;(isCI ? describe.skip : describe)('vimeo', () => {
;['https://vimeo.com/channels/staffpicks/287117046', 'https://vimeo.com/186386161'].forEach(
url => {
it(url, async () => {
const metadata = await metascraper({ url })
console.log(metadata.video)
should(extension(metadata.video)).be.equal('mp4')
})
}
)
;[
'https://vimeo.com/channels/staffpicks/287117046',
'https://vimeo.com/186386161'
].forEach(url => {
it(url, async () => {
const metadata = await metascraper({ url })
console.log(metadata.video)
should(extension(metadata.video)).be.equal('mp4')
})
})
})

describe('youtube', () => {
Expand Down

0 comments on commit 9d9d632

Please sign in to comment.