better-ani-scraped 1.3.0 → 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 +20 -13
- package/utils/setupChromium.js +0 -21
package/package.json
CHANGED
package/scrapers/animesama.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import * as cheerio from "cheerio";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import
|
|
5
|
-
import { exec } from 'child_process';
|
|
6
|
-
import { promisify } from 'util';
|
|
7
|
-
|
|
4
|
+
import puppeteer from'puppeteer';
|
|
8
5
|
|
|
9
6
|
const BASE_URL = "https://anime-sama.fr";
|
|
10
7
|
const CATALOGUE_URL = `${BASE_URL}/catalogue`;
|
|
11
|
-
const execAsync = promisify(exec);
|
|
12
|
-
|
|
13
8
|
|
|
14
9
|
function getHeaders(referer = BASE_URL) {
|
|
15
10
|
return {
|
|
@@ -130,7 +125,19 @@ export async function getSeasons(animeUrl, language = "vostfr") {
|
|
|
130
125
|
}
|
|
131
126
|
|
|
132
127
|
|
|
133
|
-
|
|
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
|
+
}
|
|
134
141
|
const basePath = path.join(
|
|
135
142
|
process.env.HOME || process.env.USERPROFILE,
|
|
136
143
|
'.cache',
|
|
@@ -138,22 +145,23 @@ async function ensureChromiumInstalled() {
|
|
|
138
145
|
'chrome'
|
|
139
146
|
);
|
|
140
147
|
const chromiumPath = path.join(basePath, 'win64-135.0.7049.95', 'chrome-win64', 'chrome.exe');
|
|
148
|
+
|
|
141
149
|
if (!fs.existsSync(chromiumPath)) {
|
|
142
|
-
console.log("📦
|
|
150
|
+
console.log("📦 Downloading Chromium 135.0.7049.95...");
|
|
143
151
|
await execAsync('npx puppeteer browsers install chrome@135.0.7049.95');
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
return chromiumPath;
|
|
147
155
|
}
|
|
148
|
-
export async function getEpisodeTitles(animeUrl) {
|
|
156
|
+
export async function getEpisodeTitles(animeUrl, customChromiumPath) {
|
|
149
157
|
let browser;
|
|
150
158
|
try {
|
|
151
159
|
const puppeteer = await import('puppeteer');
|
|
152
|
-
const executablePath = await ensureChromiumInstalled();
|
|
160
|
+
const executablePath = await ensureChromiumInstalled(customChromiumPath);
|
|
153
161
|
|
|
154
162
|
browser = await puppeteer.launch({
|
|
155
163
|
headless: true,
|
|
156
|
-
executablePath
|
|
164
|
+
executablePath,
|
|
157
165
|
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
158
166
|
});
|
|
159
167
|
|
|
@@ -179,7 +187,7 @@ export async function getEpisodeTitles(animeUrl) {
|
|
|
179
187
|
return titres;
|
|
180
188
|
|
|
181
189
|
} catch (error) {
|
|
182
|
-
console.error('
|
|
190
|
+
console.error('Error while retrieving titles :', error);
|
|
183
191
|
return [];
|
|
184
192
|
} finally {
|
|
185
193
|
if (browser) await browser.close();
|
|
@@ -187,7 +195,6 @@ export async function getEpisodeTitles(animeUrl) {
|
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
|
|
190
|
-
|
|
191
198
|
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
192
199
|
const res = await axios.get(animeUrl, {
|
|
193
200
|
headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
|
package/utils/setupChromium.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|