Skip to content

Commit

Permalink
feat: Ajouter le support de Metacafe.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Mar 22, 2020
1 parent 817634b commit 3ef3aa5
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ des vidéos et des musiques sur **Kodi** :
- liens directs : *avi*, *mkv*, *mp3*, *flac*… et torrent / magnet ;
- 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 ;
Instagram, Jamendo, LiveLeak, Metacafe, Mixcloud, Mixer, My Cloud Player,
Overcast, PeerTube, Pippa, podCloud, PodMust, Radio, Radioline, Steam,
Streamable, TikTok, Ultimedia, Veoh, VideoPress, YT Home ;
- Allemagne : Arte ;
- Belgique : VRT NU ;
- États-Unis : KCAA Radio ;
Expand Down
2 changes: 1 addition & 1 deletion locales/en/amo_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
direct links: <em>avi</em>, <em>mkv</em>, <em>mp3</em>, <em>flac</em>, ... and torrent / magnet;
</li>
<li>
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;
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;
<ul>
<li>Germany: Arte;</li>
<li>Belgium: VRT NU;</li>
Expand Down
2 changes: 1 addition & 1 deletion locales/fr/amo_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
liens directs : <em>avi</em>, <em>mkv</em>, <em>mp3</em>, <em>flac</em>… et torrent / magnet ;
</li>
<li>
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 ;
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 ;
<ul>
<li>Allemagne : Arte ;</li>
<li>Belgique : VRT NU ;</li>
Expand Down
24 changes: 24 additions & 0 deletions src/core/scraper/metacafe.js
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/*");
2 changes: 2 additions & 0 deletions src/core/scrapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as gamekult from "./scraper/gamekult.js";
import * as iframe from "./scraper/iframe.js";
import * as kcaastreaming from "./scraper/kcaastreaming.js";
import * as ldjson from "./scraper/ldjson.js";
import * as metacafe from "./scraper/metacafe.js";
import * as mixcloud from "./scraper/mixcloud.js";
import * as mixer from "./scraper/mixer.js";
import * as mycloudplayers from "./scraper/mycloudplayers.js";
Expand Down Expand Up @@ -70,6 +71,7 @@ const SCRAPERS = [
full30,
gamekult,
kcaastreaming,
metacafe,
mixcloud,
mixer,
mycloudplayers,
Expand Down
26 changes: 26 additions & 0 deletions test/integration/scraper/metacafe.js
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);
});
});
36 changes: 36 additions & 0 deletions test/unit/core/scraper/metacafe.js
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);
});
});
});

0 comments on commit 3ef3aa5

Please sign in to comment.