better-ani-scraped 1.6.4 → 1.6.6
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/DOCUMENTATION.md
CHANGED
|
@@ -28,7 +28,7 @@ const crunchyroll = new AnimeScraper('crunchyroll') //for Crunchyroll
|
|
|
28
28
|
## `AnimeScraper("animesama")` methods
|
|
29
29
|
|
|
30
30
|
- [searchAnime](#animesamasearchanimequery-limit--10-wantedlanguages--vostfr-vf-vastfr-wantedtypes--anime-film-page--null)
|
|
31
|
-
- [getSeasons](#animesamagetseasonsanimeurl-language--vostfr)
|
|
31
|
+
- [getSeasons](#animesamagetseasonsanimeurl-language--vostfr-vf-va-vkr-vcn-vqc-vf1-vf2)
|
|
32
32
|
- [getEpisodeTitles](#animesamagetepisodetitlesseasonurl-customchromiumpath)
|
|
33
33
|
- [getEmbed](#animesamagetembedseasonurl-hostpriority--sendvid-sibnet-vidmoly-oneupload-allhost--false-includeinfo--false-customchromiumpath)
|
|
34
34
|
- [getAnimeInfo](#animesamagetanimeinfoanimeurl)
|
|
@@ -63,22 +63,26 @@ Searches for anime titles that match the given query.
|
|
|
63
63
|
|
|
64
64
|
---
|
|
65
65
|
|
|
66
|
-
### `animesama.getSeasons(animeUrl,
|
|
67
|
-
Fetches all available seasons of an anime in the
|
|
66
|
+
### `animesama.getSeasons(animeUrl, languagePriority = ["vostfr", "vf", "va", "vkr", "vcn", "vqc", "vf1", "vf2"])`
|
|
67
|
+
Fetches all available seasons of an anime in the first valid language specified.
|
|
68
68
|
|
|
69
69
|
- **Parameters:**
|
|
70
70
|
- `animeUrl` *(string)*: The full URL of the anime.
|
|
71
|
-
- `
|
|
71
|
+
- `languagePriority` *(string[])*: Array of preferred language.
|
|
72
72
|
- **Returns:**
|
|
73
73
|
Either an array of season objects:
|
|
74
74
|
```js
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
{
|
|
76
|
+
language: string,
|
|
77
|
+
seasons: [
|
|
78
|
+
{
|
|
79
|
+
title: string,
|
|
80
|
+
url: string
|
|
81
|
+
},
|
|
82
|
+
...
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
|
|
82
86
|
```
|
|
83
87
|
Else, an error object if the language is not available.
|
|
84
88
|
|
|
@@ -164,17 +168,17 @@ Checks which languages are available for a given anime season (Avoid using `numb
|
|
|
164
168
|
- `wantedLanguages` *(string[])*: Language codes to check (e.g., ["vostfr", "vf", "va", ...]).
|
|
165
169
|
- `numberEpisodes` *(boolean)*: If `true`, also fetches the number of episodes in each language.
|
|
166
170
|
- **Returns:**
|
|
167
|
-
Array of objects containing available languages and their episode count:
|
|
171
|
+
Array of objects containing available languages and their episode count if numberEpisodes is true:
|
|
168
172
|
```js
|
|
169
173
|
[
|
|
170
174
|
{
|
|
171
175
|
language: string,
|
|
172
|
-
episodeCount: number
|
|
176
|
+
episodeCount: number
|
|
173
177
|
},
|
|
174
178
|
...
|
|
175
179
|
]
|
|
176
180
|
```
|
|
177
|
-
|
|
181
|
+
Or an array of available languages
|
|
178
182
|
---
|
|
179
183
|
|
|
180
184
|
### `animesama.getAllAnime(wantedLanguages = ["vostfr", "vf", "vastfr"], wantedTypes = ["Anime", "Film"], page = null, output = "anime_list.json", get_seasons = false)`
|
|
@@ -2,7 +2,7 @@ import { AnimeScraper } from "../../index.js"; // REPLACE BY "from 'better-ani-s
|
|
|
2
2
|
|
|
3
3
|
const main = async () => {
|
|
4
4
|
const animesama = new AnimeScraper('animesama');
|
|
5
|
-
const seasonUrl = "https://anime-sama.fr/catalogue/
|
|
5
|
+
const seasonUrl = "https://anime-sama.fr/catalogue/86-eighty-six/saison1/vostfr/";
|
|
6
6
|
|
|
7
7
|
const animeLanguages = await animesama.getAvailableLanguages(seasonUrl, ["vostfr", "vf", "va", "vkr","vcn", "vqc", "vf1", "vf2"], false);
|
|
8
8
|
console.log(animeLanguages);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AnimeScraper
|
|
1
|
+
import { AnimeScraper } from "../../index.js"; // REPLACE BY "from 'better-ani-scraped';"
|
|
2
2
|
|
|
3
3
|
const main = async () => {
|
|
4
4
|
const animesama = new AnimeScraper('animesama');
|
|
5
|
-
const animeUrl = "https://anime-sama.fr/catalogue/
|
|
5
|
+
const animeUrl = "https://anime-sama.fr/catalogue/sword-art-online";
|
|
6
6
|
|
|
7
|
-
const seasons = await animesama.getSeasons(animeUrl, "vostfr");
|
|
7
|
+
const seasons = await animesama.getSeasons(animeUrl, ["vostfr", "vf"]);
|
|
8
8
|
console.log("Seasons:", seasons);
|
|
9
9
|
};
|
|
10
10
|
|
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -118,62 +118,60 @@ export async function searchAnime(
|
|
|
118
118
|
return results;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export async function getSeasons(animeUrl,
|
|
121
|
+
export async function getSeasons(animeUrl, languagePriority = ["vostfr", "vf", "va", "vkr", "vcn", "vqc", "vf1", "vf2"]) {
|
|
122
122
|
const res = await axios.get(animeUrl, { headers: getHeaders(CATALOGUE_URL) });
|
|
123
123
|
const html = res.data;
|
|
124
124
|
|
|
125
|
-
// Only keep the part before the Kai section
|
|
126
125
|
const mainAnimeOnly = html.split("Anime Version Kai")[0];
|
|
127
|
-
|
|
128
126
|
const $ = cheerio.load(mainAnimeOnly);
|
|
129
127
|
const scriptTags = $("script")
|
|
130
128
|
.toArray()
|
|
131
|
-
.filter(
|
|
132
|
-
return $(script).html().includes("panneauAnime");
|
|
133
|
-
});
|
|
129
|
+
.filter(script => $(script).html().includes("panneauAnime"));
|
|
134
130
|
|
|
135
131
|
const animeName = animeUrl.split("/")[4];
|
|
136
|
-
|
|
137
|
-
let languageAvailable = false;
|
|
132
|
+
let seasons = [];
|
|
138
133
|
|
|
139
|
-
for (
|
|
140
|
-
|
|
134
|
+
for (const language of languagePriority) {
|
|
135
|
+
seasons = [];
|
|
136
|
+
let languageAvailable = false;
|
|
141
137
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
145
|
-
.replace(/\/\/.*$/gm, "");
|
|
138
|
+
for (let script of scriptTags) {
|
|
139
|
+
const content = $(script).html();
|
|
146
140
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
const uncommentedContent = content
|
|
142
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
143
|
+
.replace(/\/\/.*$/gm, "");
|
|
150
144
|
|
|
151
|
-
|
|
152
|
-
const title = match[1];
|
|
153
|
-
const href = match[2].split("/")[0];
|
|
154
|
-
const fullUrl = `${CATALOGUE_URL}/${animeName}/${href}/${language}`;
|
|
145
|
+
const matches = [...uncommentedContent.matchAll(/panneauAnime\("([^"]+)", "([^"]+)"\);/g)];
|
|
155
146
|
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
147
|
+
for (let match of matches) {
|
|
148
|
+
const title = match[1];
|
|
149
|
+
const href = match[2].split("/")[0];
|
|
150
|
+
const fullUrl = `${CATALOGUE_URL}/${animeName}/${href}/${language}`;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const check = await axios.head(fullUrl, {
|
|
154
|
+
headers: getHeaders(animeUrl),
|
|
155
|
+
});
|
|
156
|
+
if (check.status === 200) {
|
|
157
|
+
languageAvailable = true;
|
|
158
|
+
seasons.push({ title, url: fullUrl });
|
|
159
|
+
}
|
|
160
|
+
} catch (err) {
|
|
161
|
+
// Ignore invalid URLs
|
|
163
162
|
}
|
|
164
|
-
} catch (err) {
|
|
165
|
-
// Ignore missing URLs
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
|
-
}
|
|
169
165
|
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
if (languageAvailable) {
|
|
167
|
+
return { language, seasons };
|
|
168
|
+
}
|
|
172
169
|
}
|
|
173
170
|
|
|
174
|
-
return
|
|
171
|
+
return { error: "No language available in : " + languagePriority.join(", ") };
|
|
175
172
|
}
|
|
176
173
|
|
|
174
|
+
|
|
177
175
|
export async function getEpisodeTitles(seasonUrl, customChromiumPath) {
|
|
178
176
|
let browser;
|
|
179
177
|
try {
|
|
@@ -377,7 +375,7 @@ export async function getAvailableLanguages(
|
|
|
377
375
|
const episodeCount = (await getEmbed(languageUrl)).length;
|
|
378
376
|
languageLinks.push({ language: language.toUpperCase(), episodeCount: episodeCount });
|
|
379
377
|
} else {
|
|
380
|
-
languageLinks.push(
|
|
378
|
+
languageLinks.push(language.toUpperCase());
|
|
381
379
|
}
|
|
382
380
|
|
|
383
381
|
}
|