better-ani-scraped 1.2.7 → 1.3.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/package.json +1 -1
- package/scrapers/animesama.js +56 -26
- package/utils/setupChromium.js +21 -0
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import * as cheerio from "cheerio";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
const BASE_URL = "https://anime-sama.fr";
|
|
7
10
|
const CATALOGUE_URL = `${BASE_URL}/catalogue`;
|
|
11
|
+
const execAsync = promisify(exec);
|
|
12
|
+
|
|
8
13
|
|
|
9
14
|
function getHeaders(referer = BASE_URL) {
|
|
10
15
|
return {
|
|
@@ -125,39 +130,64 @@ export async function getSeasons(animeUrl, language = "vostfr") {
|
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
|
|
133
|
+
async function ensureChromiumInstalled() {
|
|
134
|
+
const basePath = path.join(
|
|
135
|
+
process.env.HOME || process.env.USERPROFILE,
|
|
136
|
+
'.cache',
|
|
137
|
+
'puppeteer',
|
|
138
|
+
'chrome'
|
|
139
|
+
);
|
|
140
|
+
const chromiumPath = path.join(basePath, 'win64-135.0.7049.95', 'chrome-win64', 'chrome.exe');
|
|
141
|
+
if (!fs.existsSync(chromiumPath)) {
|
|
142
|
+
console.log("📦 Téléchargement de Chromium 135.0.7049.95...");
|
|
143
|
+
await execAsync('npx puppeteer browsers install chrome@135.0.7049.95');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return chromiumPath;
|
|
147
|
+
}
|
|
128
148
|
export async function getEpisodeTitles(animeUrl) {
|
|
129
|
-
console.log('Executable path:', puppeteer.executablePath());
|
|
130
149
|
let browser;
|
|
131
150
|
try {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
const puppeteer = await import('puppeteer');
|
|
152
|
+
const executablePath = await ensureChromiumInstalled();
|
|
153
|
+
|
|
154
|
+
browser = await puppeteer.launch({
|
|
155
|
+
headless: true,
|
|
156
|
+
executablePath: executablePath,
|
|
157
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const page = await browser.newPage();
|
|
161
|
+
|
|
162
|
+
await page.setRequestInterception(true);
|
|
163
|
+
page.on('request', (req) => {
|
|
164
|
+
const blocked = ['image', 'stylesheet', 'font', 'media'];
|
|
165
|
+
if (blocked.includes(req.resourceType())) {
|
|
166
|
+
req.abort();
|
|
167
|
+
} else {
|
|
168
|
+
req.continue();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await page.goto(animeUrl, { waitUntil: 'domcontentloaded' });
|
|
173
|
+
await page.waitForSelector('#selectEpisodes');
|
|
174
|
+
|
|
175
|
+
const titres = await page.$$eval('#selectEpisodes option', options =>
|
|
176
|
+
options.map(o => o.textContent.trim())
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return titres;
|
|
180
|
+
|
|
152
181
|
} catch (error) {
|
|
153
|
-
|
|
154
|
-
|
|
182
|
+
console.error('Erreur dans la récupération des titres:', error);
|
|
183
|
+
return [];
|
|
155
184
|
} finally {
|
|
156
|
-
|
|
185
|
+
if (browser) await browser.close();
|
|
157
186
|
}
|
|
158
187
|
}
|
|
159
188
|
|
|
160
189
|
|
|
190
|
+
|
|
161
191
|
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
162
192
|
const res = await axios.get(animeUrl, {
|
|
163
193
|
headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
|
|
@@ -171,7 +201,7 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
|
171
201
|
? animeUrl + scriptTag
|
|
172
202
|
: animeUrl + "/" + scriptTag;
|
|
173
203
|
|
|
174
|
-
const episodesJs = await axios
|
|
204
|
+
const episodesJs = await axios
|
|
175
205
|
.get(scriptUrl, { headers: getHeaders(animeUrl) })
|
|
176
206
|
.then((r) => r.data);
|
|
177
207
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
const REVISION = '135.0.7049.95';
|
|
8
|
+
const PLATFORM = 'win64'; // adapte si tu veux pour Linux/mac
|
|
9
|
+
const cacheDir = path.join(
|
|
10
|
+
process.env.LOCALAPPDATA || process.env.HOME || '',
|
|
11
|
+
'.cache', 'puppeteer', 'chrome', `${PLATFORM}-${REVISION}`
|
|
12
|
+
);
|
|
13
|
+
const executablePath = path.join(cacheDir, 'chrome-win64', 'chrome.exe');
|
|
14
|
+
|
|
15
|
+
export async function ensureChromiumInstalled() {
|
|
16
|
+
if (!fs.existsSync(executablePath)) {
|
|
17
|
+
console.log('📦 Téléchargement de Chromium .95...');
|
|
18
|
+
await execAsync(`npx puppeteer browsers install chrome@${REVISION}`);
|
|
19
|
+
}
|
|
20
|
+
return executablePath;
|
|
21
|
+
}
|