better-ani-scraped 1.2.8 → 1.3.1
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 +62 -27
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -125,37 +125,72 @@ export async function getSeasons(animeUrl, language = "vostfr") {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
import path from 'path';
|
|
129
|
+
import { exec as execCallback } from 'child_process';
|
|
130
|
+
import { promisify } from 'util';
|
|
131
|
+
const execAsync = promisify(execCallback);
|
|
132
|
+
|
|
133
|
+
async function ensureChromiumInstalled(customPath) {
|
|
134
|
+
if (customPath && customPath.includes('chrome')) {
|
|
135
|
+
if (fs.existsSync(customPath)) {
|
|
136
|
+
return customPath;
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error(`The custom path to Chromium is invalid : ${customPath}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const basePath = path.join(
|
|
142
|
+
process.env.HOME || process.env.USERPROFILE,
|
|
143
|
+
'.cache',
|
|
144
|
+
'puppeteer',
|
|
145
|
+
'chrome'
|
|
146
|
+
);
|
|
147
|
+
const chromiumPath = path.join(basePath, 'win64-135.0.7049.95', 'chrome-win64', 'chrome.exe');
|
|
148
|
+
|
|
149
|
+
if (!fs.existsSync(chromiumPath)) {
|
|
150
|
+
console.log("📦 Downloading Chromium 135.0.7049.95...");
|
|
151
|
+
await execAsync('npx puppeteer browsers install chrome@135.0.7049.95');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return chromiumPath;
|
|
155
|
+
}
|
|
156
|
+
export async function getEpisodeTitles(animeUrl, customChromiumPath) {
|
|
129
157
|
let browser;
|
|
130
158
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
const puppeteer = await import('puppeteer');
|
|
160
|
+
const executablePath = await ensureChromiumInstalled(customChromiumPath);
|
|
161
|
+
|
|
162
|
+
browser = await puppeteer.launch({
|
|
163
|
+
headless: true,
|
|
164
|
+
executablePath,
|
|
165
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const page = await browser.newPage();
|
|
169
|
+
|
|
170
|
+
await page.setRequestInterception(true);
|
|
171
|
+
page.on('request', (req) => {
|
|
172
|
+
const blocked = ['image', 'stylesheet', 'font', 'media'];
|
|
173
|
+
if (blocked.includes(req.resourceType())) {
|
|
174
|
+
req.abort();
|
|
175
|
+
} else {
|
|
176
|
+
req.continue();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
await page.goto(animeUrl, { waitUntil: 'domcontentloaded' });
|
|
181
|
+
await page.waitForSelector('#selectEpisodes');
|
|
182
|
+
|
|
183
|
+
const titres = await page.$$eval('#selectEpisodes option', options =>
|
|
184
|
+
options.map(o => o.textContent.trim())
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return titres;
|
|
188
|
+
|
|
154
189
|
} catch (error) {
|
|
155
|
-
|
|
156
|
-
|
|
190
|
+
console.error('Error while retrieving titles :', error);
|
|
191
|
+
return [];
|
|
157
192
|
} finally {
|
|
158
|
-
|
|
193
|
+
if (browser) await browser.close();
|
|
159
194
|
}
|
|
160
195
|
}
|
|
161
196
|
|