aggregate more source
This commit is contained in:
99
aggregators/filmages-adapter.js
Normal file
99
aggregators/filmages-adapter.js
Normal file
@ -0,0 +1,99 @@
|
||||
const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
const BASE_URL = 'http://www.filmages.ch/';
|
||||
|
||||
async function searchMovies(query) {
|
||||
const searchUrl = `${BASE_URL}films/recherche/search/${encodeURIComponent(query)}.html`;
|
||||
const response = await axios.get(searchUrl, { headers: { 'User-Agent': 'Mozilla/5.0' } });
|
||||
const $ = cheerio.load(response.data);
|
||||
const results = [];
|
||||
|
||||
$('table.layout_simpletable tbody tr.item').each((_, el) => {
|
||||
const row = $(el);
|
||||
const titleFrench = row.find('td.field.title_french a').text().trim();
|
||||
const link = row.find('td.field.title_french a').attr('href');
|
||||
const titleOriginal = row.find('td.field.title_original').text().trim();
|
||||
const director = row.find('td.field.director').text().trim();
|
||||
const ageLegal = row.find('td.field.age_legal').text().trim();
|
||||
const ageSuggested = row.find('td.field.age_suggested').text().trim();
|
||||
|
||||
if (titleFrench && link) {
|
||||
results.push({
|
||||
titleFrench,
|
||||
titleOriginal,
|
||||
director,
|
||||
ageLegalSearch: ageLegal,
|
||||
ageSuggestedSearch: ageSuggested,
|
||||
link: BASE_URL + link, // Make absolute
|
||||
});
|
||||
}
|
||||
});
|
||||
// console.log('FilmAges search results:', results);
|
||||
return results;
|
||||
}
|
||||
|
||||
async function getMovieClassification(movieUrl) {
|
||||
if (!movieUrl) return {};
|
||||
const response = await axios.get(movieUrl, { headers: { 'User-Agent': 'Mozilla/5.0' } });
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const mainDetails = $('#reader_main .layout_full .item');
|
||||
const rightDetails = $('#reader_right_1 .layout_full .item'); // For ages
|
||||
const rightCriteria = $('#reader_right_2 .layout_full .item'); // For indications
|
||||
|
||||
const titleOriginal = mainDetails.find('.field.title_original .value').text().trim();
|
||||
const year = mainDetails.find('.field.year .value').text().trim();
|
||||
const summary = mainDetails.find('.field.summary .value').text().trim();
|
||||
const synthesis = mainDetails.find('.field.final_remark .value').text().trim();
|
||||
|
||||
const ageLegal = rightDetails.find('.field.age_legal .value').text().trim();
|
||||
const ageSuggested = rightDetails.find('.field.age_suggested .value').text().trim();
|
||||
|
||||
const indications = [];
|
||||
rightCriteria.find('.field.indication .value a').each((_, el) => {
|
||||
indications.push($(el).text().trim());
|
||||
});
|
||||
|
||||
const counterIndications = [];
|
||||
rightCriteria.find('.field.counter_indication .value a').each((_, el) => {
|
||||
counterIndications.push($(el).text().trim());
|
||||
});
|
||||
|
||||
const director = mainDetails.find('.field.director .value').text().trim();
|
||||
|
||||
return {
|
||||
titleOriginalPage: titleOriginal, // To distinguish from search result one
|
||||
year,
|
||||
summary,
|
||||
synthesis,
|
||||
ageLegal,
|
||||
ageSuggested,
|
||||
indications,
|
||||
counterIndications,
|
||||
directorPage: director,
|
||||
};
|
||||
}
|
||||
|
||||
async function searchAndEnrich(query) {
|
||||
const searchResults = await searchMovies(query);
|
||||
const enrichedResults = await Promise.all(
|
||||
searchResults.map(async (movie) => {
|
||||
const classification = await getMovieClassification(movie.link);
|
||||
return {
|
||||
title: movie.titleFrench || movie.titleOriginal, // Prioritize French title for matching
|
||||
year: classification.year, // Year is only on detail page
|
||||
img: null, // No images readily available from search/detail
|
||||
link: movie.link,
|
||||
source: 'filmages',
|
||||
details: {
|
||||
...movie, // Keep all search results fields
|
||||
...classification, // Add all detail page fields
|
||||
}
|
||||
};
|
||||
})
|
||||
);
|
||||
// console.log('FilmAges enriched:', enrichedResults);
|
||||
return enrichedResults;
|
||||
}
|
||||
|
||||
module.exports = { searchAndEnrich };
|
Reference in New Issue
Block a user