-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(video): improve iframe detection (#683)
* refactor(media-provider): remove unnecessary dependency * fix(audio): only consider http URLs * fix(audio): mp4 audio only files * feat(video): improve iframe detection * test: update snapshot * fix: file name * test: update assertion * test: update snapshot
- Loading branch information
Showing
9 changed files
with
2,808 additions
and
1,707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
const { default: listen } = require('async-listen') | ||
const { createServer } = require('http') | ||
const { promisify } = require('util') | ||
const test = require('ava') | ||
|
||
const closeServer = server => promisify(server.close) | ||
|
||
const createMetascraper = (...args) => | ||
require('metascraper')([require('../src')(...args)]) | ||
|
||
test('absolute http', async t => { | ||
const server = createServer((_, res) => { | ||
res.setHeader('Content-Type', 'text/html') | ||
res.end( | ||
'<meta property="og:video" content="https://cdn.microlink.io/file-examples/sample.mp4">' | ||
) | ||
}) | ||
|
||
t.teardown(() => closeServer(server)) | ||
const url = (await listen(server, { port: 0, host: '0.0.0.0' })).toString() | ||
const html = `<iframe src="${url}">` | ||
const metascraper = createMetascraper() | ||
const metadata = await metascraper({ html, url }) | ||
t.is(metadata.video, 'https://cdn.microlink.io/file-examples/sample.mp4') | ||
}) | ||
|
||
test('relative http', async t => { | ||
const server = createServer((_, res) => { | ||
res.setHeader('Content-Type', 'text/html') | ||
res.end('<meta property="og:video" content="/file-examples/sample.mp4">') | ||
}) | ||
|
||
t.teardown(() => closeServer(server)) | ||
const url = (await listen(server, { port: 0, host: '0.0.0.0' })).toString() | ||
const html = '<iframe src="/">' | ||
const metascraper = createMetascraper() | ||
const metadata = await metascraper({ html, url }) | ||
t.is(metadata.video, url + 'file-examples/sample.mp4') | ||
}) | ||
|
||
test('ignore non http urls', async t => { | ||
const server = createServer((_, res) => { | ||
res.setHeader('Content-Type', 'text/html') | ||
res.end( | ||
'<meta property="og:video" content="tg://join?invite=n3gS0R7pjFJhMWM0">' | ||
) | ||
}) | ||
|
||
t.teardown(() => closeServer(server)) | ||
const url = (await listen(server, { port: 0, host: '0.0.0.0' })).toString() | ||
const html = `<iframe src="${url}">` | ||
const metascraper = createMetascraper() | ||
const metadata = await metascraper({ html, url }) | ||
t.is(metadata.video, null) | ||
}) |
Oops, something went wrong.