Skip to content

Commit 3ef3aa5

Browse files
committedMar 22, 2020
feat: Ajouter le support de Metacafe.
1 parent 817634b commit 3ef3aa5

File tree

7 files changed

+93
-5
lines changed

7 files changed

+93
-5
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ des vidéos et des musiques sur **Kodi** :
1616
- liens directs : *avi*, *mkv*, *mp3*, *flac*… et torrent / magnet ;
1717
- YouTube, Twitch, Vimeo, SoundCloud ainsi que Ace Stream, Apple Podcasts,
1818
BitChute, Blog Talk Radio, Dailymotion, DevTube, Facebook, Flickr, Full30,
19-
Instagram, Jamendo, LiveLeak, Mixcloud, Mixer, My Cloud Player, Overcast,
20-
PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam, Streamable,
21-
TikTok, Ultimedia, Veoh, VideoPress, YT Home ;
19+
Instagram, Jamendo, LiveLeak, Metacafe, Mixcloud, Mixer, My Cloud Player,
20+
Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam,
21+
Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home ;
2222
- Allemagne : Arte ;
2323
- Belgique : VRT NU ;
2424
- États-Unis : KCAA Radio ;

‎locales/en/amo_description.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
direct links: <em>avi</em>, <em>mkv</em>, <em>mp3</em>, <em>flac</em>, ... and torrent / magnet;
55
</li>
66
<li>
7-
YouTube, Twitch, Vimeo, SoundCloud as well as Ace Stream, Apple Podcasts, BitChute, Blog Talk Radio, Dailymotion, DevTube, Facebook, Flickr, Full30, Instagram, Jamendo, LiveLeak, Mixcloud, Mixer, My Cloud Player, Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home;
7+
YouTube, Twitch, Vimeo, SoundCloud as well as Ace Stream, Apple Podcasts, BitChute, Blog Talk Radio, Dailymotion, DevTube, Facebook, Flickr, Full30, Instagram, Jamendo, LiveLeak, Metacafe, Mixcloud, Mixer, My Cloud Player, Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home;
88
<ul>
99
<li>Germany: Arte;</li>
1010
<li>Belgium: VRT NU;</li>

‎locales/fr/amo_description.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
liens directs : <em>avi</em>, <em>mkv</em>, <em>mp3</em>, <em>flac</em>… et torrent / magnet ;
55
</li>
66
<li>
7-
YouTube, Twitch, Vimeo, SoundCloud ainsi que Ace Stream, Apple Podcasts, BitChute, Blog Talk Radio, Dailymotion, DevTube, Facebook, Flickr, Full30, Instagram, Jamendo, LiveLeak, Mixcloud, Mixer, My Cloud Player, Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home ;
7+
YouTube, Twitch, Vimeo, SoundCloud ainsi que Ace Stream, Apple Podcasts, BitChute, Blog Talk Radio, Dailymotion, DevTube, Facebook, Flickr, Full30, Instagram, Jamendo, LiveLeak, Metacafe, Mixcloud, Mixer, My Cloud Player, Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam, Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home ;
88
<ul>
99
<li>Allemagne : Arte ;</li>
1010
<li>Belgique : VRT NU ;</li>

‎src/core/scraper/metacafe.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @module
3+
*/
4+
/* eslint-disable require-await */
5+
6+
import { matchPattern } from "../../tools/matchpattern.js";
7+
8+
/**
9+
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
10+
*
11+
* @param {URL} _url L'URL d'une vidéo Metacafe.
12+
* @param {object} content Le contenu de l'URL.
13+
* @param {Function} content.html La fonction retournant la promesse contenant
14+
* le document HTML.
15+
* @returns {Promise.<string>} Une promesse contenant le lien du
16+
* <em>fichier</em>.
17+
*/
18+
const action = async function (_url, content) {
19+
const doc = await content.html();
20+
const script = doc.querySelector("script#json_video_data");
21+
22+
return JSON.parse(script.text).sources[0].src;
23+
};
24+
export const extract = matchPattern(action, "*://www.metacafe.com/watch/*");

‎src/core/scrapers.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as gamekult from "./scraper/gamekult.js";
2222
import * as iframe from "./scraper/iframe.js";
2323
import * as kcaastreaming from "./scraper/kcaastreaming.js";
2424
import * as ldjson from "./scraper/ldjson.js";
25+
import * as metacafe from "./scraper/metacafe.js";
2526
import * as mixcloud from "./scraper/mixcloud.js";
2627
import * as mixer from "./scraper/mixer.js";
2728
import * as mycloudplayers from "./scraper/mycloudplayers.js";
@@ -70,6 +71,7 @@ const SCRAPERS = [
7071
full30,
7172
gamekult,
7273
kcaastreaming,
74+
metacafe,
7375
mixcloud,
7476
mixer,
7577
mycloudplayers,

‎test/integration/scraper/metacafe.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import assert from "assert";
2+
import { extract } from "../../../src/core/scrapers.js";
3+
4+
describe("Scraper: Metacafe", function () {
5+
it("should return URL when it's not a video", async function () {
6+
const url = "https://www.metacafe.com/galleries/62479" +
7+
"/just-let-these-pictures-do-the-explaining/305047/";
8+
const options = { depth: 0, incognito: false };
9+
const expected = url;
10+
11+
const file = await extract(new URL(url), options);
12+
assert.strictEqual(file, expected);
13+
});
14+
15+
it("should return video URL", async function () {
16+
const url = "https://www.metacafe.com/watch/11516798" +
17+
"/even-the-horse-showed-it-s-sympathy-for" +
18+
"-the-girl-who-just-couldn-t-climb-up/";
19+
const options = { depth: 0, incognito: false };
20+
const expected = "https://cdn.mcstatic.com/videos/11516000/11516798" +
21+
"/11516798.m3u8";
22+
23+
const file = await extract(new URL(url), options);
24+
assert.strictEqual(file, expected);
25+
});
26+
});

‎test/unit/core/scraper/metacafe.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import assert from "assert";
2+
import { extract } from "../../../../src/core/scraper/metacafe.js";
3+
4+
describe("core/scraper/metacafe.js", function () {
5+
describe("extract()", function () {
6+
it("should return null when it's a unsupported URL", async function () {
7+
const url = "https://www.metacafe.com/galleries/foo";
8+
const expected = null;
9+
10+
const file = await extract(new URL(url));
11+
assert.strictEqual(file, expected);
12+
});
13+
14+
it("should return video URL", async function () {
15+
const url = "https://www.metacafe.com/watch/foo";
16+
const content = {
17+
html: () => Promise.resolve(new DOMParser().parseFromString(`
18+
<html>
19+
<body>
20+
<script id="json_video_data">
21+
{
22+
"sources": [{
23+
"src": "https://bar.com/baz.mp4"
24+
}]
25+
}
26+
</script>
27+
</body>
28+
</html>`, "text/html")),
29+
};
30+
const expected = "https://bar.com/baz.mp4";
31+
32+
const file = await extract(new URL(url), content);
33+
assert.strictEqual(file, expected);
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)
Please sign in to comment.