better-ani-scraped 1.6.1 → 1.6.2

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.
@@ -4,7 +4,7 @@ const main = async () => {
4
4
  const animesama = new AnimeScraper('animesama');
5
5
  const seasonUrl = "https://anime-sama.fr/catalogue/86-eighty-six/saison1/vostfr/";
6
6
 
7
- const embeds = await animesama.getEmbed(seasonUrl, ["sibnet", "vidmoly"]);
7
+ const embeds = await animesama.getEmbed(seasonUrl, ["sibnet", "vidmoly"], true);
8
8
  console.log("Embed Links:", embeds);
9
9
  };
10
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-ani-scraped",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "Scrape anime data from different sources (only anime-sama.fr for the moment)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -215,12 +215,23 @@ export async function getEpisodeTitles(seasonUrl, customChromiumPath) {
215
215
  }
216
216
  }
217
217
 
218
- export async function getEmbed(seasonUrl, hostPriority = ["sendvid", "sibnet", "vidmoly", "oneupload"], customChromiumPath) {
218
+ export async function getEmbed(
219
+ seasonUrl,
220
+ hostPriority = ["sendvid", "sibnet", "vidmoly", "oneupload"],
221
+ includeInfo = false,
222
+ customChromiumPath
223
+ ) {
219
224
  const res = await axios.get(seasonUrl, {
220
225
  headers: getHeaders(seasonUrl.split("/").slice(0, 5).join("/")),
221
226
  });
222
227
 
223
228
  const $ = cheerio.load(res.data);
229
+
230
+ const seasonTitle = ($('script').toArray()
231
+ .map(s => $(s).html())
232
+ .find(c => c && c.includes('#avOeuvre')) || '')
233
+ .match(/#avOeuvre"\)\.html\("([^"]+)"/)?.[1] || "Saison inconnue";
234
+
224
235
  const scriptTag = $('script[src*="episodes.js"]').attr("src");
225
236
  if (!scriptTag) throw new Error("No episodes script found");
226
237
 
@@ -232,9 +243,7 @@ export async function getEmbed(seasonUrl, hostPriority = ["sendvid", "sibnet", "
232
243
  .get(scriptUrl, { headers: getHeaders(seasonUrl) })
233
244
  .then((r) => r.data);
234
245
 
235
- const matches = [
236
- ...episodesJs.matchAll(/var\s+(eps\d+)\s*=\s*(\[[^\]]+\])/g),
237
- ];
246
+ const matches = [...episodesJs.matchAll(/var\s+(eps\d+)\s*=\s*(\[[^\]]+\])/g)];
238
247
  if (!matches.length) throw new Error("No episode arrays found");
239
248
 
240
249
  let episodeMatrix = [];
@@ -249,37 +258,50 @@ export async function getEmbed(seasonUrl, hostPriority = ["sendvid", "sibnet", "
249
258
 
250
259
  const maxEpisodes = Math.max(...episodeMatrix.map(arr => arr.length));
251
260
  const finalEmbeds = [];
252
- for (let i = 0; i < maxEpisodes; i++) {
253
- let selectedUrl = null;
254
- let selectedHost = null;
255
-
256
- for (const host of hostPriority) {
257
- for (const arr of episodeMatrix) {
258
- if (i < arr.length && arr[i].includes(host)) {
259
- selectedUrl = arr[i];
260
- selectedHost = host;
261
- break;
261
+
262
+ for (let i = 0; i < maxEpisodes; i++) {
263
+ let selectedUrl = null;
264
+ let selectedHost = null;
265
+
266
+ for (const host of hostPriority) {
267
+ for (const arr of episodeMatrix) {
268
+ if (i < arr.length && arr[i].includes(host)) {
269
+ selectedUrl = arr[i];
270
+ selectedHost = host;
271
+ break;
272
+ }
262
273
  }
274
+ if (selectedUrl) break;
263
275
  }
264
- if (selectedUrl) break;
276
+
277
+ finalEmbeds.push({
278
+ title: null, // on remplit après
279
+ url: selectedUrl || null,
280
+ host: selectedHost || null
281
+ });
265
282
  }
266
283
 
267
- finalEmbeds.push({
268
- url: selectedUrl || null,
269
- host: selectedHost || null
284
+ const titles = await getEpisodeTitles(seasonUrl, customChromiumPath);
285
+ finalEmbeds.forEach((embed, i) => {
286
+ embed.title = titles[i] || `Episode ${i + 1}`;
270
287
  });
271
- }
272
288
 
273
- const titles = await getEpisodeTitles(seasonUrl, customChromiumPath);
274
-
275
- return finalEmbeds.map((embed, i) => ({
276
- title: titles[i] || null,
277
- url: embed.url,
278
- host: embed.host
279
- }));
289
+ if (includeInfo) {
290
+ return {
291
+ episodes: finalEmbeds,
292
+ animeInfo: {
293
+ seasonTitle,
294
+ episodeCount: maxEpisodes
295
+ }
296
+ };
280
297
 
298
+ } else {
299
+ return finalEmbeds;
300
+ }
281
301
  }
282
302
 
303
+
304
+
283
305
  export async function getAnimeInfo(animeUrl) {
284
306
  const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
285
307
  const $ = cheerio.load(res.data);
@@ -53,9 +53,11 @@ export async function getSendvidVideo(embedUrl) {
53
53
 
54
54
  export async function getVidmolyOrOneuploadVideo(embedUrl) {
55
55
  try {
56
+ console.log(embedUrl)
56
57
  const { data } = await axios.get(embedUrl, {
57
58
  headers: getHeaders(embedUrl),
58
59
  });
60
+ console.log(data)
59
61
  const $ = cheerio.load(data);
60
62
  const scripts = $("script");
61
63