better-ani-scraped 1.6.3 → 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, language = "vostfr")`
67
- Fetches all available seasons of an anime in the specified language.
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
- - `language` *(string)*: Language to filter by (default: "vostfr").
71
+ - `languagePriority` *(string[])*: Array of preferred language.
72
72
  - **Returns:**
73
73
  Either an array of season objects:
74
74
  ```js
@@ -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/86-eighty-six/saison1/vostfr/";
5
+ const seasonUrl = "https://anime-sama.fr/catalogue/aggretsuko/saison1/vf/";
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, getVideoUrlFromEmbed } from "../../index.js"; // REPLACE BY "from 'better-ani-scraped';"
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/86-eighty-six/";
5
+ const animeUrl = "https://anime-sama.fr/catalogue/aggretsuko/";
6
6
 
7
- const seasons = await animesama.getSeasons(animeUrl, "vostfr");
7
+ const seasons = await animesama.getSeasons(animeUrl, );
8
8
  console.log("Seasons:", seasons);
9
9
  };
10
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-ani-scraped",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "Scrape anime data from different sources (only anime-sama.fr for the moment)",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -118,62 +118,60 @@ export async function searchAnime(
118
118
  return results;
119
119
  }
120
120
 
121
- export async function getSeasons(animeUrl, language = "vostfr") {
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((script) => {
132
- return $(script).html().includes("panneauAnime");
133
- });
129
+ .filter(script => $(script).html().includes("panneauAnime"));
134
130
 
135
131
  const animeName = animeUrl.split("/")[4];
136
- const seasons = [];
137
- let languageAvailable = false;
132
+ let seasons = [];
138
133
 
139
- for (let script of scriptTags) {
140
- const content = $(script).html();
134
+ for (const language of languagePriority) {
135
+ seasons = [];
136
+ let languageAvailable = false;
141
137
 
142
- // Remove anything inside comments either ("/* */" or "//")
143
- const uncommentedContent = content
144
- .replace(/\/\*[\s\S]*?\*\//g, "")
145
- .replace(/\/\/.*$/gm, "");
138
+ for (let script of scriptTags) {
139
+ const content = $(script).html();
146
140
 
147
- const matches = [
148
- ...uncommentedContent.matchAll(/panneauAnime\("([^"]+)", "([^"]+)"\);/g),
149
- ];
141
+ const uncommentedContent = content
142
+ .replace(/\/\*[\s\S]*?\*\//g, "")
143
+ .replace(/\/\/.*$/gm, "");
150
144
 
151
- for (let match of matches) {
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
- try {
157
- const check = await axios.head(fullUrl, {
158
- headers: getHeaders(animeUrl),
159
- });
160
- if (check.status === 200) {
161
- languageAvailable = true;
162
- seasons.push({ title, url: fullUrl });
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
- if (!languageAvailable) {
171
- return { error: `Language "${language}" is not available for this anime.` };
166
+ if (languageAvailable) {
167
+ return { language, seasons };
168
+ }
172
169
  }
173
170
 
174
- return seasons;
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 {
@@ -367,7 +365,7 @@ export async function getAvailableLanguages(
367
365
 
368
366
  // Iterate over each possible language and check if the page exists
369
367
  for (let language of wantedLanguages) {
370
- const languageUrl = seasonUrl.replace("vostfr", `${language}`);
368
+ const languageUrl = seasonUrl.split('/').map((s, i) => i === 6 ? language : s).join('/');
371
369
  try {
372
370
  const res = await axios.get(languageUrl, {
373
371
  headers: getHeaders(CATALOGUE_URL),