better-ani-scraped 1.3.0 → 1.3.2
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 +23 -15
- package/scrapers/scrapers.js +2 -2
- 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,20 @@ 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) {
|
|
135
|
+
if (fs.existsSync(customPath)) {
|
|
136
|
+
console.log("customPath:", customPath);
|
|
137
|
+
return customPath;
|
|
138
|
+
} else {
|
|
139
|
+
console.log(`The custom path to Chromium is invalid : ${customPath}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
134
142
|
const basePath = path.join(
|
|
135
143
|
process.env.HOME || process.env.USERPROFILE,
|
|
136
144
|
'.cache',
|
|
@@ -138,22 +146,23 @@ async function ensureChromiumInstalled() {
|
|
|
138
146
|
'chrome'
|
|
139
147
|
);
|
|
140
148
|
const chromiumPath = path.join(basePath, 'win64-135.0.7049.95', 'chrome-win64', 'chrome.exe');
|
|
149
|
+
|
|
141
150
|
if (!fs.existsSync(chromiumPath)) {
|
|
142
|
-
console.log("📦
|
|
151
|
+
console.log("📦 Downloading Chromium 135.0.7049.95...");
|
|
143
152
|
await execAsync('npx puppeteer browsers install chrome@135.0.7049.95');
|
|
144
153
|
}
|
|
145
154
|
|
|
146
155
|
return chromiumPath;
|
|
147
156
|
}
|
|
148
|
-
export async function getEpisodeTitles(animeUrl) {
|
|
157
|
+
export async function getEpisodeTitles(animeUrl, customChromiumPath) {
|
|
149
158
|
let browser;
|
|
150
159
|
try {
|
|
151
160
|
const puppeteer = await import('puppeteer');
|
|
152
|
-
const executablePath = await ensureChromiumInstalled();
|
|
161
|
+
const executablePath = await ensureChromiumInstalled(customChromiumPath);
|
|
153
162
|
|
|
154
163
|
browser = await puppeteer.launch({
|
|
155
164
|
headless: true,
|
|
156
|
-
executablePath
|
|
165
|
+
executablePath,
|
|
157
166
|
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
158
167
|
});
|
|
159
168
|
|
|
@@ -179,7 +188,7 @@ export async function getEpisodeTitles(animeUrl) {
|
|
|
179
188
|
return titres;
|
|
180
189
|
|
|
181
190
|
} catch (error) {
|
|
182
|
-
console.error('
|
|
191
|
+
console.error('Error while retrieving titles :', error);
|
|
183
192
|
return [];
|
|
184
193
|
} finally {
|
|
185
194
|
if (browser) await browser.close();
|
|
@@ -187,8 +196,7 @@ export async function getEpisodeTitles(animeUrl) {
|
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
|
|
190
|
-
|
|
191
|
-
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
199
|
+
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"], customChromiumPath) {
|
|
192
200
|
const res = await axios.get(animeUrl, {
|
|
193
201
|
headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
|
|
194
202
|
});
|
|
@@ -236,7 +244,7 @@ export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
|
236
244
|
finalEmbeds.push(selectedUrl || null);
|
|
237
245
|
}
|
|
238
246
|
|
|
239
|
-
const titles = await getEpisodeTitles(animeUrl);
|
|
247
|
+
const titles = await getEpisodeTitles(animeUrl, customChromiumPath);
|
|
240
248
|
return finalEmbeds.map((url, i) => ({
|
|
241
249
|
title: titles[i] || "Untitled",
|
|
242
250
|
url,
|
package/scrapers/scrapers.js
CHANGED
|
@@ -84,9 +84,9 @@ export class AnimeScraper {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
async getEpisodeTitles(animeUrl) {
|
|
87
|
+
async getEpisodeTitles(animeUrl, ...rest) {
|
|
88
88
|
try {
|
|
89
|
-
return await this.source.getEpisodeTitles(animeUrl);
|
|
89
|
+
return await this.source.getEpisodeTitles(animeUrl, ...rest);
|
|
90
90
|
} catch (error) {
|
|
91
91
|
console.error(`This scraper does not have the getRandomAnime function implemented or an error happened -> ${error}`);
|
|
92
92
|
return null;
|
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
|
-
}
|