Compare commits
No commits in common. "main" and "v0.0.2" have entirely different histories.
@ -6,13 +6,13 @@
|
|||||||
"changelog": "file://CHANGELOG.md",
|
"changelog": "file://CHANGELOG.md",
|
||||||
"tagline": "Ciné-agrégateur multi-source pour enfants.",
|
"tagline": "Ciné-agrégateur multi-source pour enfants.",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"healthCheckPath": "/search",
|
"healthCheckPath": "/search?q=test",
|
||||||
"httpPort": 3000,
|
"httpPort": 3000,
|
||||||
"addons": {
|
"addons": {
|
||||||
"localstorage": {}
|
"localstorage": {}
|
||||||
},
|
},
|
||||||
"manifestVersion": 2,
|
"manifestVersion": 2,
|
||||||
"website": "https://cinekids.info",
|
"website": "https://zoemp.be/cine-kids",
|
||||||
"contactEmail": "morgan@zoemp.be",
|
"contactEmail": "morgan@zoemp.be",
|
||||||
"icon": "file://logo.png",
|
"icon": "file://logo.png",
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -45,11 +45,6 @@ async function getMovieClassification(movieUrl) {
|
|||||||
const label = $(el).find('span.vh').text().trim();
|
const label = $(el).find('span.vh').text().trim();
|
||||||
if (label) marks.push(label);
|
if (label) marks.push(label);
|
||||||
});
|
});
|
||||||
const normalizedMarks = marks.map(m => {
|
|
||||||
// Extract first number found, else null
|
|
||||||
const n = parseInt((m + '').replace(/\D/g, ''), 10);
|
|
||||||
return isNaN(n) ? null : n;
|
|
||||||
}).filter(x => x !== null);
|
|
||||||
const details = [];
|
const details = [];
|
||||||
$('.c-classificatie__item').each((_, el) => {
|
$('.c-classificatie__item').each((_, el) => {
|
||||||
const type = $(el).find('svg use').first().attr('xlink:href') || '';
|
const type = $(el).find('svg use').first().attr('xlink:href') || '';
|
||||||
@ -66,7 +61,6 @@ async function getMovieClassification(movieUrl) {
|
|||||||
genres,
|
genres,
|
||||||
img,
|
img,
|
||||||
marks,
|
marks,
|
||||||
normalizedMarks,
|
|
||||||
details,
|
details,
|
||||||
summary
|
summary
|
||||||
};
|
};
|
||||||
|
@ -36,4 +36,3 @@ echo "Version bumped to $NEW_VERSION"
|
|||||||
git add VERSION
|
git add VERSION
|
||||||
git tag "v$MAJOR.$MINOR.$PATCH"
|
git tag "v$MAJOR.$MINOR.$PATCH"
|
||||||
git push origin "v$MAJOR.$MINOR.$PATCH"
|
git push origin "v$MAJOR.$MINOR.$PATCH"
|
||||||
git push origin --tags
|
|
||||||
|
BIN
doc/demo.webp
BIN
doc/demo.webp
Binary file not shown.
Before Width: | Height: | Size: 462 KiB After Width: | Height: | Size: 71 KiB |
99
merge.js
99
merge.js
@ -1,94 +1,29 @@
|
|||||||
|
// Utilitaire pour merger les résultats de plusieurs agrégateurs
|
||||||
function normalizeTitle(str) {
|
function normalizeTitle(str) {
|
||||||
return str ? str.toLowerCase().replace(/[^a-z0-9 ]/g, '') : '';
|
return str ? str.toLowerCase().replace(/[^a-z0-9]/g, '') : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasSignificantWordOverlap(a, b) {
|
function normalizeTitle(str) {
|
||||||
const skipWords = new Set(['the','le','la','les','de','du','des','and','et','a','an','un','une','dans','en','on']);
|
return str ? str.toLowerCase().replace(/[^a-z0-9]/g, '') : '';
|
||||||
const aw = normalizeTitle(a).split(/\s+/).filter(w => w.length > 3 && !skipWords.has(w));
|
|
||||||
const bw = normalizeTitle(b).split(/\s+/).filter(w => w.length > 3 && !skipWords.has(w));
|
|
||||||
const overlap = aw.filter(w => bw.includes(w));
|
|
||||||
if (overlap.length > 0) {
|
|
||||||
console.log(`[MERGE] Overlap: "${a}" <-> "${b}" | Words: ${overlap.join(', ')}`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
function mergeResults(arrays) {
|
||||||
// Compute match score: exact > startsWith > includes > other
|
const map = {};
|
||||||
function getMatchScore(film, query) {
|
|
||||||
const nTitle = normalizeTitle(film.title);
|
|
||||||
const nQuery = normalizeTitle(query);
|
|
||||||
if (nTitle === nQuery) return 100;
|
|
||||||
if (nTitle.startsWith(nQuery)) return 80;
|
|
||||||
if (nTitle.includes(nQuery)) return 60;
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
function stripSeason(title) {
|
|
||||||
return normalizeTitle(title).replace(/(saison|season)\s*\d+/g, '').trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeResults(arrays, query = '', limit = 5) {
|
|
||||||
const merged = [];
|
|
||||||
arrays.flat().forEach(entry => {
|
arrays.flat().forEach(entry => {
|
||||||
const entryYear = entry.year ? entry.year.toString() : '';
|
// Note: only title, fallback if no year
|
||||||
let foundIdx = -1;
|
const key = normalizeTitle(entry.title) + (entry.year ? '|' + entry.year : '');
|
||||||
for (let i = 0; i < merged.length; i++) {
|
if (!map[key]) {
|
||||||
const m = merged[i];
|
map[key] = {
|
||||||
|
|
||||||
// Regroup series/seasons from same source if base title matches (strip "season X"/"saison X")
|
|
||||||
const isSeason = /saison|season/i.test(entry.title) && /saison|season/i.test(m.title);
|
|
||||||
if (
|
|
||||||
m.results[0] && m.results[0].source === entry.source &&
|
|
||||||
isSeason &&
|
|
||||||
stripSeason(m.title) === stripSeason(entry.title)
|
|
||||||
) {
|
|
||||||
foundIdx = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default merge: Match same year AND at least one significant word in common
|
|
||||||
if (
|
|
||||||
(m.year ? m.year.toString() : '') === entryYear &&
|
|
||||||
hasSignificantWordOverlap(entry.title, m.title)
|
|
||||||
) {
|
|
||||||
foundIdx = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (foundIdx >= 0) {
|
|
||||||
merged[foundIdx].results.push({ source: entry.source, ...entry });
|
|
||||||
} else {
|
|
||||||
merged.push({
|
|
||||||
title: entry.title,
|
title: entry.title,
|
||||||
year: entry.year,
|
year: entry.year,
|
||||||
results: [{ source: entry.source, ...entry }],
|
results: []
|
||||||
__raw: entry // For tie-break
|
};
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
map[key].results.push({
|
||||||
|
source: entry.source,
|
||||||
|
...entry
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
return Object.values(map);
|
||||||
let out = merged;
|
|
||||||
if (query) {
|
|
||||||
out.forEach(f => f.__score = getMatchScore(f, query));
|
|
||||||
out = out.sort((a, b) => b.__score - a.__score);
|
|
||||||
|
|
||||||
// PATCH: filter only films with ALL significant query words in title
|
|
||||||
const normQuery = query.trim().toLowerCase();
|
|
||||||
const skip = new Set(['the','le','la','les','de','du','des','and','et','a','an','un','une','dans','en','on']);
|
|
||||||
const queryWords = normQuery.split(/\s+/).filter(w => w.length > 3 && !skip.has(w));
|
|
||||||
if (queryWords.length) {
|
|
||||||
out = out.filter(film => {
|
|
||||||
const title = (film.title || '').toLowerCase();
|
|
||||||
return queryWords.every(qw => title.includes(qw));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Remove internals, trim to limit
|
|
||||||
return out.slice(0, limit).map(f => {
|
|
||||||
delete f.__score; delete f.__raw;
|
|
||||||
return f;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { mergeResults };
|
module.exports = { mergeResults };
|
||||||
|
3
package-lock.json
generated
3
package-lock.json
generated
@ -13,7 +13,8 @@
|
|||||||
"cheerio": "^1.0.0",
|
"cheerio": "^1.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^5.1.0"
|
"express": "^5.1.0"
|
||||||
}
|
},
|
||||||
|
"devDependencies": {}
|
||||||
},
|
},
|
||||||
"node_modules/accepts": {
|
"node_modules/accepts": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<title>Agrégateur Multi-Source</title>
|
||||||
<title>CineKids: Recommandations d'âge requis pour films et séries tv :-)</title>
|
|
||||||
<style>
|
<style>
|
||||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: #1a1a1a; color: #e0e0e0; margin: 0; padding: 20px; font-size: 14px; }
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: #1a1a1a; color: #e0e0e0; margin: 0; padding: 20px; font-size: 14px; }
|
||||||
.container { max-width: 1200px; margin: auto; }
|
.container { max-width: 1200px; margin: auto; }
|
||||||
h1 { color: #fff; text-align: center; }
|
h1 { color: #fff; text-align: center; }
|
||||||
.searchbox { margin: 20px 0 30px; display: flex; justify-content: center; align-items:center; }
|
.searchbox { margin: 20px 0 30px; display: flex; justify-content: center; }
|
||||||
input[type="text"] { font-size: 1.1em; width: clamp(200px, 60%, 500px); background: #2c2c2c; color: #fff; border: 1px solid #444; border-radius: 4px; padding: 10px 12px; }
|
input[type="text"] { font-size: 1.1em; width: clamp(200px, 60%, 500px); background: #2c2c2c; color: #fff; border: 1px solid #444; border-radius: 4px; padding: 10px 12px; }
|
||||||
button { font-size: 1.1em; padding: 10px 18px; background: #007aff; color: #fff; border-radius: 4px; border: none; margin-left: 10px; cursor: pointer; transition: background-color 0.2s; }
|
button { font-size: 1.1em; padding: 10px 18px; background: #007aff; color: #fff; border-radius: 4px; border: none; margin-left: 10px; cursor: pointer; transition: background-color 0.2s; }
|
||||||
button:hover { background: #005bb5; }
|
button:hover { background: #005bb5; }
|
||||||
@ -29,330 +28,119 @@
|
|||||||
.year { color: #aaa; }
|
.year { color: #aaa; }
|
||||||
.loader { text-align: center; font-size: 1.2em; color: #888; }
|
.loader { text-align: center; font-size: 1.2em; color: #888; }
|
||||||
.no-results { text-align: center; font-size: 1.1em; color: #999; margin-top:30px;}
|
.no-results { text-align: center; font-size: 1.1em; color: #999; margin-top:30px;}
|
||||||
.maxagebox { display:flex;align-items:center;margin-left:25px;}
|
|
||||||
.slider-age-badge {
|
|
||||||
font-size:1.25em;font-weight:bold;
|
|
||||||
color:#fff;border-radius:0.5em;padding:2px 10px;
|
|
||||||
min-width:2.5em;display:inline-block;letter-spacing:0.05em;
|
|
||||||
margin-left:10px;transition:background 0.2s;
|
|
||||||
}
|
|
||||||
@media (max-width: 800px) {
|
|
||||||
.searchbox {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: stretch;
|
|
||||||
}
|
|
||||||
.searchbox input[type="text"] {
|
|
||||||
width: 100%;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.searchbox button {
|
|
||||||
margin-left: 0;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.maxagebox {
|
|
||||||
margin-left: 0;
|
|
||||||
margin-top: 10px;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
.results-table,
|
|
||||||
.results-table tbody,
|
|
||||||
.results-table tr,
|
|
||||||
.results-table td {
|
|
||||||
display: block;
|
|
||||||
width: 100% !important;
|
|
||||||
}
|
|
||||||
.results-table thead {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.results-table tr {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
border-bottom: 1px solid #333;
|
|
||||||
}
|
|
||||||
.results-table td {
|
|
||||||
border: none;
|
|
||||||
padding: 10px 0;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
.results-table td:first-child div {
|
|
||||||
font-size: 1.2em;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.results-table img,
|
|
||||||
.source-block img {
|
|
||||||
width: 100% !important;
|
|
||||||
height: auto !important;
|
|
||||||
display: block;
|
|
||||||
margin: 10px 0 !important;
|
|
||||||
float: none !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<img src="/logo.png" alt="Logo CineKids" style="display:block;margin:30px auto 10px;max-width:130px;height:auto;">
|
<img src="/logo.png" alt="Logo Cine Kids" style="display:block;margin:30px auto 10px;max-width:130px;height:auto;">
|
||||||
<h1>CinéKids - Recommandations d'âge requis pour films et séries tv</h1>
|
<h1>Ciné-agrégateur Multi-Source</h1>
|
||||||
<div class="searchbox">
|
<div class="searchbox">
|
||||||
<input type="text" id="q" placeholder="Ex: Dune, Spider-Man, Oppenheimer..." />
|
<input type="text" id="q" placeholder="Ex: Dune, Spider-Man, Oppenheimer..." />
|
||||||
<button onclick="search()">Rechercher</button>
|
<button onclick="search()">Rechercher</button>
|
||||||
<div class="maxagebox">
|
|
||||||
<label for="maxAge" style="margin-right:9px;">Âge max :</label>
|
|
||||||
<input type="range" id="maxAge" min="3" max="21" value="21" step="1" style="vertical-align:middle;width:140px;" oninput="updateMaxAgeDisplay()">
|
|
||||||
<span id="maxAgeDisplay" class="slider-age-badge">21+</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="films"></div>
|
<div id="films"></div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
function getAgeColor(age) {
|
<script>
|
||||||
age = parseInt(age, 10);
|
async function search() {
|
||||||
if (isNaN(age)) return '#999';
|
const query = document.getElementById('q').value.trim();
|
||||||
if (age <= 6) return '#19c94a';
|
if (!query) return;
|
||||||
if (age <= 9) return '#68c3ee';
|
const filmsDiv = document.getElementById('films');
|
||||||
if (age <= 12) return '#ffe45e';
|
filmsDiv.innerHTML = '<p class="loader">Recherche en cours...</p>';
|
||||||
if (age <= 16) return '#ffb154';
|
|
||||||
if (age <= 18) return '#ff6384';
|
try {
|
||||||
return '#e2525c';
|
const response = await fetch(`http://localhost:3000/search?q=${encodeURIComponent(query)}`);
|
||||||
}
|
if (!response.ok) {
|
||||||
function ageBadge(age) {
|
// Gilfoyle: "The network, or your server, is garbage."
|
||||||
if (!age) return '';
|
filmsDiv.innerHTML = `<p class="no-results">Erreur: ${response.status} ${response.statusText || 'Impossible de joindre le backend.'}</p>`;
|
||||||
const c = getAgeColor(age);
|
return;
|
||||||
return `<span class="age-badge" style="
|
}
|
||||||
display:inline-block;
|
const films = await response.json();
|
||||||
font-size:1.2em;
|
|
||||||
min-width:2.5em;
|
if (!Array.isArray(films) || !films.length) {
|
||||||
font-weight:bold;
|
filmsDiv.innerHTML = '<p class="no-results">Aucun résultat trouvé. Essayez un autre terme.</p>';
|
||||||
color:#222;
|
return;
|
||||||
background:${c};
|
}
|
||||||
border-radius:0.4em;
|
|
||||||
text-align:center;
|
let html = `<table class="results-table">
|
||||||
margin-right:0.7em;
|
<thead>
|
||||||
padding:0.15em 0.7em;
|
<tr>
|
||||||
box-shadow:0 2px 8px #0003;
|
<th>Titre</th>
|
||||||
letter-spacing:0.03em;
|
<th>Année</th>
|
||||||
">${age}+</span>`;
|
<th>Sources d'information</th>
|
||||||
}
|
</tr>
|
||||||
function shortSummary(str, n = 200) {
|
</thead>
|
||||||
if (!str) return '-';
|
<tbody>`;
|
||||||
if (str.length <= n) return str;
|
|
||||||
return str.slice(0, n).replace(/\s+\S*$/, '') + '…';
|
films.forEach(film => {
|
||||||
}
|
html += `<tr>
|
||||||
function getAllAges(results) {
|
<td>${film.title || 'Titre inconnu'}</td>
|
||||||
const ages = [];
|
<td class="year">${film.year || 'N/A'}</td>
|
||||||
results.forEach(r => {
|
<td>`;
|
||||||
if (r.source === 'commonsense' && r.age && !isNaN(parseInt(r.age))) {
|
|
||||||
ages.push(parseInt(r.age));
|
film.results.forEach(r => {
|
||||||
}
|
html += `<div class="source-block">
|
||||||
else if (r.source === 'cinecheck') {
|
<p class="source-name">${r.source.charAt(0).toUpperCase() + r.source.slice(1)}</p>`;
|
||||||
if (Array.isArray(r.normalizedMarks) && r.normalizedMarks.length) {
|
if (r.img) {
|
||||||
r.normalizedMarks.forEach(a => { if (!isNaN(parseInt(a))) ages.push(parseInt(a)); });
|
html += `<img src="${r.img}" alt="Affiche pour ${film.title}">`;
|
||||||
} else if (r.marks && r.marks.length) {
|
}
|
||||||
r.marks.forEach(a => {
|
if (r.link) {
|
||||||
const n = parseInt(a);
|
html += `<p><a href="${r.link}" target="_blank">Voir la fiche détaillée</a></p>`;
|
||||||
if (!isNaN(n)) ages.push(n);
|
}
|
||||||
|
|
||||||
|
// CommonSense Media specific
|
||||||
|
if (r.source === 'commonsense') {
|
||||||
|
html += `<p><b>Âge conseillé:</b> ${r.age || '-'}</p>`;
|
||||||
|
html += `<p><b>Résumé (CSM):</b> ${r.summary || r.parentsNeedToKnow || '-'}</p>`;
|
||||||
|
if (r.details && r.details.length) {
|
||||||
|
html += `<p><b>Détails (CSM):</b></p><ul>`;
|
||||||
|
r.details.forEach(d => {
|
||||||
|
html += `<li>${d.type}: ${d.score}/5 - ${d.description || ''}</li>`;
|
||||||
|
});
|
||||||
|
html += `</ul>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cinecheck specific
|
||||||
|
else if (r.source === 'cinecheck') {
|
||||||
|
html += `<p><b>Âge(s) (Cinecheck):</b> ${r.marks && r.marks.length ? r.marks.join(', ') : '-'}</p>`;
|
||||||
|
html += `<p><b>Résumé (Cinecheck):</b> ${r.summary || '-'}</p>`;
|
||||||
|
if (r.details && r.details.length) {
|
||||||
|
html += `<p><b>Pictogrammes (Cinecheck):</b> ${r.details.map(d => d.type).join(', ') || '-'}</p>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Filmages specific
|
||||||
|
else if (r.source === 'filmages') {
|
||||||
|
html += `<p><b>Titre original (Filmages):</b> ${r.details.titleOriginalPage || r.details.titleOriginal || '-'}</p>`;
|
||||||
|
html += `<p><b>Âge légal (Filmages):</b> ${r.details.ageLegal || '-'}</p>`;
|
||||||
|
html += `<p><b>Âge suggéré (Filmages):</b> ${r.details.ageSuggested || '-'}</p>`;
|
||||||
|
html += `<p><b>Résumé (Filmages):</b> ${r.details.summary || '-'}</p>`;
|
||||||
|
html += `<p><b>Synthèse (Filmages):</b> ${r.details.synthesis || '-'}</p>`;
|
||||||
|
if (r.details.indications && r.details.indications.length) {
|
||||||
|
html += `<p><b>Indications:</b> ${r.details.indications.join(', ')}</p>`;
|
||||||
|
}
|
||||||
|
if (r.details.counterIndications && r.details.counterIndications.length) {
|
||||||
|
html += `<p><b>Contre-indications:</b> ${r.details.counterIndications.join(', ')}</p>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fallback for any other or new source
|
||||||
|
else {
|
||||||
|
html += `<p><b>Résumé:</b> ${r.summary || '-'}</p>`;
|
||||||
|
html += `<p><b>Âge:</b> ${r.age || '-'}</p>`;
|
||||||
|
}
|
||||||
|
html += `</div>`;
|
||||||
});
|
});
|
||||||
}
|
html += `</td></tr>`;
|
||||||
}
|
|
||||||
else if (r.source === 'filmages') {
|
|
||||||
if (r.details && r.details.ageLegal && !isNaN(parseInt(r.details.ageLegal))) {
|
|
||||||
ages.push(parseInt(r.details.ageLegal));
|
|
||||||
}
|
|
||||||
if (r.details && r.details.ageSuggested && !isNaN(parseInt(r.details.ageSuggested))) {
|
|
||||||
ages.push(parseInt(r.details.ageSuggested));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (r.age && !isNaN(parseInt(r.age))) {
|
|
||||||
ages.push(parseInt(r.age));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return ages;
|
|
||||||
}
|
|
||||||
function updateMaxAgeDisplay() {
|
|
||||||
var el = document.getElementById('maxAge');
|
|
||||||
var badge = document.getElementById('maxAgeDisplay');
|
|
||||||
var val = el.value || 21;
|
|
||||||
badge.textContent = val + '+';
|
|
||||||
badge.style.background = getAgeColor(val);
|
|
||||||
}
|
|
||||||
let lastQuery = '';
|
|
||||||
let lastResults = [];
|
|
||||||
|
|
||||||
async function search(force = false) {
|
|
||||||
const query = document.getElementById('q').value.trim();
|
|
||||||
if (!query) return;
|
|
||||||
const maxAge = parseInt(document.getElementById('maxAge').value, 10);
|
|
||||||
window.history.replaceState({}, '', '?q=' + encodeURIComponent(query) + (maxAge < 21 ? `&maxAge=${maxAge}` : ''));
|
|
||||||
const filmsDiv = document.getElementById('films');
|
|
||||||
filmsDiv.innerHTML = '<p class="loader">Searching...</p>';
|
|
||||||
|
|
||||||
// Si on a déjà cherché ce terme, et pas force, on ne refait pas le fetch
|
|
||||||
if (!force && lastQuery === query && lastResults.length) {
|
|
||||||
renderFilms(filterFilmsByMaxAge(lastResults, maxAge));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const base = window.location.origin;
|
|
||||||
const response = await fetch(`${base}/search?q=${encodeURIComponent(query)}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
filmsDiv.innerHTML = `<p class="no-results">Error: ${response.status} ${response.statusText || 'Backend unreachable.'}</p>`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let films = await response.json();
|
|
||||||
films = films.map(film => {
|
|
||||||
film.results = film.results.filter(r => {
|
|
||||||
let hasDescription =
|
|
||||||
(r.summary && r.summary.length >= 8) ||
|
|
||||||
(r.parentsNeedToKnow && r.parentsNeedToKnow.length >= 8) ||
|
|
||||||
(r.details && r.details.summary && r.details.summary.length >= 8);
|
|
||||||
let ages = getAllAges([r]);
|
|
||||||
let hasAge = ages && ages.length > 0;
|
|
||||||
return hasDescription && hasAge;
|
|
||||||
});
|
});
|
||||||
return film;
|
|
||||||
}).filter(film => film.results.length > 0);
|
|
||||||
|
|
||||||
lastQuery = query;
|
html += '</tbody></table>';
|
||||||
lastResults = films;
|
filmsDiv.innerHTML = html;
|
||||||
renderFilms(filterFilmsByMaxAge(films, maxAge));
|
} catch (error) {
|
||||||
} catch (error) {
|
// Mike: "Didn't go as planned."
|
||||||
console.error('Search function error:', error);
|
console.error('Search function error:', error);
|
||||||
filmsDiv.innerHTML = `<p class="no-results">Search failed. Check the console.</p>`;
|
filmsDiv.innerHTML = `<p class="no-results">Une erreur s'est produite lors de la recherche. Vérifiez la console.</p>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
document.getElementById('q').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
|
||||||
|
</script>
|
||||||
function filterFilmsByMaxAge(films, maxAge) {
|
|
||||||
if (!isFinite(maxAge)) return films;
|
|
||||||
return films.filter(film => {
|
|
||||||
const uniqueResults = [];
|
|
||||||
const seenSources = new Set();
|
|
||||||
film.results.forEach(r => {
|
|
||||||
if (!seenSources.has(r.source)) {
|
|
||||||
uniqueResults.push(r);
|
|
||||||
seenSources.add(r.source);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const ages = getAllAges(uniqueResults);
|
|
||||||
if (ages.length === 0) return true;
|
|
||||||
return Math.max(...ages) <= maxAge;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderFilms(films) {
|
|
||||||
const filmsDiv = document.getElementById('films');
|
|
||||||
if (!films.length) {
|
|
||||||
filmsDiv.innerHTML = '<p class="no-results">No results for this max age.</p>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let html = `<table class="results-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>Year</th>
|
|
||||||
<th>Information sources</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>`;
|
|
||||||
films.forEach(film => {
|
|
||||||
const allImgs = film.results.map(r => r.img).filter(Boolean);
|
|
||||||
const mainImg = allImgs.length ? allImgs[0] : null;
|
|
||||||
html += `<tr>
|
|
||||||
<td style="vertical-align:top;">
|
|
||||||
<div style="text-align:center;">
|
|
||||||
<div style="font-weight:bold;margin-bottom:0.7em;">${film.title || 'Unknown title'}</div>
|
|
||||||
${mainImg ? `<img src="${mainImg}" alt="Poster for ${film.title}" style="display:block;margin:auto;max-width:200px;max-height:250px;border-radius:5px;box-shadow:0 2px 8px #0003;margin-bottom:10px;">` : ''}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="year" style="vertical-align:top;">${film.year || 'N/A'}</td>
|
|
||||||
<td>`;
|
|
||||||
const uniqueResults = [];
|
|
||||||
const seenSources = new Set();
|
|
||||||
film.results.forEach(r => {
|
|
||||||
if (!seenSources.has(r.source)) {
|
|
||||||
uniqueResults.push(r);
|
|
||||||
seenSources.add(r.source);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
uniqueResults.forEach(r => {
|
|
||||||
html += `<div class="source-block">`;
|
|
||||||
html += `<p class="source-name">${r.source.charAt(0).toUpperCase() + r.source.slice(1)}</p>`;
|
|
||||||
if (r.link) {
|
|
||||||
html += `<p><a href="${r.link}" target="_blank">View details</a></p>`;
|
|
||||||
}
|
|
||||||
if (r.source === 'commonsense') {
|
|
||||||
html += `<p><b>Recommended age:</b> ${ageBadge(r.age)}</p>`;
|
|
||||||
html += `<p><b>Summary (CSM):</b> ${shortSummary(r.summary || r.parentsNeedToKnow)}</p>`;
|
|
||||||
if (r.details && r.details.length) {
|
|
||||||
html += `<p><b>Details (CSM):</b></p><ul>`;
|
|
||||||
r.details.forEach(d => {
|
|
||||||
html += `<li>${d.type}: ${d.score}/5 - ${shortSummary(d.description, 80)}</li>`;
|
|
||||||
});
|
|
||||||
html += `</ul>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (r.source === 'cinecheck') {
|
|
||||||
let numericAges = Array.isArray(r.normalizedMarks) && r.normalizedMarks.length
|
|
||||||
? r.normalizedMarks
|
|
||||||
: (r.marks || []).map(x => {
|
|
||||||
let n = parseInt((x + '').replace(/\d+/, ''), 10);
|
|
||||||
return isNaN(n) ? null : n;
|
|
||||||
}).filter(n => n !== null && !isNaN(n));
|
|
||||||
let minAge = numericAges.length ? Math.min(...numericAges) : '';
|
|
||||||
html += `<p><b>Age(s) (Cinecheck):</b> ${minAge ? ageBadge(minAge) : ''}${r.marks && r.marks.length ? r.marks.join(', ') : '-'}</p>`;
|
|
||||||
html += `<p><b>Summary (Cinecheck):</b> ${shortSummary(r.summary)}</p>`;
|
|
||||||
if (r.details && r.details.length) {
|
|
||||||
html += `<p><b>Pictograms (Cinecheck):</b> ${r.details.map(d => d.type).join(', ') || '-'}</p>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (r.source === 'filmages') {
|
|
||||||
html += `<p><b>Original title (Filmages):</b> ${r.details.titleOriginalPage || r.details.titleOriginal || '-'}</p>`;
|
|
||||||
html += `<p><b>Legal age (Filmages):</b> ${ageBadge(r.details.ageLegal)}</p>`;
|
|
||||||
html += `<p><b>Suggested age (Filmages):</b> ${ageBadge(r.details.ageSuggested)}</p>`;
|
|
||||||
html += `<p><b>Summary (Filmages):</b> ${shortSummary(r.details.summary)}</p>`;
|
|
||||||
html += `<p><b>Synthesis (Filmages):</b> ${shortSummary(r.details.synthesis, 100)}</p>`;
|
|
||||||
if (r.details.indications && r.details.indications.length) {
|
|
||||||
html += `<p><b>Indications:</b> ${shortSummary(r.details.indications.join(', '), 100)}</p>`;
|
|
||||||
}
|
|
||||||
if (r.details.counterIndications && r.details.counterIndications.length) {
|
|
||||||
html += `<p><b>Contra-indications:</b> ${shortSummary(r.details.counterIndications.join(', '), 100)}</p>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
html += `<p><b>Summary:</b> ${shortSummary(r.summary)}</p>`;
|
|
||||||
html += `<p><b>Age:</b> ${ageBadge(r.age)}</p>`;
|
|
||||||
}
|
|
||||||
html += `</div>`;
|
|
||||||
});
|
|
||||||
html += `</td></tr>`;
|
|
||||||
});
|
|
||||||
html += '</tbody></table>';
|
|
||||||
filmsDiv.innerHTML = html;
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('maxAge').addEventListener('input', function() {
|
|
||||||
updateMaxAgeDisplay();
|
|
||||||
// Pas de fetch, juste filtre en front
|
|
||||||
const query = document.getElementById('q').value.trim();
|
|
||||||
if (!query || !lastResults.length) return;
|
|
||||||
const maxAge = parseInt(document.getElementById('maxAge').value, 10);
|
|
||||||
renderFilms(filterFilmsByMaxAge(lastResults, maxAge));
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
const q = params.get('q');
|
|
||||||
const maxAge = params.get('maxAge');
|
|
||||||
if (maxAge) {
|
|
||||||
document.getElementById('maxAge').value = maxAge;
|
|
||||||
updateMaxAgeDisplay();
|
|
||||||
}
|
|
||||||
if (q) {
|
|
||||||
document.getElementById('q').value = q;
|
|
||||||
search(true); // force fetch initiale
|
|
||||||
}
|
|
||||||
});
|
|
||||||
document.getElementById('q').addEventListener('keydown', e => { if (e.key === 'Enter') search(true); });
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -49,7 +49,8 @@ app.get('/search', async (req, res) => {
|
|||||||
console.log('Filmages results:', fa.length);
|
console.log('Filmages results:', fa.length);
|
||||||
console.log('FilmsTousPublics results:', ftp.length);
|
console.log('FilmsTousPublics results:', ftp.length);
|
||||||
console.log('FilmsPourEnfants results:', fpe.length);
|
console.log('FilmsPourEnfants results:', fpe.length);
|
||||||
const merged = mergeResults([cine, cs, fa, ftp, fpe], q, 10); // limit=5
|
|
||||||
|
const merged = mergeResults([cine, cs, fa, ftp, fpe]);
|
||||||
res.json(merged);
|
res.json(merged);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('General search error:', e);
|
console.error('General search error:', e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user