Skip to content

Commit 3f6958a

Browse files
committed
fix: Adapter le scraper au nouveau site onetv.
1 parent 4f6d934 commit 3f6958a

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

src/core/scraper/onetv.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
import { matchPattern } from "../../tools/matchpattern.js";
77

88
/**
9-
* Extrait les informations nécessaire pour lire une vidéo sur Kodi. Ce scraper
10-
* est similaire au scraper de l'Open Graph, mais il ne vérifie pas le type de
11-
* la vidéo car Первый канал (1tv.ru) n'indique pas le bon format
12-
* (<code>text/html</code> alors que la vidéo est un fichier <em>mp4</em>).
9+
* L'URL de l'API de Первый канал (1tv.ru).
1310
*
14-
* @param {URL} _url L'URL d'une page de Первый канал (1tv.ru).
15-
* @param {HTMLDocument} doc Le contenu HTML de la page.
11+
* @constant {string}
12+
*/
13+
const API_URL = "https://www.1tv.ru/playlist?single=true&video_id=";
14+
15+
/**
16+
* Extrait les informations nécessaire pour lire une vidéo sur Kodi.
17+
*
18+
* @param {URL} url L'URL d'une page embarquée de Первый канал (1tv.ru).
1619
* @returns {Promise.<?string>} Une promesse contenant le lien du
1720
* <em>fichier</em> ou <code>null</code>.
1821
*/
19-
const action = async function (_url, doc) {
20-
const meta = doc.querySelector(`meta[property="og:video:url"]`);
21-
return null === meta ? null
22-
: meta.content;
22+
const action = async function ({ pathname }) {
23+
const id = pathname.slice(7, pathname.indexOf(":"));
24+
const response = await fetch(API_URL + id);
25+
const json = await response.json();
26+
return "https:" + json[0].mbr[0].src;
2327
};
24-
export const extract = matchPattern(action, "*://www.1tv.ru/*");
28+
export const extract = matchPattern(action, "*://www.1tv.ru/embed/*");

test/integration/scraper/onetv.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("Scraper: Первый канал (1tv.ru)", function () {
1919
const expected = "https://balancer-vod.1tv.ru/video" +
2020
"/multibitrate/video/2019/06/03" +
2121
"/0535f134-80c9-40f2-af3b-6bb485488fe8" +
22-
"_20190604_Pozner_High_950.mp4";
22+
"_20190604_Pozner_High_3800.mp4";
2323

2424
const file = await extract(new URL(url), options);
2525
assert.strictEqual(file, expected);
@@ -32,7 +32,7 @@ describe("Scraper: Первый канал (1tv.ru)", function () {
3232
const expected = "https://balancer-vod.1tv.ru/video" +
3333
"/multibitrate/video/2019/05/26" +
3434
"/0bcc8f80-6082-4589-85b1-fcc000e150e9" +
35-
"_HD-news-2019_05_26-08_19_35_2923421_cut_950.mp4";
35+
"_HD-news-2019_05_26-08_19_35_2923421_cut_3800.mp4";
3636

3737
const file = await extract(new URL(url), options);
3838
assert.strictEqual(file, expected);

test/unit/core/scraper/onetv.js

+7-15
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,20 @@ describe("core/scraper/onetv.js", function () {
55
describe("extract()", function () {
66
it("should return null when there isn't Open Graph", async function () {
77
const url = "https://www.1tv.ru/foo.html";
8-
const doc = new DOMParser().parseFromString(`
9-
<html>
10-
<head></head>
11-
</html>`, "text/html");
128
const expected = null;
139

14-
const file = await extract(new URL(url), doc);
10+
const file = await extract(new URL(url));
1511
assert.strictEqual(file, expected);
1612
});
1713

1814
it("should return video URL", async function () {
19-
const url = "https://www.1tv.ru/foo.html";
20-
const doc = new DOMParser().parseFromString(`
21-
<html>
22-
<head>
23-
<meta property="og:video:url"
24-
content="http://bar.com/baz.mp4" />
25-
</head>
26-
</html>`, "text/html");
27-
const expected = "http://bar.com/baz.mp4";
15+
const url = "https://www.1tv.ru/embed/157535:12";
16+
const expected = "https://balancer-vod.1tv.ru/video/multibitrate" +
17+
"/video/2019/12/30" +
18+
"/9186df7c-9677-45e6-8de3-3f8bee109338" +
19+
"_HD-news-2020_01_01-23_28_05_3800.mp4";
2820

29-
const file = await extract(new URL(url), doc);
21+
const file = await extract(new URL(url));
3022
assert.strictEqual(file, expected);
3123
});
3224
});

0 commit comments

Comments
 (0)