Skip to content

Commit

Permalink
feat: Ajouter le support de Vidlox.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Apr 30, 2020
1 parent dc2d2c0 commit fd2222a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/core/scraper/vidlox.js
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/*");
2 changes: 2 additions & 0 deletions src/core/scrapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import * as ultimedia from "./scraper/ultimedia.js";
import * as veoh from "./scraper/veoh.js";
import * as video from "./scraper/video.js";
import * as videopress from "./scraper/videopress.js";
import * as vidlox from "./scraper/vidlox.js";
import * as vimeo from "./scraper/vimeo.js";
import * as vrtnu from "./scraper/vrtnu.js";
import * as youtube from "./scraper/youtube.js";
Expand Down Expand Up @@ -92,6 +93,7 @@ const SCRAPERS = [
ultimedia,
veoh,
videopress,
vidlox,
vimeo,
vrtnu,
youtube,
Expand Down
20 changes: 20 additions & 0 deletions test/integration/scraper/vidlox.js
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(...)`);
});
});
45 changes: 45 additions & 0 deletions test/unit/core/scraper/vidlox.js
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");
});
});
});

0 comments on commit fd2222a

Please sign in to comment.