Skip to content

Commit 1a64a14

Browse files
committed
Detect extractors without HTTP request
1 parent 68ece2b commit 1a64a14

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

packages/metascraper-video-provider/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
},
1818
"dependencies": {
1919
"@metascraper/helpers": "^3.11.8",
20-
"cheerio": "~1.0.0-rc.2",
2120
"json-future": "~2.1.2",
2221
"lodash": "~4.17.10",
2322
"parse-domain": "~2.1.2",
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
'use strict'
22

3+
const parseDomain = require('parse-domain')
34
const jsonFuture = require('json-future')
4-
const cheerio = require('cheerio')
5-
const got = require('got')
5+
const youtubedl = require('youtube-dl')
6+
const { promisify } = require('util')
7+
8+
const getExtractors = promisify(youtubedl.getExtractors)
69

710
;(async () => {
8-
const { body } = await got('https://rg3.github.io/youtube-dl/supportedsites.html')
9-
const $ = cheerio.load(body)
10-
const set = new Set()
11+
const extractors = await getExtractors()
1112

12-
$('li').each(function (i, el) {
13-
const domain = $(el).text().split(':')[0].toLowerCase()
14-
set.add(domain)
15-
})
13+
const providers = extractors.reduce((set, extractor) => {
14+
const provider = extractor.split(':')[0].toLowerCase()
15+
const { domain = '' } = parseDomain(provider) || {}
16+
set.add(domain || provider)
17+
return set
18+
}, new Set())
1619

17-
await jsonFuture.saveAsync('providers.json', Array.from(set))
20+
await jsonFuture.saveAsync('providers.json', Array.from(providers))
1821
})()

0 commit comments

Comments
 (0)