better-ani-scraped 1.2.5 → 1.2.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-ani-scraped",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "Scrape anime data from different sources (only anime-sama.fr for the moment)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,46 @@ 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, options = {}) {
129
- const { executablePath = null } = options; // <-- ajout ici
128
+ export async function getEpisodeTitles(animeUrl) {
129
+ console.log('Executable path:', puppeteer.executablePath());
130
130
  let browser;
131
-
132
131
  try {
133
- browser = await chromium.launch({
134
- headless: true,
135
- ...(executablePath ? { executablePath } : {}) // <-- on injecte le chemin si dispo
136
- });
137
-
138
- const context = await browser.newContext({
139
- locale: 'fr-FR',
140
- userAgent: 'Mozilla/5.0'
132
+ browser = await puppeteer.launch({
133
+ headless: true,
134
+ args: ['--no-sandbox', '--disable-setuid-sandbox']
141
135
  });
142
-
143
- const page = await context.newPage();
144
-
145
- await page.route('**/*', (route) => {
136
+ const page = await browser.newPage();
137
+ await page.setRequestInterception(true);
138
+ page.on('request', (req) => {
146
139
  const blocked = ['image', 'stylesheet', 'font', 'media'];
147
- if (blocked.includes(route.request().resourceType())) {
148
- route.abort();
140
+ if (blocked.includes(req.resourceType())) {
141
+ req.abort();
149
142
  } else {
150
- route.continue();
143
+ req.continue();
151
144
  }
152
145
  });
153
-
154
- await page.goto(animeUrl, { waitUntil: 'domcontentloaded', timeout: 20000 });
155
- await page.waitForSelector('#selectEpisodes', { timeout: 10000 });
156
-
146
+ await page.goto(animeUrl, { waitUntil: 'domcontentloaded' });
147
+ await page.waitForSelector('#selectEpisodes');
157
148
  const titres = await page.$$eval('#selectEpisodes option', options =>
158
149
  options.map(o => o.textContent.trim())
159
150
  );
160
-
161
151
  return titres;
162
152
  } catch (error) {
163
- console.error('Erreur dans la récupération des titres :', error);
153
+ console.error('Erreur dans la récupération des titres:', error);
164
154
  return [];
165
155
  } finally {
166
- if (browser) {
167
- await browser.close();
168
- }
156
+ if (browser) await browser.close();
169
157
  }
170
158
  }
171
159
 
160
+
172
161
  export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
173
162
  const res = await axios.get(animeUrl, {
174
163
  headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
175
164
  });
176
- const $ = cheerio.load(res.data);
177
165
 
166
+ const $ = cheerio.load(res.data);
178
167
  const scriptTag = $('script[src*="episodes.js"]').attr("src");
179
168
  if (!scriptTag) throw new Error("No episodes script found");
180
169
 
@@ -182,7 +171,7 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
182
171
  ? animeUrl + scriptTag
183
172
  : animeUrl + "/" + scriptTag;
184
173
 
185
- const episodesJs = await axios
174
+ const episodesJs = await axios
186
175
  .get(scriptUrl, { headers: getHeaders(animeUrl) })
187
176
  .then((r) => r.data);
188
177
 
@@ -191,7 +180,6 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
191
180
  ];
192
181
  if (!matches.length) throw new Error("No episode arrays found");
193
182
 
194
- // Parse les arrays et crée une matrice [epsX][index]
195
183
  let episodeMatrix = [];
196
184
  for (const [, , arrayString] of matches) {
197
185
  try {
@@ -202,14 +190,10 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
202
190
  }
203
191
  }
204
192
 
205
- // Déterminer le nombre total d'épisodes max (plus long des arrays)
206
193
  const maxEpisodes = Math.max(...episodeMatrix.map(arr => arr.length));
207
194
  const finalEmbeds = [];
208
-
209
- // Parcours vertical
210
195
  for (let i = 0; i < maxEpisodes; i++) {
211
196
  let selectedUrl = null;
212
-
213
197
  for (const host of hostPriority) {
214
198
  for (const arr of episodeMatrix) {
215
199
  if (i < arr.length && arr[i].includes(host)) {
@@ -219,17 +203,17 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
219
203
  }
220
204
  if (selectedUrl) break;
221
205
  }
222
-
223
206
  finalEmbeds.push(selectedUrl || null);
224
207
  }
225
208
 
226
209
  const titles = await getEpisodeTitles(animeUrl);
227
- return titles.slice(0, finalEmbeds.length).map((title, i) => ({
228
- title,
229
- url: finalEmbeds[i]
210
+ return finalEmbeds.map((url, i) => ({
211
+ title: titles[i] || "Untitled",
212
+ url,
230
213
  }));
231
214
  }
232
215
 
216
+
233
217
  export async function getAnimeInfo(animeUrl) {
234
218
  const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
235
219
  const $ = cheerio.load(res.data);