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.
- package/examples/example_usage_01.js +2 -2
- package/package.json +1 -1
- package/scrapers/animesama.js +26 -15
|
@@ -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("
|
|
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[
|
|
19
|
+
const videoUrl = await getVideoUrlFromEmbed("sibnet", embeds[0].url)
|
|
20
20
|
console.log("Video URL:", videoUrl);
|
|
21
21
|
};
|
|
22
22
|
|
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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,
|
|
214
|
+
return titles.slice(0, finalEmbeds.length).map((title, i) => ({
|
|
203
215
|
title,
|
|
204
|
-
url:
|
|
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);
|