Skip to content

Commit 17e82ce

Browse files
Temporary work around for closeupfilmcentre.com cloudflare setup
1 parent bff72c5 commit 17e82ce

3 files changed

Lines changed: 47 additions & 19 deletions

File tree

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
11
const cheerio = require("cheerio");
2-
const { fetchText } = require("../../common/utils");
3-
const { domain } = require("./attributes");
2+
const getPageWithPlaywright = require("../../common/get-page-with-playwright");
3+
const { id, domain } = require("./attributes");
4+
5+
function isCloudflareChallenge(html) {
6+
return (
7+
html.includes("challenges.cloudflare.com") ||
8+
html.includes("cf_chl_opt") ||
9+
html.includes("Enable JavaScript and cookies to continue")
10+
);
11+
}
412

513
async function retrieve() {
614
const movieListPageUrl = `${domain}/search_film_programmes/`;
7-
const movieListPage = await fetchText(movieListPageUrl);
815

9-
const $ = cheerio.load(movieListPage);
16+
return getPageWithPlaywright(movieListPageUrl, id, async (page) => {
17+
await page.waitForLoadState();
18+
const movieListPage = await page.content();
1019

11-
const moviePageUrls = new Set();
12-
$(".inner_block_3 a").each(function () {
13-
const url = $(this).attr("href");
14-
moviePageUrls.add(url);
15-
});
20+
if (isCloudflareChallenge(movieListPage)) {
21+
console.log(
22+
" - ⚠️ Cloudflare challenge detected - falling back to sourced events",
23+
);
24+
return { movieListPage: "", moviePages: {} };
25+
}
1626

17-
const moviePages = {};
18-
for (const moviePageUrl of [...moviePageUrls]) {
19-
moviePages[moviePageUrl] = await fetchText(moviePageUrl);
20-
}
27+
const $ = cheerio.load(movieListPage);
28+
const moviePageUrls = new Set();
29+
$(".inner_block_3 a").each(function () {
30+
const url = $(this).attr("href");
31+
moviePageUrls.add(url);
32+
});
2133

22-
return {
23-
movieListPage,
24-
moviePages,
25-
};
34+
const moviePages = {};
35+
for (const moviePageUrl of [...moviePageUrls]) {
36+
await page.goto(moviePageUrl);
37+
await page.waitForLoadState("networkidle");
38+
moviePages[moviePageUrl] = await page.content();
39+
}
40+
41+
return { movieListPage, moviePages };
42+
});
2643
}
2744

2845
module.exports = retrieve;

cinemas/closeupfilmcentre.com/transform.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,18 @@ async function transform({ moviePages }, sourcedEvents) {
141141
});
142142

143143
if (movies.length === 0) {
144-
throw new Error("No movies found - the page structure may have changed");
144+
// The venue's website is behind a Cloudflare Turnstile challenge that
145+
// blocks automated retrieval. When that happens, we get empty `moviePages`
146+
// and fall back to events from the TicketSource source.
147+
// Only throw if TicketSource also has nothing, which would indicate a
148+
// genuine breakage rather than a Cloudflare block.
149+
const allSourcedEvents = Object.values(sourcedEvents).flatMap((e) => e);
150+
if (allSourcedEvents.length === 0) {
151+
throw new Error("No movies found - the page structure may have changed");
152+
}
153+
console.log(
154+
" - ⚠️ No movies from venue website - falling back to sourced events only",
155+
);
145156
}
146157

147158
const listOfSourcedEvents = Object.values(sourcedEvents).flatMap(

sources/bfi.org.uk-bfi-festivals/find-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function getAccessibilityFlagsForType(typeText) {
9292
if (typeText === "Descriptive Subtitles") {
9393
return { hardOfHearing: true };
9494
}
95-
if (typeText === "BSL") {
95+
if (typeText === "BSL" || typeText === "BSL intro / Q&A") {
9696
return { hardOfHearing: true };
9797
}
9898
if (typeText === "Live captioned") {

0 commit comments

Comments
 (0)