-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @module | ||
*/ | ||
/* eslint-disable require-await */ | ||
|
||
import { matchPattern } from "../../tools/matchpattern.js"; | ||
|
||
/** | ||
* L'expression rationnelle pour extraire l'URL de la vidéo. | ||
* | ||
* @constant {RegExp} | ||
*/ | ||
const URL_REGEXP = /sources: \["([^"]+)",/u; | ||
|
||
/** | ||
* Extrait les informations nécessaire pour lire une vidéo sur Kodi. | ||
* | ||
* @param {URL} _url L'URL d'une vidéo de Bigo Live. | ||
* @param {object} content Le contenu de l'URL. | ||
* @param {Function} content.html La fonction retournant la promesse contenant | ||
* le document HTML. | ||
* @returns {Promise.<?string>} Une promesse contenant le lien du | ||
* <em>fichier</em> ou <code>null</code>. | ||
*/ | ||
const action = async function (_url, content) { | ||
const doc = await content.html(); | ||
for (const script of doc.querySelectorAll("script:not([src])")) { | ||
const result = URL_REGEXP.exec(script.text); | ||
if (null === result) { | ||
continue; | ||
} | ||
|
||
return result[1]; | ||
} | ||
return null; | ||
}; | ||
export const extract = matchPattern(action, "*://vidlox.me/*"); |
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,20 @@ | ||
import assert from "assert"; | ||
import { extract } from "../../../src/core/scrapers.js"; | ||
|
||
describe("Scraper: Vidlox", function () { | ||
it("should return URL when it's not a video", async function () { | ||
const url = "https://vidlox.me/faq"; | ||
const options = { depth: 0, incognito: false }; | ||
|
||
const file = await extract(new URL(url), options); | ||
assert.strictEqual(file, url); | ||
}); | ||
|
||
it("should return video URL", async function () { | ||
const url = "https://vidlox.me/30fxi9o50b3v"; | ||
const options = { depth: 0, incognito: false }; | ||
|
||
const file = await extract(new URL(url), options); | ||
assert.ok(file.endsWith("/master.m3u8"), `"${file}".endsWith(...)`); | ||
}); | ||
}); |
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,45 @@ | ||
import assert from "assert"; | ||
import { extract } from "../../../../src/core/scraper/vidlox.js"; | ||
|
||
describe("core/scraper/vidlox.js", function () { | ||
describe("extract()", function () { | ||
it("should return null when it's a unsupported URL", async function () { | ||
const url = "https://twitter.com/vidloxtv"; | ||
|
||
const file = await extract(new URL(url)); | ||
assert.strictEqual(file, null); | ||
}); | ||
|
||
it("should return null when it's not a video", async function () { | ||
const url = "https://vidlox.me/foo"; | ||
const content = { | ||
html: () => Promise.resolve(new DOMParser().parseFromString(` | ||
<html> | ||
<body><script></script></body> | ||
</html>`, "text/html")), | ||
}; | ||
|
||
const file = await extract(new URL(url), content); | ||
assert.strictEqual(file, null); | ||
}); | ||
|
||
it("should return video URL", async function () { | ||
const url = "https://vidlox.me/foo"; | ||
const content = { | ||
html: () => Promise.resolve(new DOMParser().parseFromString(` | ||
<html> | ||
<body> | ||
<script> | ||
var player = new Clappr.Player({ | ||
sources: ["https://bar.baz/qux.m3u8","QUUX"] | ||
}) | ||
</script> | ||
</body> | ||
</html>`, "text/html")), | ||
}; | ||
|
||
const file = await extract(new URL(url), content); | ||
assert.strictEqual(file, "https://bar.baz/qux.m3u8"); | ||
}); | ||
}); | ||
}); |