Skip to content

Commit 8339c9e

Browse files
committed
fix: Actualiser le scraper de Le Point.
1 parent af6555b commit 8339c9e

File tree

4 files changed

+38
-121
lines changed

4 files changed

+38
-121
lines changed

src/core/scraper/lepoint.js

+18-37
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,31 @@
22
* @module
33
*/
44

5-
// eslint-disable-next-line import/no-cycle
6-
import { extract as metaExtract } from "../scrapers.js";
5+
import * as plugin from "../plugin/dailymotion.js";
76
import { matchPattern } from "../tools/matchpattern.js";
87

98
/**
10-
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
9+
* Extrait les informations nécessaire pour lire une vidéo sur Kodi. Les pages
10+
* avec des vidéos Dailymotion contiennent des microdonnées, mais c'est l'URL de
11+
* la page embarquée de Dailymotion qui est renseignée dans le champ de l'URL
12+
* de la vidéo. Il faut donc récupérer l'identifiant de la vidéo Dailymotion
13+
* dans les balises HTML. Pour les vidéos YouTube, elles sont extraites
14+
* directement de l'iframe.
1115
*
12-
* @param {URL} url L'URL d'une vidéo du Point.
13-
* @param {Object} content Le contenu de l'URL.
14-
* @param {Function} content.html La fonction retournant la promesse
15-
* contenant le document HTML.
16-
* @param {Object} options Les options de l'extraction.
17-
* @param {boolean} options.depth La marque indiquant si l'extraction est
18-
* en profondeur.
19-
* @param {boolean} options.incognito La marque indiquant si l'utilisateur est
20-
* en navigation privée.
16+
* @param {URL} _url L'URL d'une vidéo du Point.
17+
* @param {Object} content Le contenu de l'URL.
18+
* @param {Function} content.html La fonction retournant la promesse contenant
19+
* le document HTML.
2120
* @returns {Promise<string|undefined>} Une promesse contenant le lien du
2221
* <em>fichier</em> ou
2322
* <code>undefined</code>.
2423
*/
25-
const action = async function (url, content, options) {
26-
if (options.depth) {
27-
return undefined;
28-
}
24+
const action = async function (_url, content) {
2925
const doc = await content.html();
30-
const div = doc.querySelector("div[data-video-src]");
31-
if (null !== div) {
32-
return metaExtract(new URL(div.dataset.videoSrc),
33-
{ ...options, depth: true });
34-
}
35-
36-
// Ne pas utiliser le scraper iframe car il est exécuté trop tard.
37-
// La page contient des microdonnées sur la vidéo, mais c'est l'URL de la
38-
// page embarquée de Dailymotion qui est renseignée dans le champ de l'URL
39-
// de la vidéo. Le scraper iframe étant exécuté après celui sur le ldjson,
40-
// il faut gérer l'iframe avant le scraper ldjson.
41-
for (const iframe of doc.querySelectorAll("iframe[src]")) {
42-
const file = await metaExtract(new URL(iframe.getAttribute("src"), url),
43-
{ ...options, depth: true });
44-
if (undefined !== file) {
45-
return file;
46-
}
47-
}
48-
49-
return undefined;
26+
const blockquote = doc.querySelector(
27+
"blockquote.video-dailymotion-unloaded[data-videoid]",
28+
);
29+
return null === blockquote ? undefined
30+
: plugin.generateUrl(blockquote.dataset.videoid);
5031
};
51-
export const extract = matchPattern(action, "https://www.lepoint.fr/*");
32+
export const extract = matchPattern(action, "*://www.lepoint.fr/*");

src/core/scrapers.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import * as kcaastreaming from "./scraper/kcaastreaming.js";
3434
import * as ldjson from "./scraper/ldjson.js";
3535
// eslint-disable-next-line import/no-cycle
3636
import * as lemonde from "./scraper/lemonde.js";
37-
// eslint-disable-next-line import/no-cycle
3837
import * as lepoint from "./scraper/lepoint.js";
3938
import * as media from "./scraper/media.js";
4039
import * as megaphone from "./scraper/megaphone.js";

test/integration/scraper/lepoint.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Scraper: Le Point", function () {
1616
assert.strictEqual(file, url.href);
1717
});
1818

