cine-kids/cinecheck-adapter.js
2025-05-16 19:27:51 +02:00

76 lines
2.4 KiB
JavaScript

const axios = require('axios');
const cheerio = require('cheerio');
const CINECHECK_BASE = 'https://www.cinecheck.be';
async function searchMovies(query) {
const url = `${CINECHECK_BASE}/umbraco/surface/searchresults/search?query=${encodeURIComponent(query)}&producties=0&amount=5`;
const res = await axios.get(url, {
headers: {
'x-umb-culture': 'fr-BE',
'x-umb-key': '0a0c11a9-ece8-4dc8-8578-e5aab235d9ff',
'x-requested-with': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0',
}
});
const $ = cheerio.load(res.data);
const results = [];
$('.c-search__result').each((_, el) => {
const title = $(el).find('.c-search__title').text().trim().replace(/\s*\(.+?\)\s*$/, '');
const yearMatch = $(el).find('.c-search__title').text().match(/\((\d{4})\)/);
const year = yearMatch ? yearMatch[1] : null;
const imgSrc = $(el).find('img.c-search__image').attr('src')
? CINECHECK_BASE + $(el).find('img.c-search__image').attr('src')
: null;
const link = $(el).find('a.c-search__hiddenlink').attr('href')
? CINECHECK_BASE + $(el).find('a.c-search__hiddenlink').attr('href')
: null;
if (title && link) {
results.push({ title, year, imgSrc, link });
}
});
return results;
}
async function getMovieClassification(movieUrl) {
const res = await axios.get(movieUrl, {
headers: { 'User-Agent': 'Mozilla/5.0' }
});
const $ = cheerio.load(res.data);
const year = $('.c-movie__details .c-movie__label').first().text().trim() || null;
const genres = $('.c-movie__details .c-movie__label').eq(1).text().split(',').map(s => s.trim());
const img = $('.c-movie__cover img').attr('src')
? CINECHECK_BASE + $('.c-movie__cover img').attr('src')
: null;
const marks = [];
$('.c-header__marks .c-header__mark').each((_, el) => {
const label = $(el).find('span.vh').text().trim();
if (label) marks.push(label);
});
const details = [];
$('.c-classificatie__item').each((_, el) => {
const type = $(el).find('svg use').first().attr('xlink:href') || '';
const typeName = type.split('#')[1] || '';
const description = $(el).find('.js-classificatie-text').text().trim();
if (typeName && description) {
details.push({ type: typeName, description });
}
});
const summary = $('.c-movie__introtext p').first().text().trim();
return {
year,
genres,
img,
marks,
details,
summary
};
}
module.exports = { searchMovies, getMovieClassification };