-
-
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.
feat: Ajouter le support de Metacafe.
- Loading branch information
Showing
7 changed files
with
93 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @module | ||
*/ | ||
/* eslint-disable require-await */ | ||
|
||
import { matchPattern } from "../../tools/matchpattern.js"; | ||
|
||
/** | ||
* Extrait les informations nécessaire pour lire une vidéo sur Kodi. | ||
* | ||
* @param {URL} _url L'URL d'une vidéo Metacafe. | ||
* @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>. | ||
*/ | ||
const action = async function (_url, content) { | ||
const doc = await content.html(); | ||
const script = doc.querySelector("script#json_video_data"); | ||
|
||
return JSON.parse(script.text).sources[0].src; | ||
}; | ||
export const extract = matchPattern(action, "*://www.metacafe.com/watch/*"); |
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,26 @@ | ||
import assert from "assert"; | ||
import { extract } from "../../../src/core/scrapers.js"; | ||
|
||
describe("Scraper: Metacafe", function () { | ||
it("should return URL when it's not a video", async function () { | ||
const url = "https://www.metacafe.com/galleries/62479" + | ||
"/just-let-these-pictures-do-the-explaining/305047/"; | ||
const options = { depth: 0, incognito: false }; | ||
const expected = url; | ||
|
||
const file = await extract(new URL(url), options); | ||
assert.strictEqual(file, expected); | ||
}); | ||
|
||
it("should return video URL", async function () { | ||
const url = "https://www.metacafe.com/watch/11516798" + | ||
"/even-the-horse-showed-it-s-sympathy-for" + | ||
"-the-girl-who-just-couldn-t-climb-up/"; | ||
const options = { depth: 0, incognito: false }; | ||
const expected = "https://cdn.mcstatic.com/videos/11516000/11516798" + | ||
"/11516798.m3u8"; | ||
|
||
const file = await extract(new URL(url), options); | ||
assert.strictEqual(file, expected); | ||
}); | ||
}); |
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,36 @@ | ||
import assert from "assert"; | ||
import { extract } from "../../../../src/core/scraper/metacafe.js"; | ||
|
||
describe("core/scraper/metacafe.js", function () { | ||
describe("extract()", function () { | ||
it("should return null when it's a unsupported URL", async function () { | ||
const url = "https://www.metacafe.com/galleries/foo"; | ||
const expected = null; | ||
|
||
const file = await extract(new URL(url)); | ||
assert.strictEqual(file, expected); | ||
}); | ||
|
||
it("should return video URL", async function () { | ||
const url = "https://www.metacafe.com/watch/foo"; | ||
const content = { | ||
html: () => Promise.resolve(new DOMParser().parseFromString(` | ||
<html> | ||
<body> | ||
<script id="json_video_data"> | ||
{ | ||
"sources": [{ | ||
"src": "https://bar.com/baz.mp4" | ||
}] | ||
} | ||
</script> | ||
</body> | ||
</html>`, "text/html")), | ||
}; | ||
const expected = "https://bar.com/baz.mp4"; | ||
|
||
const file = await extract(new URL(url), content); | ||
assert.strictEqual(file, expected); | ||
}); | ||
}); | ||
}); |