Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -258,7 +258,7 @@ async function downloadVideoR34(url) {
|
|
| 258 |
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
| 259 |
});
|
| 260 |
const page = await browser.newPage();
|
| 261 |
-
const downloadPath = path.resolve(os.tmpdir());
|
| 262 |
|
| 263 |
await page.setExtraHTTPHeaders({
|
| 264 |
'User-Agent': getRandomUserAgent(),
|
|
@@ -267,44 +267,31 @@ async function downloadVideoR34(url) {
|
|
| 267 |
});
|
| 268 |
|
| 269 |
await page.goto(url, { waitUntil: 'networkidle0' });
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
const result = await page.evaluate(() => {
|
| 273 |
const infoElements = document.querySelectorAll("#tab_video_info > div");
|
| 274 |
-
const links = Array.from(document.querySelectorAll('a')).map(a => ({
|
| 275 |
-
href: a.href,
|
| 276 |
-
text: a.textContent.trim()
|
| 277 |
-
}));
|
| 278 |
-
|
| 279 |
if (infoElements.length > 0) {
|
| 280 |
const download = infoElements[infoElements.length - 1];
|
| 281 |
if (download) {
|
| 282 |
const wrapDivsDownload = download.querySelectorAll("div.wrap > a");
|
| 283 |
-
return
|
| 284 |
}
|
| 285 |
}
|
| 286 |
-
return
|
| 287 |
});
|
| 288 |
-
|
| 289 |
-
const { downloadLink, links } = result;
|
| 290 |
-
|
| 291 |
let filePath = null;
|
| 292 |
-
let
|
|
|
|
| 293 |
if (downloadLink) {
|
| 294 |
const response = await axios({
|
| 295 |
method: 'GET',
|
| 296 |
url: downloadLink,
|
| 297 |
responseType: 'stream'
|
| 298 |
});
|
|
|
|
| 299 |
|
| 300 |
-
|
| 301 |
-
const contentDisposition = response.headers['content-disposition'];
|
| 302 |
-
filename = contentDisposition ? contentDisposition.split('filename=')[1] : null;
|
| 303 |
-
if (!filename) {
|
| 304 |
-
filename = url.match(/video\/(\d+)\/([a-zA-Z0-9-]+)\//)[2] + '.mp4'; // Adjust as needed
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
filePath = path.join(downloadPath, filename);
|
| 308 |
const writer = fs.createWriteStream(filePath);
|
| 309 |
|
| 310 |
response.data.pipe(writer);
|
|
@@ -313,6 +300,7 @@ async function downloadVideoR34(url) {
|
|
| 313 |
writer.on('finish', resolve);
|
| 314 |
writer.on('error', reject);
|
| 315 |
});
|
|
|
|
| 316 |
} else {
|
| 317 |
console.error('Download link not found.');
|
| 318 |
}
|
|
@@ -320,10 +308,8 @@ async function downloadVideoR34(url) {
|
|
| 320 |
await browser.close();
|
| 321 |
|
| 322 |
return {
|
| 323 |
-
download: "https://arashicode-komik.hf.space/static/" + filename,
|
| 324 |
path: filePath,
|
| 325 |
-
|
| 326 |
-
links
|
| 327 |
};
|
| 328 |
}
|
| 329 |
|
|
|
|
| 258 |
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
| 259 |
});
|
| 260 |
const page = await browser.newPage();
|
| 261 |
+
const downloadPath = path.resolve(os.tmpdir());
|
| 262 |
|
| 263 |
await page.setExtraHTTPHeaders({
|
| 264 |
'User-Agent': getRandomUserAgent(),
|
|
|
|
| 267 |
});
|
| 268 |
|
| 269 |
await page.goto(url, { waitUntil: 'networkidle0' });
|
| 270 |
+
|
| 271 |
+
const downloadLink = await page.evaluate(() => {
|
|
|
|
| 272 |
const infoElements = document.querySelectorAll("#tab_video_info > div");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
if (infoElements.length > 0) {
|
| 274 |
const download = infoElements[infoElements.length - 1];
|
| 275 |
if (download) {
|
| 276 |
const wrapDivsDownload = download.querySelectorAll("div.wrap > a");
|
| 277 |
+
return wrapDivsDownload[0].href;
|
| 278 |
}
|
| 279 |
}
|
| 280 |
+
return null;
|
| 281 |
});
|
| 282 |
+
|
|
|
|
|
|
|
| 283 |
let filePath = null;
|
| 284 |
+
let title;
|
| 285 |
+
|
| 286 |
if (downloadLink) {
|
| 287 |
const response = await axios({
|
| 288 |
method: 'GET',
|
| 289 |
url: downloadLink,
|
| 290 |
responseType: 'stream'
|
| 291 |
});
|
| 292 |
+
title = url.match(/video\/(\d+)\/([a-zA-Z0-9-]+)\//)[2];
|
| 293 |
|
| 294 |
+
filePath = path.join(downloadPath, `/${title}.mp4`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
const writer = fs.createWriteStream(filePath);
|
| 296 |
|
| 297 |
response.data.pipe(writer);
|
|
|
|
| 300 |
writer.on('finish', resolve);
|
| 301 |
writer.on('error', reject);
|
| 302 |
});
|
| 303 |
+
|
| 304 |
} else {
|
| 305 |
console.error('Download link not found.');
|
| 306 |
}
|
|
|
|
| 308 |
await browser.close();
|
| 309 |
|
| 310 |
return {
|
|
|
|
| 311 |
path: filePath,
|
| 312 |
+
download: `https://arashicode-komik.hf.space/static/${title}.mp4`,
|
|
|
|
| 313 |
};
|
| 314 |
}
|
| 315 |
|