better-ani-scraped 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scrapers/animesama.js +21 -38
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import * as cheerio from "cheerio";
|
|
3
3
|
import fs from "fs";
|
|
4
|
+
import puppeteer from'puppeteer';
|
|
4
5
|
|
|
5
6
|
const BASE_URL = "https://anime-sama.fr";
|
|
6
7
|
const CATALOGUE_URL = `${BASE_URL}/catalogue`;
|
|
@@ -123,58 +124,45 @@ export async function getSeasons(animeUrl, language = "vostfr") {
|
|
|
123
124
|
return seasons;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
import { chromium } from 'playwright';
|
|
127
127
|
|
|
128
|
-
export async function getEpisodeTitles(animeUrl
|
|
129
|
-
const { executablePath = null } = options; // <-- ajout ici
|
|
128
|
+
export async function getEpisodeTitles(animeUrl) {
|
|
130
129
|
let browser;
|
|
131
|
-
|
|
132
130
|
try {
|
|
133
|
-
browser = await
|
|
134
|
-
headless: true,
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const context = await browser.newContext({
|
|
139
|
-
locale: 'fr-FR',
|
|
140
|
-
userAgent: 'Mozilla/5.0'
|
|
131
|
+
browser = await puppeteer.launch({
|
|
132
|
+
headless: true,
|
|
133
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
141
134
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
await page.route('**/*', (route) => {
|
|
135
|
+
const page = await browser.newPage();
|
|
136
|
+
await page.setRequestInterception(true);
|
|
137
|
+
page.on('request', (req) => {
|
|
146
138
|
const blocked = ['image', 'stylesheet', 'font', 'media'];
|
|
147
|
-
if (blocked.includes(
|
|
148
|
-
|
|
139
|
+
if (blocked.includes(req.resourceType())) {
|
|
140
|
+
req.abort();
|
|
149
141
|
} else {
|
|
150
|
-
|
|
142
|
+
req.continue();
|
|
151
143
|
}
|
|
152
144
|
});
|
|
153
|
-
|
|
154
|
-
await page.
|
|
155
|
-
await page.waitForSelector('#selectEpisodes', { timeout: 10000 });
|
|
156
|
-
|
|
145
|
+
await page.goto(animeUrl, { waitUntil: 'domcontentloaded' });
|
|
146
|
+
await page.waitForSelector('#selectEpisodes');
|
|
157
147
|
const titres = await page.$$eval('#selectEpisodes option', options =>
|
|
158
148
|
options.map(o => o.textContent.trim())
|
|
159
149
|
);
|
|
160
|
-
|
|
161
150
|
return titres;
|
|
162
151
|
} catch (error) {
|
|
163
|
-
console.error('
|
|
152
|
+
console.error('Erreur dans la récupération des titres:', error);
|
|
164
153
|
return [];
|
|
165
154
|
} finally {
|
|
166
|
-
if (browser)
|
|
167
|
-
await browser.close();
|
|
168
|
-
}
|
|
155
|
+
if (browser) await browser.close();
|
|
169
156
|
}
|
|
170
157
|
}
|
|
171
158
|
|
|
159
|
+
|
|
172
160
|
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
173
161
|
const res = await axios.get(animeUrl, {
|
|
174
162
|
headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
|
|
175
163
|
});
|
|
176
|
-
const $ = cheerio.load(res.data);
|
|
177
164
|
|
|
165
|
+
const $ = cheerio.load(res.data);
|
|
178
166
|
const scriptTag = $('script[src*="episodes.js"]').attr("src");
|
|
179
167
|
if (!scriptTag) throw new Error("No episodes script found");
|
|
180
168
|
|
|
@@ -191,7 +179,6 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
|
191
179
|
];
|
|
192
180
|
if (!matches.length) throw new Error("No episode arrays found");
|
|
193
181
|
|
|
194
|
-
// Parse les arrays et crée une matrice [epsX][index]
|
|
195
182
|
let episodeMatrix = [];
|
|
196
183
|
for (const [, , arrayString] of matches) {
|
|
197
184
|
try {
|
|
@@ -202,14 +189,10 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
|
202
189
|
}
|
|
203
190
|
}
|
|
204
191
|
|
|
205
|
-
// Déterminer le nombre total d'épisodes max (plus long des arrays)
|
|
206
192
|
const maxEpisodes = Math.max(...episodeMatrix.map(arr => arr.length));
|
|
207
193
|
const finalEmbeds = [];
|
|
208
|
-
|
|
209
|
-
// Parcours vertical
|
|
210
194
|
for (let i = 0; i < maxEpisodes; i++) {
|
|
211
195
|
let selectedUrl = null;
|
|
212
|
-
|
|
213
196
|
for (const host of hostPriority) {
|
|
214
197
|
for (const arr of episodeMatrix) {
|
|
215
198
|
if (i < arr.length && arr[i].includes(host)) {
|
|
@@ -219,17 +202,17 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
|
219
202
|
}
|
|
220
203
|
if (selectedUrl) break;
|
|
221
204
|
}
|
|
222
|
-
|
|
223
205
|
finalEmbeds.push(selectedUrl || null);
|
|
224
206
|
}
|
|
225
207
|
|
|
226
208
|
const titles = await getEpisodeTitles(animeUrl);
|
|
227
|
-
return
|
|
228
|
-
title,
|
|
229
|
-
url
|
|
209
|
+
return finalEmbeds.map((url, i) => ({
|
|
210
|
+
title: titles[i] || "Untitled",
|
|
211
|
+
url,
|
|
230
212
|
}));
|
|
231
213
|
}
|
|
232
214
|
|
|
215
|
+
|
|
233
216
|
export async function getAnimeInfo(animeUrl) {
|
|
234
217
|
const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
|
|
235
218
|
const $ = cheerio.load(res.data);
|