Skip to content

Commit

Permalink
fix: Corriger le scraper de CBC Listen.
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Oct 20, 2024
1 parent 8166b25 commit d0709b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/core/scraper/cbclisten.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
};
Expand Down
9 changes: 6 additions & 3 deletions test/unit/core/scraper/cbclisten.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]);
});

Expand All @@ -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",
]);
});

Expand All @@ -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",
]);
});
});
Expand Down

0 comments on commit d0709b8

Please sign in to comment.