better-ani-scraped 1.1.1 → 1.2.0

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.
@@ -3,7 +3,7 @@ import { AnimeScraper, getVideoUrlFromEmbed } from "../index.js"; // REPLACE BY
3
3
  const main = async () => {
4
4
  const scraper = new AnimeScraper('animesama');
5
5
 
6
- const search = await scraper.searchAnime("frieren");
6
+ const search = await scraper.searchAnime("86");
7
7
  console.log("Search Results:", search);
8
8
 
9
9
  const animeUrl = Object.values(search)[0].url;
@@ -16,7 +16,7 @@ const main = async () => {
16
16
  ]);
17
17
  console.log("Embed Links:", embeds);
18
18
 
19
- const videoUrl = await getVideoUrlFromEmbed("sibnet", embeds[11].url)
19
+ const videoUrl = await getVideoUrlFromEmbed("sibnet", embeds[0].url)
20
20
  console.log("Video URL:", videoUrl);
21
21
  };
22
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-ani-scraped",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Scrape anime data from different sources (only anime-sama.fr for the moment)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -178,34 +178,45 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
178
178
  ];
179
179
  if (!matches.length) throw new Error("No episode arrays found");
180
180
 
181
- let allEmbeds = [];
182
-
181
+ // Parse les arrays et crée une matrice [epsX][index]
182
+ let episodeMatrix = [];
183
183
  for (const [, , arrayString] of matches) {
184
184
  try {
185
- const links = eval(arrayString);
186
- allEmbeds.push(...links);
185
+ const links = eval(arrayString);
186
+ episodeMatrix.push(links);
187
187
  } catch (e) {
188
188
  console.warn("Could not parse embed array:", e);
189
189
  }
190
190
  }
191
- for (const host of hostPriority) {
192
- const filtered = allEmbeds.filter((url) => url.includes(host));
193
- if (filtered.length) {
194
- const titles = await getEpisodeTitles(animeUrl);
195
- return titles.slice(0, filtered.length).map((title, i) => ({
196
- title,
197
- url: filtered[i]
198
- }));
191
+
192
+ // Déterminer le nombre total d'épisodes max (plus long des arrays)
193
+ const maxEpisodes = Math.max(...episodeMatrix.map(arr => arr.length));
194
+ const finalEmbeds = [];
195
+
196
+ // Parcours vertical
197
+ for (let i = 0; i < maxEpisodes; i++) {
198
+ let selectedUrl = null;
199
+
200
+ for (const host of hostPriority) {
201
+ for (const arr of episodeMatrix) {
202
+ if (i < arr.length && arr[i].includes(host)) {
203
+ selectedUrl = arr[i];
204
+ break;
205
+ }
206
+ }
207
+ if (selectedUrl) break;
199
208
  }
209
+
210
+ finalEmbeds.push(selectedUrl || null);
200
211
  }
212
+
201
213
  const titles = await getEpisodeTitles(animeUrl);
202
- return titles.slice(0, allEmbeds.length).map((title, i) => ({
214
+ return titles.slice(0, finalEmbeds.length).map((title, i) => ({
203
215
  title,
204
- url: allEmbeds[i]
216
+ url: finalEmbeds[i]
205
217
  }));
206
218
  }
207
219
 
208
-
209
220
  export async function getAnimeInfo(animeUrl) {
210
221
  const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
211
222
  const $ = cheerio.load(res.data);