From d0709b8ee90c58bd43eb89e75ec9f63ae38e1c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20R=C3=A8gne?= Date: Wed, 16 Oct 2024 17:34:31 +0200 Subject: [PATCH] fix: Corriger le scraper de CBC Listen. --- src/core/scraper/cbclisten.js | 12 +++++++++++- test/unit/core/scraper/cbclisten.js | 9 ++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/core/scraper/cbclisten.js b/src/core/scraper/cbclisten.js index 24b217d8..b6cbe808 100644 --- a/src/core/scraper/cbclisten.js +++ b/src/core/scraper/cbclisten.js @@ -14,6 +14,14 @@ import { matchPattern } from "../tools/matchpattern.js"; */ const API_URL = "https://www.cbc.ca/listen/api/v1"; +/** + * Le nombre maximum qu'on peut demander à l'API retournant les clips. Cette + * valeur est égale à la valeur maximum pour un nombre entier signé sur 32 bits. + * + * @type {number} + */ +const MAX_PAGE_SIZE = 2_147_483_647; + /** * L'expression rationnelle pour extraire les identifiants du show et du clip. * @@ -46,7 +54,9 @@ const actionClip = async function ({ pathname }) { const type = Number(result.groups.type); const show = Number(result.groups.show); const clip = Number(result.groups.clip); - const response = await fetch(`${API_URL}/shows/${type}/${show}/clips`); + const response = await fetch( + `${API_URL}/shows/${type}/${show}/clips?pageSize=${MAX_PAGE_SIZE}`, + ); const json = await response.json(); return json.data?.clips.find((e) => e.clipID === clip)?.src; }; diff --git a/test/unit/core/scraper/cbclisten.js b/test/unit/core/scraper/cbclisten.js index 0efb0f58..4c29f849 100644 --- a/test/unit/core/scraper/cbclisten.js +++ b/test/unit/core/scraper/cbclisten.js @@ -41,7 +41,8 @@ describe("core/scraper/cbclisten.js", function () { assert.equal(stub.callCount, 1); assert.deepEqual(stub.firstCall.args, [ - "https://www.cbc.ca/listen/api/v1/shows/1/42/clips", + "https://www.cbc.ca/listen/api/v1/shows/1/42/clips" + + "?pageSize=2147483647", ]); }); @@ -68,7 +69,8 @@ describe("core/scraper/cbclisten.js", function () { assert.equal(stub.callCount, 1); assert.deepEqual(stub.firstCall.args, [ - "https://www.cbc.ca/listen/api/v1/shows/1/43/clips", + "https://www.cbc.ca/listen/api/v1/shows/1/43/clips" + + "?pageSize=2147483647", ]); }); @@ -95,7 +97,8 @@ describe("core/scraper/cbclisten.js", function () { assert.equal(stub.callCount, 1); assert.deepEqual(stub.firstCall.args, [ - "https://www.cbc.ca/listen/api/v1/shows/1/43/clips", + "https://www.cbc.ca/listen/api/v1/shows/1/43/clips" + + "?pageSize=2147483647", ]); }); });