19-
it("should return video URL [iframe-dailymotion]", async function () {
19+
it("should return video URL of Dailymotion", async function () {
2020
const url = new URL("https://www.lepoint.fr/astronomie" +
2121
"/un-nouveau-signal-radio-extraterrestre" +
2222
"-intrigue-les-scientifiques" +
@@ -30,6 +30,21 @@ describe("Scraper: Le Point", function () {
3030
"?mode=playVideo&url=x7rz0ur");
3131
});
3232

33+
it("should return video URL of Dailymotion when protocol is HTTP",
34+
async function () {
35+
const url = new URL("http://www.lepoint.fr/astronomie" +
36+
"/un-nouveau-signal-radio-extraterrestre" +
37+
"-intrigue-les-scientifiques" +
38+
"-18-02-2020-2363244_1925.php" +
39+
"#xtmc=video&xtnp=7&xtcr=61");
40+
const options = { depth: false, incognito: false };
41+
42+
const file = await extract(url, options);
43+
assert.strictEqual(file,
44+
"plugin://plugin.video.dailymotion_com/" +
45+
"?mode=playVideo&url=x7rz0ur");
46+
});
47+
3348
it("should return video URL [iframe-youtube]", async function () {
3449
const stub = sinon.stub(kodi.addons, "getAddons").resolves([]);
3550

test/unit/core/scraper/lepoint.js

+4-82
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import assert from "node:assert";
2-
import sinon from "sinon";
3-
import { kodi } from "../../../../src/core/kodi.js";
42
import * as scraper from "../../../../src/core/scraper/lepoint.js";
53

64
describe("core/scraper/lepoint.js", function () {
@@ -14,44 +12,12 @@ describe("core/scraper/lepoint.js", function () {
1412
});
1513

1614
it("should return undefined when it's not a video", async function () {
17-
const url = new URL("https://www.lepoint.fr/foo");
18-
const content = {
19-
html: () => Promise.resolve(new DOMParser().parseFromString(`
20-
<html>
21-
<body></body>
22-
</html>`, "text/html")),
23-
};
24-
const options = { depth: false, incognito: false };
25-
26-
const file = await scraper.extract(url, content, options);
27-
assert.strictEqual(file, undefined);
28-
});
29-
30-
it("should return undefined when it's depther", async function () {
3115
const url = new URL("https://www.lepoint.fr/foo");
3216
const content = {
3317
html: () => Promise.resolve(new DOMParser().parseFromString(`
3418
<html>
3519
<body>
36-
<div data-video-src="https://www.youtube.com/embed/baz">
37-
</div>
38-
</body>
39-
</html>`, "text/html")),
40-
};
41-
const options = { depth: true, incognito: false };
42-
43-
const file = await scraper.extract(url, content, options);
44-
assert.strictEqual(file, undefined);
45-
});
46-
47-
it("should return undefined when sub-page doesn't have media",
48-
async function () {
49-
const url = new URL("https://www.lepoint.fr/foo");
50-
const content = {
51-
html: () => Promise.resolve(new DOMParser().parseFromString(`
52-
<html>
53-
<body>
54-
<div data-video-src="http://bar.com/"></div>
20+
<blockquote></blockquote>
5521
</body>
5622
</html>`, "text/html")),
5723
};
@@ -61,38 +27,14 @@ describe("core/scraper/lepoint.js", function () {
6127
assert.strictEqual(file, undefined);
6228
});
6329

64-
it("should return video URL", async function () {
65-
const stub = sinon.stub(kodi.addons, "getAddons").resolves([]);
66-
67-
const url = new URL("https://www.lepoint.fr/foo");
68-
const content = {
69-
html: () => Promise.resolve(new DOMParser().parseFromString(`
70-
<html>
71-
<body>
72-
<div data-video-src="https://www.youtube.com/embed/baz">
73-
</div>
74-
</body>
75-
</html>`, "text/html")),
76-
};
77-
const options = { depth: false, incognito: false };
78-
79-
const file = await scraper.extract(url, content, options);
80-
assert.strictEqual(file,
81-
"plugin://plugin.video.youtube/play/" +
82-
"?video_id=baz&incognito=false");
83-
84-
assert.strictEqual(stub.callCount, 1);
85-
assert.deepStrictEqual(stub.firstCall.args, ["video"]);
86-
});
87-
88-
it("should return URL from iframe", async function () {
30+
it("should return URL", async function () {
8931
const url = new URL("https://www.lepoint.fr/foo");
9032
const content = {
9133
html: () => Promise.resolve(new DOMParser().parseFromString(`
9234
<html>
9335
<body>
94-
<iframe src="https://www.dailymotion.com/embed/video` +
95-
`/bar"></iframe>
36+
<blockquote class="video-dailymotion-unloaded"
37+
data-videoid="bar"></blockquote>
9638
</body>
9739
</html>`, "text/html")),
9840
};
@@ -103,25 +45,5 @@ describe("core/scraper/lepoint.js", function () {
10345
"plugin://plugin.video.dailymotion_com/" +
10446
"?mode=playVideo&url=bar");
10547
});
106-
107-
it("should return URL from second iframe", async function () {
108-
const url = new URL("https://www.lepoint.fr/foo");
109-
const content = {
110-
html: () => Promise.resolve(new DOMParser().parseFromString(`
111-
<html>
112-
<body>
113-
<iframe src="http://exemple.com/data.zip"></iframe>
114-
<iframe src="https://www.dailymotion.com/embed/video` +
115-
`/bar"></iframe>
116-
</body>
117-
</html>`, "text/html")),
118-
};
119-
const options = { depth: false, incognito: false };
120-
121-
const file = await scraper.extract(url, content, options);
122-
assert.strictEqual(file,
123-
"plugin://plugin.video.dailymotion_com/" +
124-
"?mode=playVideo&url=bar");
125-
});
12648
});
12749
});

0 commit comments

Comments
 (0)