better-ani-scraped 1.6.81 → 1.6.82

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.6.81",
3
+ "version": "1.6.82",
4
4
  "description": "Scrape anime data from different sources (only anime-sama.fr, animepahe and crunchyroll for the moment)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -36,19 +36,13 @@ async function ensureChromiumInstalled(customPath) {
36
36
  }
37
37
 
38
38
  function getHeaders(referer = BASE_URL) {
39
- const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
40
39
  return {
41
- headers: {
42
- "User-Agent": userAgent,
43
- "Accept-Language": "fr-FR,fr;q=0.9,en;q=0.8",
44
- "Referer": referer,
45
- },
46
- userAgent
40
+ "User-Agent": "Mozilla/5.0",
41
+ "Accept-Language": "fr-FR,fr;q=0.9,en;q=0.8",
42
+ Referer: referer,
47
43
  };
48
44
  }
49
45
 
50
-
51
-
52
46
  export async function searchAnime(
53
47
  query,
54
48
  limit = 10,
@@ -59,7 +53,6 @@ export async function searchAnime(
59
53
  const languages = Array.isArray(wantedLanguages) ? wantedLanguages : ["vostfr", "vf", "vastfr"];
60
54
  const types = Array.isArray(wantedTypes) ? wantedTypes : ["Anime", "Film"];
61
55
 
62
- const { headers } = getHeaders(CATALOGUE_URL);
63
56
  const isWanted = (text, list) =>
64
57
  list.length === 0 || list.some(item => text.toLowerCase().includes(item.toLowerCase()));
65
58
 
@@ -71,7 +64,7 @@ export async function searchAnime(
71
64
  ? `${CATALOGUE_URL}/?search=${encodeURIComponent(query)}`
72
65
  : `${CATALOGUE_URL}/?search=${encodeURIComponent(query)}&page=${pageNum}`;
73
66
 
74
- const res = await axios.get(url, { headers: headers });
67
+ const res = await axios.get(url, { headers: getHeaders(CATALOGUE_URL) });
75
68
  const $ = cheerio.load(res.data);
76
69
 
77
70
  const containers = $("a.flex.divide-x");
@@ -132,9 +125,7 @@ export async function searchAnime(
132
125
  }
133
126
 
134
127
  export async function getSeasons(animeUrl, languagePriority = ["vostfr", "vf", "va", "vkr", "vcn", "vqc", "vf1", "vf2"]) {
135
- const { headersCatalog } = getHeaders(CATALOGUE_URL);
136
- const { headersAnime } = getHeaders(animeUrl);
137
- const res = await axios.get(animeUrl, { headers: headersCatalog });
128
+ const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
138
129
  const html = res.data;
139
130
 
140
131
  const mainAnimeOnly = html.split("Anime Version Kai")[0];
@@ -164,19 +155,19 @@ export async function getSeasons(animeUrl, languagePriority = ["vostfr", "vf", "
164
155
  const href = match[2].split("/")[0];
165
156
  const fullUrl = `${CATALOGUE_URL}/${animeName}/${href}/${language}`;
166
157
 
167
- try {
168
- const check = await axios.head(fullUrl, {
169
- headers: headersAnime,
170
- });
171
- if (check.status === 200) {
172
- languageAvailable = true;
173
- seasons.push({ title, url: fullUrl });
158
+ try {
159
+ const check = await axios.head(fullUrl, {
160
+ headers: getHeaders(animeUrl),
161
+ });
162
+ if (check.status === 200) {
163
+ languageAvailable = true;
164
+ seasons.push({ title, url: fullUrl });
165
+ }
166
+ } catch (err) {
167
+ // Ignore invalid URLs
174
168
  }
175
- } catch (err) {
176
- // Ignore missing URLs
177
169
  }
178
170
  }
179
- }
180
171
 
181
172
  if (languageAvailable) {
182
173
  return { language, seasons };
@@ -188,7 +179,6 @@ export async function getSeasons(animeUrl, languagePriority = ["vostfr", "vf", "
188
179
 
189
180
 
190
181
  export async function getEpisodeTitles(seasonUrl, customChromiumPath) {
191
- const { headers, userAgent } = getHeaders(seasonUrl);
192
182
  let browser;
193
183
  try {
194
184
  const puppeteer = await import('puppeteer');
@@ -205,7 +195,7 @@ export async function getEpisodeTitles(seasonUrl, customChromiumPath) {
205
195
  });
206
196
 
207
197
  const page = await browser.newPage();
208
- await page.setExtraHTTPHeaders(headers);
198
+ await page.setExtraHTTPHeaders(getHeaders(seasonUrl));
209
199
  await page.setRequestInterception(true);
210
200
  page.on('request', (req) => {
211
201
  const blocked = ['image', 'stylesheet', 'font', 'media'];
@@ -215,7 +205,7 @@ export async function getEpisodeTitles(seasonUrl, customChromiumPath) {
215
205
  req.continue();
216
206
  }
217
207
  });
218
- await page.setUserAgent(userAgent);
208
+ await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36');
219
209
  await page.evaluateOnNewDocument(() => {
220
210
  Object.defineProperty(navigator, 'webdriver', { get: () => false });
221
211
  });
@@ -244,10 +234,8 @@ export async function getEmbed(
244
234
  includeInfo = false,
245
235
  customChromiumPath
246
236
  ) {
247
- const { headersSplit } = getHeaders(seasonUrl.split("/").slice(0, 5).join("/"));
248
- const { headers } = getHeaders(seasonUrl);
249
237
  const res = await axios.get(seasonUrl, {
250
- headers: headersSplit,
238
+ headers: getHeaders(seasonUrl.split("/").slice(0, 5).join("/")),
251
239
  });
252
240
 
253
241
  const $ = cheerio.load(res.data);
@@ -265,7 +253,7 @@ export async function getEmbed(
265
253
  : seasonUrl + "/" + scriptTag;
266
254
 
267
255
  const episodesJs = await axios
268
- .get(scriptUrl, { headers: headers })
256
+ .get(scriptUrl, { headers: getHeaders(seasonUrl) })
269
257
  .then((r) => r.data);
270
258
 
271
259
  const matches = [...episodesJs.matchAll(/var\s+(eps\d+)\s*=\s*(\[[^\]]+\])/g)];
@@ -322,13 +310,13 @@ export async function getEmbed(
322
310
  if (selectedUrl) break;
323
311
  }
324
312
 
325
- finalEmbeds.push({
326
- title: null,
327
- url: selectedUrl || null,
328
- host: selectedHost || null
329
- });
313
+ finalEmbeds.push({
314
+ title: null, // à remplir plus tard
315
+ url: selectedUrl || null,
316
+ host: selectedHost || null,
317
+ });
318
+ }
330
319
  }
331
- }
332
320
 
333
321
  const titles = await getEpisodeTitles(seasonUrl, customChromiumPath);
334
322
  finalEmbeds.forEach((embed, i) => {
@@ -351,8 +339,7 @@ export async function getEmbed(
351
339
 
352
340
 
353
341
  export async function getAnimeInfo(animeUrl) {
354
- const { headers } = getHeaders(CATALOGUE_URL);
355
- const res = await axios.get(animeUrl, { headers: headers });
342
+ const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
356
343
  const $ = cheerio.load(res.data);
357
344
 
358
345
  const cover = $("#coverOeuvre").attr("src");
@@ -388,7 +375,6 @@ export async function getAvailableLanguages(
388
375
  wantedLanguages = ["vostfr", "vf", "va", "vkr", "vcn", "vqc", "vf1", "vf2"],
389
376
  numberEpisodes = false
390
377
  ) {
391
- const { headers } = getHeaders(CATALOGUE_URL);
392
378
  const languageLinks = [];
393
379
 
394
380
  // Iterate over each possible language and check if the page exists
@@ -396,7 +382,7 @@ export async function getAvailableLanguages(
396
382
  const languageUrl = seasonUrl.split('/').map((s, i) => i === 6 ? language : s).join('/');
397
383
  try {
398
384
  const res = await axios.get(languageUrl, {
399
- headers: headers,
385
+ headers: getHeaders(CATALOGUE_URL),
400
386
  });
401
387
  if (res.status === 200) {
402
388
  if (numberEpisodes){
@@ -422,7 +408,6 @@ export async function getAllAnime(
422
408
  output = "anime_list.json",
423
409
  get_seasons = false
424
410
  ) {
425
- const { headers } = getHeaders(CATALOGUE_URL);
426
411
  let animeLinks = [];
427
412
 
428
413
  const isWanted = (text, list) =>
@@ -430,7 +415,7 @@ export async function getAllAnime(
430
415
 
431
416
  const fetchPage = async (pageNum) => {
432
417
  const url = pageNum === 1 ? CATALOGUE_URL : `${CATALOGUE_URL}?page=${pageNum}`;
433
- const res = await axios.get(url, { headers: headers });
418
+ const res = await axios.get(url, { headers: getHeaders(CATALOGUE_URL) });
434
419
  const $ = cheerio.load(res.data);
435
420
 
436
421
  const containers = $("div.shrink-0.m-3.rounded.border-2");
@@ -509,8 +494,7 @@ export async function getAllAnime(
509
494
 
510
495
  export async function getLatestEpisodes(languageFilter = null) {
511
496
  try {
512
- const { headers } = getHeaders(BASE_URL);
513
- const res = await axios.get(BASE_URL, { headers: headers });
497
+ const res = await axios.get(BASE_URL, { headers: getHeaders() });
514
498
  const $ = cheerio.load(res.data);
515
499
 
516
500
  const container = $("#containerAjoutsAnimes");
@@ -522,7 +506,7 @@ export async function getLatestEpisodes(languageFilter = null) {
522
506
  const cover = $(el).find("img").attr("src");
523
507
 
524
508
  const buttons = $(el).find("button");
525
- const language = $(buttons[0]).text().trim().toLowerCase();
509
+ const language = $(buttons[0]).text().trim().toLowerCase(); // Normalisation
526
510
  const episode = $(buttons[1]).text().trim();
527
511
 
528
512
  if (
@@ -556,11 +540,10 @@ export async function getRandomAnime(
556
540
  maxAttempts = null,
557
541
  attempt = 0
558
542
  ) {
559
- const { headers } = getHeaders(CATALOGUE_URL);
560
543
  try {
561
544
  const res = await axios.get(
562
545
  `${CATALOGUE_URL}/?search=&random=1`,
563
- { headers:headers }
546
+ { headers: getHeaders(CATALOGUE_URL) }
564
547
  );
565
548
 
566
549
  const $ = cheerio.load(res.data);
@@ -626,4 +609,3 @@ export async function getRandomAnime(
626
609
  return null;
627
610
  }
628
611
  }
629
-