better-ani-scraped 1.6.4 → 1.6.5
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,12 +63,12 @@ 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
|
|
@@ -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/aggretsuko/";
|
|
6
6
|
|
|
7
|
-
const seasons = await animesama.getSeasons(animeUrl,
|
|
7
|
+
const seasons = await animesama.getSeasons(animeUrl, );
|
|
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 {
|