multporn-api-sdk 0.1.3 → 0.1.4
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/dist/browser/index.js +1556 -206
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +1557 -206
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1556 -206
- package/dist/node/index.js.map +1 -1
- package/dist/rn/index.js +1556 -206
- package/dist/rn/index.js.map +1 -1
- package/dist/types/index.d.ts +22 -32
- package/dist/types/index.js +1576 -204
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as cheerio from 'cheerio';
|
|
2
|
+
import * as cheerio3 from 'cheerio/slim';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
4
9
|
function createCheerioDom() {
|
|
5
10
|
return {
|
|
6
11
|
parse(html) {
|
|
@@ -256,253 +261,1598 @@ var HttpClient = class {
|
|
|
256
261
|
}
|
|
257
262
|
};
|
|
258
263
|
|
|
259
|
-
// src/
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
// src/api/alphabet.ts
|
|
265
|
+
var alphabet_exports = {};
|
|
266
|
+
__export(alphabet_exports, {
|
|
267
|
+
alphabetItems: () => alphabetItems,
|
|
268
|
+
alphabetLetters: () => alphabetLetters
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// src/utils.ts
|
|
272
|
+
function toAbsolute(baseURL, href) {
|
|
267
273
|
if (!href) return void 0;
|
|
268
274
|
try {
|
|
269
|
-
|
|
270
|
-
return new URL(href, base).href;
|
|
275
|
+
return new URL(href).toString();
|
|
271
276
|
} catch {
|
|
272
|
-
|
|
277
|
+
if (href.startsWith("//")) {
|
|
278
|
+
const base = new URL(baseURL);
|
|
279
|
+
return `${base.protocol}${href}`;
|
|
280
|
+
}
|
|
281
|
+
return new URL(href.replace(/^\//, ""), baseURL.replace(/\/+$/, "") + "/").toString();
|
|
273
282
|
}
|
|
274
283
|
}
|
|
275
|
-
function
|
|
276
|
-
return
|
|
284
|
+
function uniq(arr) {
|
|
285
|
+
return Array.from(new Set(arr));
|
|
277
286
|
}
|
|
278
|
-
function
|
|
279
|
-
if (!
|
|
280
|
-
|
|
287
|
+
function absUrl(base, href) {
|
|
288
|
+
if (!href) return null;
|
|
289
|
+
try {
|
|
290
|
+
return new URL(href, base).toString();
|
|
291
|
+
} catch {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
281
294
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
function normSpace(s) {
|
|
296
|
+
return (s ?? "").replace(/\s+/g, " ").trim();
|
|
297
|
+
}
|
|
298
|
+
function parseNumberLike(s) {
|
|
299
|
+
if (!s) return void 0;
|
|
300
|
+
const m = String(s).replace(/[^\d.,]/g, "").replace(",", ".");
|
|
301
|
+
const n = parseFloat(m);
|
|
302
|
+
return Number.isFinite(n) ? n : void 0;
|
|
303
|
+
}
|
|
304
|
+
function parseIntLike(s) {
|
|
305
|
+
if (!s) return void 0;
|
|
306
|
+
const n = parseInt(String(s).replace(/[^\d]/g, ""), 10);
|
|
307
|
+
return Number.isFinite(n) ? n : void 0;
|
|
308
|
+
}
|
|
309
|
+
function guessKindFromPath(path) {
|
|
310
|
+
const p = path.split("?")[0].split("#")[0];
|
|
311
|
+
if (p.includes("/hentai_manga/") || p.includes("/munga/")) return "manga";
|
|
312
|
+
if (p.includes("/comics/")) return "comics";
|
|
313
|
+
if (p.includes("/pictures/")) return "pictures";
|
|
314
|
+
if (p.includes("/humor/")) return "humor";
|
|
315
|
+
if (p.includes("/video/")) return "video";
|
|
316
|
+
if (p.includes("/games/")) return "game";
|
|
317
|
+
return "other";
|
|
318
|
+
}
|
|
319
|
+
function guessAlphabetSectionFromPath(path) {
|
|
320
|
+
const slug = String(path || "").trim().replace(/^\//, "").split("/")[0]?.toLowerCase();
|
|
321
|
+
const map = {
|
|
322
|
+
comics: "alphabetical_order_comics",
|
|
323
|
+
manga: "alphabetical_order_manga",
|
|
324
|
+
pictures: "alphabetical_order_pipictures",
|
|
325
|
+
porn_gifs: "alphabetical_order_gif",
|
|
326
|
+
characters: "alphabetical_order_characters",
|
|
327
|
+
category_comic: "alphabetical_order_category_comic",
|
|
328
|
+
authors_comics: "alphabetical_order_authors_comics",
|
|
329
|
+
authors_hentai: "alphabetical_order_authors_hentai",
|
|
330
|
+
pipictures: "alphabetical_order_pipictures"
|
|
331
|
+
};
|
|
332
|
+
return map[slug] || (slug ? `alphabetical_order_${slug}` : "alphabetical_order");
|
|
333
|
+
}
|
|
334
|
+
function pageIndexFromParam(raw) {
|
|
335
|
+
if (!raw) return null;
|
|
336
|
+
const decoded = decodeURIComponent(String(raw));
|
|
337
|
+
const parts = decoded.split(",").map((s) => parseInt(s.trim(), 10)).filter((n) => Number.isFinite(n));
|
|
338
|
+
if (!parts.length) return null;
|
|
339
|
+
return Math.max(...parts);
|
|
340
|
+
}
|
|
341
|
+
function pageIndexFromHref(href) {
|
|
342
|
+
if (!href) return null;
|
|
343
|
+
try {
|
|
344
|
+
const u = new URL(href, "https://example.com");
|
|
345
|
+
return pageIndexFromParam(u.searchParams.get("page"));
|
|
346
|
+
} catch {
|
|
347
|
+
const m = href.match(/[?&]page=([^&#]+)/i);
|
|
348
|
+
return m ? pageIndexFromParam(m[1]) : null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function extractTotalPages(html) {
|
|
352
|
+
const $ = cheerio3.load(html);
|
|
353
|
+
const root = $(
|
|
354
|
+
"ul.pager, nav.pagination, .pagination, .item-list .pager, #content .pager"
|
|
355
|
+
).first();
|
|
356
|
+
if (!root.length) return 1;
|
|
357
|
+
const lastHref = root.find('li.pager-last a[href], a[rel="last"], a[title*="Last"], a[title*="\u041F\u043E\u0441\u043B\u0435\u0434\u043D\u044F\u044F"]').attr("href") || void 0;
|
|
358
|
+
if (lastHref) {
|
|
359
|
+
const idx = pageIndexFromHref(lastHref);
|
|
360
|
+
if (idx != null) return Math.max(1, idx + 1);
|
|
361
|
+
}
|
|
362
|
+
let maxPages = 0;
|
|
363
|
+
root.find("a[href]").each((_, a) => {
|
|
364
|
+
const href = String($(a).attr("href") || "");
|
|
365
|
+
const idx = pageIndexFromHref(href);
|
|
366
|
+
if (idx != null) maxPages = Math.max(maxPages, idx + 1);
|
|
367
|
+
});
|
|
368
|
+
root.find("a, li, span").each((_, el) => {
|
|
369
|
+
const n = Number(($(el).text() || "").trim());
|
|
370
|
+
if (Number.isFinite(n)) maxPages = Math.max(maxPages, n);
|
|
371
|
+
});
|
|
372
|
+
return Math.max(1, maxPages || 1);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/parsers/alphabet.ts
|
|
376
|
+
function parseAlphabetLetters(html, baseURL) {
|
|
377
|
+
const $ = cheerio3.load(html);
|
|
378
|
+
const letters = [];
|
|
379
|
+
$(".views-summary a[href]").each((_, a) => {
|
|
380
|
+
const el = $(a);
|
|
381
|
+
const raw = normSpace(el.text());
|
|
382
|
+
if (!raw) return;
|
|
383
|
+
const count = parseIntLike(raw);
|
|
384
|
+
const label = raw.replace(/\(\s*\d+\s*\)\s*$/, "").trim() || raw;
|
|
385
|
+
const hrefRel = el.attr("href") || "";
|
|
386
|
+
const href = toAbsolute(baseURL, hrefRel) || "";
|
|
387
|
+
const lastSeg = decodeURIComponent((hrefRel.split("/").filter(Boolean).pop() || "").trim());
|
|
388
|
+
if (!label || !href) return;
|
|
389
|
+
letters.push({
|
|
390
|
+
label,
|
|
391
|
+
value: lastSeg || label,
|
|
392
|
+
href,
|
|
393
|
+
count: typeof count === "number" ? count : void 0,
|
|
394
|
+
active: el.hasClass("active") || /(^|\s)active(\s|$)/.test(el.attr("class") || "")
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
const uniq3 = /* @__PURE__ */ new Map();
|
|
398
|
+
for (const l of letters) if (!uniq3.has(l.value)) uniq3.set(l.value, l);
|
|
399
|
+
return Array.from(uniq3.values());
|
|
400
|
+
}
|
|
401
|
+
function parseAlphabetInline(html, baseURL) {
|
|
402
|
+
const $ = cheerio3.load(html);
|
|
403
|
+
const containers = [];
|
|
404
|
+
containers.push(...$(".view-glossary-comics").toArray());
|
|
405
|
+
if (containers.length === 0) containers.push(...$(".view-glossary").toArray());
|
|
406
|
+
if (containers.length === 0) {
|
|
407
|
+
const anyNodes = $(".view").has(".views-summary a").toArray();
|
|
408
|
+
const onlyElements = anyNodes.filter((n) => n?.type === "tag");
|
|
409
|
+
containers.push(...onlyElements);
|
|
410
|
+
}
|
|
411
|
+
if (containers.length === 0) return null;
|
|
412
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
413
|
+
for (const cont of containers) {
|
|
414
|
+
const $cont = $(cont);
|
|
415
|
+
$cont.find(".views-summary a[href]").each((__, a) => {
|
|
416
|
+
const el = $(a);
|
|
417
|
+
const raw = normSpace(el.text());
|
|
418
|
+
if (!raw) return;
|
|
419
|
+
const count = parseIntLike(raw);
|
|
420
|
+
const label = raw.replace(/\(\s*\d+\s*\)\s*$/, "").trim() || raw;
|
|
421
|
+
const hrefRel = el.attr("href") || "";
|
|
422
|
+
const hrefAbs = toAbsolute(baseURL, hrefRel);
|
|
423
|
+
if (!hrefAbs) return;
|
|
424
|
+
let section = "";
|
|
425
|
+
try {
|
|
426
|
+
const p = new URL(hrefAbs).pathname;
|
|
427
|
+
const m = p.match(/^\/([^/]+)/);
|
|
428
|
+
section = m ? m[1] : "";
|
|
429
|
+
} catch {
|
|
430
|
+
}
|
|
431
|
+
const value = decodeURIComponent((hrefRel.split("/").filter(Boolean).pop() || "").trim()) || label;
|
|
432
|
+
const entry = {
|
|
433
|
+
label,
|
|
434
|
+
value,
|
|
435
|
+
href: hrefAbs,
|
|
436
|
+
count: typeof count === "number" ? count : void 0,
|
|
437
|
+
active: el.hasClass("active") || /(^|\s)active(\s|$)/.test(el.attr("class") || "")
|
|
438
|
+
};
|
|
439
|
+
const arr = grouped.get(section) ?? [];
|
|
440
|
+
if (!arr.some((x) => x.value === entry.value)) arr.push(entry);
|
|
441
|
+
grouped.set(section, arr);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if (!grouped.size) return null;
|
|
445
|
+
let chosen = null;
|
|
446
|
+
for (const [sec, letters] of grouped.entries()) {
|
|
447
|
+
if (letters.some((l) => l.active)) {
|
|
448
|
+
chosen = { section: sec, letters };
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (!chosen) {
|
|
453
|
+
let bestSec = "";
|
|
454
|
+
let bestArr = [];
|
|
455
|
+
for (const [sec, letters] of grouped.entries()) {
|
|
456
|
+
if (letters.length > bestArr.length) {
|
|
457
|
+
bestSec = sec;
|
|
458
|
+
bestArr = letters;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
chosen = { section: bestSec, letters: bestArr };
|
|
462
|
+
}
|
|
463
|
+
if (!chosen) {
|
|
464
|
+
const [sec, letters] = grouped.entries().next().value;
|
|
465
|
+
chosen = { section: sec, letters };
|
|
466
|
+
}
|
|
467
|
+
chosen.letters.sort((a, b) => a.label.localeCompare(b.label, "en"));
|
|
468
|
+
if (!looksLikeAlphabet(chosen.letters)) return null;
|
|
469
|
+
return { section: chosen.section, letters: chosen.letters };
|
|
470
|
+
}
|
|
471
|
+
function looksLikeAlphabet(letters) {
|
|
472
|
+
const short = letters.filter((l) => /^[A-Z#]$/i.test(l.label.trim())).length;
|
|
473
|
+
return letters.length >= 10 && short >= 10;
|
|
474
|
+
}
|
|
475
|
+
function pickFromSrcset(srcset) {
|
|
476
|
+
if (!srcset) return;
|
|
477
|
+
const first = srcset.split(",")[0]?.trim();
|
|
478
|
+
if (!first) return;
|
|
479
|
+
const url = first.split(/\s+/)[0];
|
|
480
|
+
return url || void 0;
|
|
481
|
+
}
|
|
482
|
+
function pickFromStyle(style) {
|
|
483
|
+
if (!style) return;
|
|
484
|
+
const m = style.match(/url\((['"]?)(.*?)\1\)/i);
|
|
485
|
+
return m?.[2] || void 0;
|
|
486
|
+
}
|
|
487
|
+
function pickThumbUrl(scope, baseURL) {
|
|
488
|
+
const candidates = [
|
|
489
|
+
".views-field-field-comg-preview img",
|
|
490
|
+
".views-field-field-cat-preview img",
|
|
491
|
+
".views-field-field-category-preview img",
|
|
492
|
+
".views-field-field-man-preview-1 img",
|
|
493
|
+
".views-field-field-man-preview img",
|
|
494
|
+
".views-field-field-author-preview img",
|
|
495
|
+
".views-field-field-authors-pre img",
|
|
496
|
+
".views-field-field-gif-pre-1 img",
|
|
497
|
+
".views-field-field-gif-preview img",
|
|
498
|
+
".views-field-field-gif-pre img",
|
|
499
|
+
".views-field-field-gif img",
|
|
500
|
+
".views-field-field-preview img",
|
|
501
|
+
".views-field-field-image img",
|
|
502
|
+
".views-field-field-avatar img",
|
|
503
|
+
".field-content a > img",
|
|
504
|
+
".field-content img",
|
|
505
|
+
"a > img",
|
|
506
|
+
"img"
|
|
507
|
+
];
|
|
508
|
+
for (const sel of candidates) {
|
|
509
|
+
const img = scope.find(sel).first();
|
|
510
|
+
if (img.length) {
|
|
511
|
+
const ds = img.attr("data-src") || img.attr("data-original");
|
|
512
|
+
const ss = pickFromSrcset(img.attr("srcset") || "");
|
|
513
|
+
const src = ds || ss || img.attr("src");
|
|
514
|
+
const abs = toAbsolute(baseURL, src || "");
|
|
515
|
+
if (abs) return abs;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const srcset = pickFromSrcset(scope.find("picture source").first().attr("srcset") || "");
|
|
519
|
+
if (srcset) {
|
|
520
|
+
const abs = toAbsolute(baseURL, srcset);
|
|
521
|
+
if (abs) return abs;
|
|
522
|
+
}
|
|
523
|
+
const bg = pickFromStyle(
|
|
524
|
+
scope.attr("style") || scope.find('[style*="background-image"]').first().attr("style")
|
|
525
|
+
);
|
|
526
|
+
if (bg) {
|
|
527
|
+
const abs = toAbsolute(baseURL, bg);
|
|
528
|
+
if (abs) return abs;
|
|
529
|
+
}
|
|
530
|
+
return void 0;
|
|
531
|
+
}
|
|
532
|
+
function parseAlphabetListing(html, baseURL, page) {
|
|
533
|
+
const $ = cheerio3.load(html);
|
|
534
|
+
const items = [];
|
|
535
|
+
$("table.views-view-grid td").each((_, td) => {
|
|
536
|
+
const scope = $(td);
|
|
537
|
+
const a = scope.find(
|
|
538
|
+
".views-field-title a[href], .views-field-name a[href], strong a[href], h5 a[href], a[href]"
|
|
539
|
+
).first();
|
|
540
|
+
const href = a.attr("href") || "";
|
|
541
|
+
const url = toAbsolute(baseURL, href);
|
|
542
|
+
const title = (a.text() || scope.find(".views-field-title .field-content").text() || scope.find(".views-field-name .field-content").text() || scope.find("strong").first().text() || scope.find("h5").first().text() || "").trim();
|
|
543
|
+
const thumb = pickThumbUrl(scope, baseURL);
|
|
544
|
+
if (url && title) items.push({ title, url, thumb });
|
|
545
|
+
});
|
|
546
|
+
if (items.length === 0) {
|
|
547
|
+
$(".view .view-content .views-row").each((_, row) => {
|
|
548
|
+
const el = $(row);
|
|
549
|
+
const a = el.find(
|
|
550
|
+
".views-field-title a[href], .views-field-name a[href], strong a[href], h5 a[href], a[href]"
|
|
551
|
+
).first();
|
|
552
|
+
const href = a.attr("href") || "";
|
|
553
|
+
const url = toAbsolute(baseURL, href);
|
|
554
|
+
const title = (a.text() || el.find(".views-field-title .field-content").text() || el.find(".views-field-name .field-content").text() || el.find("strong").first().text() || el.find("h5").first().text() || "").trim();
|
|
555
|
+
const thumb = pickThumbUrl(el, baseURL);
|
|
556
|
+
if (url && title) items.push({ title, url, thumb });
|
|
294
557
|
});
|
|
295
|
-
this.dom = opts.dom;
|
|
296
558
|
}
|
|
297
|
-
|
|
298
|
-
|
|
559
|
+
const totalPages = extractTotalPages(html);
|
|
560
|
+
const hasNext = page + 1 < totalPages;
|
|
561
|
+
return { items, page, hasNext, totalPages };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// src/api/alphabet.ts
|
|
565
|
+
var ALPHA_CFG = {
|
|
566
|
+
comics: { hubPath: "/comic", alphaPrefix: "/alphabetical_order_comics" },
|
|
567
|
+
category_comic: { hubPath: "/category_comic", alphaPrefix: "/category_comic/alphabetical" },
|
|
568
|
+
characters: { hubPath: "/characters", alphaPrefix: "/alphabetical_order_characters" },
|
|
569
|
+
authors_comics: { hubPath: "/authors_comics", alphaPrefix: "/alphabetical_order_authors" },
|
|
570
|
+
pipictures: { hubPath: "/pipictures", alphaPrefix: "/alphabetical_order_pictures" },
|
|
571
|
+
porn_gifs: { hubPath: "/porn_gifs", alphaPrefix: "/alphabetical_order_gif" },
|
|
572
|
+
manga: { hubPath: "/munga", alphaPrefix: "/alphabetical_order_manga" },
|
|
573
|
+
authors_hentai: { hubPath: "/authors_hentai", alphaPrefix: "/authors_hentai/alphabetical" }
|
|
574
|
+
};
|
|
575
|
+
async function alphabetLetters(http, baseURL, section) {
|
|
576
|
+
const cfg = ALPHA_CFG[section];
|
|
577
|
+
const hub = cfg.hubPath;
|
|
578
|
+
const html = await http.getHtml(hub);
|
|
579
|
+
return parseAlphabetLetters(html, baseURL);
|
|
580
|
+
}
|
|
581
|
+
async function alphabetItems(http, baseURL, section, letter, page = 0) {
|
|
582
|
+
const cfg = ALPHA_CFG[section];
|
|
583
|
+
const letterSeg = encodeURIComponent(letter);
|
|
584
|
+
const html = await http.getHtml(`${cfg.alphaPrefix}/${letterSeg}?page=${page}`);
|
|
585
|
+
return parseAlphabetListing(html, baseURL, page);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/api/listings.ts
|
|
589
|
+
var listings_exports = {};
|
|
590
|
+
__export(listings_exports, {
|
|
591
|
+
latest: () => latest,
|
|
592
|
+
listByPath: () => listByPath
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
// src/parsers/sorting.ts
|
|
596
|
+
function parseExposedSorting(html, baseURL) {
|
|
597
|
+
const vfIdx = html.search(/<div[^>]+class=["'][^"']*view-filters[^"']*["'][^>]*>/i);
|
|
598
|
+
if (vfIdx < 0) return void 0;
|
|
599
|
+
const formStart = html.indexOf("<form", vfIdx);
|
|
600
|
+
if (formStart < 0) return void 0;
|
|
601
|
+
const formEnd = html.indexOf("</form>", formStart);
|
|
602
|
+
if (formEnd < 0) return void 0;
|
|
603
|
+
const formHtml = html.slice(formStart, formEnd + 7);
|
|
604
|
+
const actionMatch = /<form[^>]*\baction=["']([^"']+)["'][^>]*>/i.exec(formHtml);
|
|
605
|
+
if (!actionMatch) return void 0;
|
|
606
|
+
const abs = toAbsolute(baseURL, actionMatch[1] || "");
|
|
607
|
+
if (!abs) return void 0;
|
|
608
|
+
let actionPath = "/";
|
|
609
|
+
try {
|
|
610
|
+
actionPath = new URL(abs).pathname || "/";
|
|
611
|
+
} catch {
|
|
612
|
+
actionPath = "/";
|
|
299
613
|
}
|
|
300
|
-
|
|
301
|
-
|
|
614
|
+
const labels = /* @__PURE__ */ new Map();
|
|
615
|
+
const reLabel = /<label[^>]*\bfor=["']([^"']+)["'][^>]*>([\s\S]*?)<\/label>/gi;
|
|
616
|
+
let lm;
|
|
617
|
+
while (lm = reLabel.exec(formHtml)) {
|
|
618
|
+
const id = lm[1];
|
|
619
|
+
const raw = (lm[2] || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
620
|
+
if (id && raw) labels.set(id, raw);
|
|
302
621
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
622
|
+
const selects = [];
|
|
623
|
+
const reSelect = /<select\b([^>]*)>([\s\S]*?)<\/select>/gi;
|
|
624
|
+
let sm;
|
|
625
|
+
while (sm = reSelect.exec(formHtml)) {
|
|
626
|
+
const attrs = sm[1] || "";
|
|
627
|
+
const inner = sm[2] || "";
|
|
628
|
+
const name = /(?:^|\s)name=["']([^"']+)["']/i.exec(attrs)?.[1];
|
|
629
|
+
if (!name) continue;
|
|
630
|
+
const idAttr = /(?:^|\s)id=["']([^"']+)["']/i.exec(attrs)?.[1];
|
|
631
|
+
const label = idAttr ? labels.get(idAttr) : void 0;
|
|
632
|
+
const options = [];
|
|
633
|
+
const reOpt = /<option\b([^>]*)>([\s\S]*?)<\/option>/gi;
|
|
634
|
+
let om;
|
|
635
|
+
while (om = reOpt.exec(inner)) {
|
|
636
|
+
const oattrs = om[1] || "";
|
|
637
|
+
const text = (om[2] || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
638
|
+
const val = /(?:^|\s)value=["']([^"']*)["']/i.exec(oattrs)?.[1] ?? text;
|
|
639
|
+
const selected = /\bselected\b/i.test(oattrs) || /\bselected=["']selected["']/i.test(oattrs);
|
|
640
|
+
options.push({ value: val, label: text || val, selected });
|
|
641
|
+
}
|
|
642
|
+
selects.push({ name, label, options });
|
|
309
643
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
644
|
+
if (!selects.length) return void 0;
|
|
645
|
+
const appliedParams = {};
|
|
646
|
+
for (const s of selects) {
|
|
647
|
+
const selected = s.options.find((o) => o.selected);
|
|
648
|
+
if (selected && selected.value !== void 0) {
|
|
649
|
+
appliedParams[s.name] = String(selected.value);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return { actionPath, selects, appliedParams };
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// src/parsers/listing.ts
|
|
656
|
+
function pickFromSrcset2(srcset) {
|
|
657
|
+
if (!srcset) return;
|
|
658
|
+
const first = srcset.split(",")[0]?.trim();
|
|
659
|
+
if (!first) return;
|
|
660
|
+
const url = first.split(/\s+/)[0];
|
|
661
|
+
return url || void 0;
|
|
662
|
+
}
|
|
663
|
+
function pickFromStyle2(style) {
|
|
664
|
+
if (!style) return;
|
|
665
|
+
const m = style.match(/url\((['"]?)(.*?)\1\)/i);
|
|
666
|
+
return m?.[2] || void 0;
|
|
667
|
+
}
|
|
668
|
+
function pickThumb($scope, baseURL) {
|
|
669
|
+
const cands = [
|
|
670
|
+
".views-field-field-preview img",
|
|
671
|
+
".views-field-field-image img",
|
|
672
|
+
".views-field-field-avatar img",
|
|
673
|
+
".views-field-field-cat-preview img",
|
|
674
|
+
".views-field-field-category-preview img",
|
|
675
|
+
".views-field-field-comg-preview img",
|
|
676
|
+
".views-field-field-gif-preview img",
|
|
677
|
+
".views-field-field-gif-pre img",
|
|
678
|
+
".views-field-field-gif img",
|
|
679
|
+
".views-field-field-files img",
|
|
680
|
+
"img"
|
|
681
|
+
];
|
|
682
|
+
for (const sel of cands) {
|
|
683
|
+
const img = $scope.find(sel).first();
|
|
684
|
+
if (img.length) {
|
|
685
|
+
const ds = img.attr("data-src") || img.attr("data-original");
|
|
686
|
+
const ss = pickFromSrcset2(img.attr("srcset") || "");
|
|
687
|
+
const src = ds || ss || img.attr("src");
|
|
688
|
+
const abs = toAbsolute(baseURL, src || "");
|
|
689
|
+
if (abs) return abs;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const srcset = pickFromSrcset2($scope.find("picture source").first().attr("srcset") || "");
|
|
693
|
+
if (srcset) return toAbsolute(baseURL, srcset);
|
|
694
|
+
const bg = pickFromStyle2(
|
|
695
|
+
$scope.attr("style") || $scope.find('[style*="background-image"]').first().attr("style")
|
|
696
|
+
);
|
|
697
|
+
if (bg) return toAbsolute(baseURL, bg);
|
|
698
|
+
return void 0;
|
|
699
|
+
}
|
|
700
|
+
function findTitleLink($scope) {
|
|
701
|
+
const sel = $scope.find(".views-field-title a[href]").first().length ? ".views-field-title a[href]" : $scope.find(".views-field-name a[href]").first().length ? ".views-field-name a[href]" : $scope.find(".views-field-nothing-1 h3 a[href]").first().length ? ".views-field-nothing-1 h3 a[href]" : $scope.find("strong a[href]").first().length ? "strong a[href]" : $scope.find("h5 a[href]").first().length ? "h5 a[href]" : "a[href]";
|
|
702
|
+
return $scope.find(sel).first();
|
|
703
|
+
}
|
|
704
|
+
function textFrom($el) {
|
|
705
|
+
return ($el.text() || "").replace(/\s+/g, " ").trim();
|
|
706
|
+
}
|
|
707
|
+
function isPager($a) {
|
|
708
|
+
return !!$a.closest("ul.pager, .pager, nav.pagination").length;
|
|
709
|
+
}
|
|
710
|
+
function cardRoot($a) {
|
|
711
|
+
const r = $a.closest("li, .views-row, td, .node, .views-col, .view-content > div, tr").first();
|
|
712
|
+
return r.length ? r : $a.parent();
|
|
713
|
+
}
|
|
714
|
+
function parseHubListing(html, baseURL, page) {
|
|
715
|
+
const $ = cheerio3.load(html);
|
|
716
|
+
const items = [];
|
|
717
|
+
const seen = /* @__PURE__ */ new Set();
|
|
718
|
+
const views = $(".view");
|
|
719
|
+
const scopes = views.length ? views.toArray() : [$("body").get(0)];
|
|
720
|
+
for (const v of scopes) {
|
|
721
|
+
const $view = $(v);
|
|
722
|
+
const $root = $view.find(".view-content").length ? $view.find(".view-content") : $view;
|
|
723
|
+
$root.find("table.views-table tbody tr").each((_, tr) => {
|
|
724
|
+
const $tr = $(tr);
|
|
725
|
+
let a = $tr.find(".views-field-nothing-1 h3 a[href]").first();
|
|
726
|
+
if (!a.length) {
|
|
727
|
+
const cand = $tr.find("a[href]").first();
|
|
728
|
+
if (cand.length && !isPager(cand)) a = cand;
|
|
729
|
+
}
|
|
730
|
+
const href = a.attr("href") || "";
|
|
731
|
+
const url = toAbsolute(baseURL, href);
|
|
732
|
+
if (!url || seen.has(url)) return;
|
|
733
|
+
const title = textFrom($tr.find(".views-field-nothing-1 h3").first()) || textFrom(a) || a.attr("title") || "";
|
|
734
|
+
if (!title.trim()) return;
|
|
735
|
+
const thumbCell = $tr.find(".views-field-field-files").first();
|
|
736
|
+
const thumb = pickThumb(thumbCell, baseURL) || pickThumb($tr, baseURL);
|
|
737
|
+
items.push({ title: title.trim(), url, thumb });
|
|
738
|
+
seen.add(url);
|
|
739
|
+
});
|
|
740
|
+
$root.find("table.views-view-grid td").each((_, td) => {
|
|
741
|
+
const $td = $(td);
|
|
742
|
+
const a = findTitleLink($td);
|
|
743
|
+
const href = a.attr("href") || "";
|
|
744
|
+
const url = toAbsolute(baseURL, href);
|
|
745
|
+
if (!url || seen.has(url)) return;
|
|
746
|
+
const title = textFrom(a) || textFrom($td.find(".views-field-title .field-content")) || textFrom($td.find(".views-field-name .field-content")) || a.attr("title") || "";
|
|
747
|
+
const thumb = pickThumb($td, baseURL);
|
|
748
|
+
if (title) {
|
|
749
|
+
items.push({ title, url, thumb });
|
|
750
|
+
seen.add(url);
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
$root.find(".views-row, .node, li").each((_, row) => {
|
|
754
|
+
const $row = $(row);
|
|
755
|
+
const a = findTitleLink($row);
|
|
756
|
+
const href = a.attr("href") || "";
|
|
757
|
+
const url = toAbsolute(baseURL, href);
|
|
758
|
+
if (!url || seen.has(url)) return;
|
|
759
|
+
const title = textFrom(a) || textFrom($row.find(".views-field-title .field-content")) || textFrom($row.find(".views-field-name .field-content")) || a.attr("title") || "";
|
|
760
|
+
const thumb = pickThumb($row, baseURL);
|
|
761
|
+
if (title) {
|
|
762
|
+
items.push({ title, url, thumb });
|
|
763
|
+
seen.add(url);
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
$root.find("a[href] img").each((_, imgEl) => {
|
|
767
|
+
const $a = $(imgEl).closest("a[href]");
|
|
768
|
+
if (isPager($a)) return;
|
|
769
|
+
const url = toAbsolute(baseURL, $a.attr("href") || "");
|
|
770
|
+
if (!url || seen.has(url)) return;
|
|
771
|
+
const $card = cardRoot($a);
|
|
772
|
+
const title = textFrom($card.find(".views-field-title .field-content").first()) || textFrom($card.find(".views-field-name .field-content").first()) || textFrom($card.find(".views-field-nothing-1 h3").first()) || $a.attr("title") || $(imgEl).attr("alt") || "";
|
|
773
|
+
if (!title.trim()) return;
|
|
774
|
+
const thumb = pickThumb($card, baseURL) || pickThumb($a, baseURL) || toAbsolute(baseURL, $(imgEl).attr("src") || "");
|
|
775
|
+
items.push({ title: title.trim(), url, thumb });
|
|
326
776
|
seen.add(url);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const totalPages = extractTotalPages(html);
|
|
780
|
+
const hasNext = page + 1 < totalPages;
|
|
781
|
+
const alphabet = parseAlphabetInline(html, baseURL) || void 0;
|
|
782
|
+
const sorting = parseExposedSorting(html, baseURL);
|
|
783
|
+
return {
|
|
784
|
+
items,
|
|
785
|
+
page,
|
|
786
|
+
hasNext,
|
|
787
|
+
totalPages,
|
|
788
|
+
pageSize: void 0,
|
|
789
|
+
alphabet,
|
|
790
|
+
sorting
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/api/listings.ts
|
|
795
|
+
function buildUrl(baseURL, path, params) {
|
|
796
|
+
const url = new URL(path.startsWith("/") ? path : `/${path}`, baseURL);
|
|
797
|
+
if (params) {
|
|
798
|
+
for (const [k, v] of Object.entries(params)) {
|
|
799
|
+
if (v === void 0) continue;
|
|
800
|
+
if (typeof v === "boolean") url.searchParams.set(k, v ? "1" : "0");
|
|
801
|
+
else url.searchParams.set(k, String(v));
|
|
327
802
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
803
|
+
}
|
|
804
|
+
return url.pathname + (url.search ? url.search : "");
|
|
805
|
+
}
|
|
806
|
+
function normalizeCharactersPath(path) {
|
|
807
|
+
const clean = path.startsWith("/") ? path : `/${path}`;
|
|
808
|
+
if (/^\/alphabetical_order_characters\/?$/i.test(clean)) return "/characters";
|
|
809
|
+
return clean;
|
|
810
|
+
}
|
|
811
|
+
function sniffPagePrefixFromHtml(html) {
|
|
812
|
+
const m = html.match(
|
|
813
|
+
/<ul[^>]*class=["'][^"']*pager[^"']*["'][\s\S]*?\bhref=["'][^"']*?\bpage=([^"&]+)["'][\s\S]*?<\/ul>/i
|
|
814
|
+
) || html.match(/\bpage=([^"&]+)/i);
|
|
815
|
+
if (!m) return null;
|
|
816
|
+
try {
|
|
817
|
+
const decoded = decodeURIComponent(m[1]);
|
|
818
|
+
if (decoded.includes(",")) {
|
|
819
|
+
const parts = decoded.split(",").map((s) => s.trim());
|
|
820
|
+
if (parts.length > 1) return parts.slice(0, -1).join(",") + ",";
|
|
341
821
|
}
|
|
342
|
-
|
|
822
|
+
} catch {
|
|
823
|
+
}
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
function buildPageParam(htmlWithPager, page) {
|
|
827
|
+
const prefix = sniffPagePrefixFromHtml(htmlWithPager);
|
|
828
|
+
return prefix ? `${prefix}${page}` : String(page);
|
|
829
|
+
}
|
|
830
|
+
function getAppliedFromHtml(html, baseURL) {
|
|
831
|
+
const sorting = parseExposedSorting(html, baseURL);
|
|
832
|
+
return sorting?.appliedParams ?? {};
|
|
833
|
+
}
|
|
834
|
+
async function latest(http, baseURL, page = 0, params) {
|
|
835
|
+
const url0 = buildUrl(baseURL, "/new", { ...params ?? {}, page: 0 });
|
|
836
|
+
const html0 = await http.getHtml(url0);
|
|
837
|
+
if (page === 0) {
|
|
838
|
+
return parseHubListing(html0, baseURL, 0);
|
|
343
839
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
840
|
+
const applied = params ? {} : getAppliedFromHtml(html0, baseURL);
|
|
841
|
+
const pageParam = buildPageParam(html0, page);
|
|
842
|
+
const html = await http.getHtml(
|
|
843
|
+
buildUrl(baseURL, "/new", { ...applied, ...params ?? {}, page: pageParam })
|
|
844
|
+
);
|
|
845
|
+
return parseHubListing(html, baseURL, page);
|
|
846
|
+
}
|
|
847
|
+
async function listByPath(http, baseURL, path, page = 0, opts) {
|
|
848
|
+
const clean = path.startsWith("/") ? path : `/${path}`;
|
|
849
|
+
const commonParams = { ...opts ?? {} };
|
|
850
|
+
delete commonParams.letter;
|
|
851
|
+
if (opts?.letter) {
|
|
852
|
+
const entryHtml = await http.getHtml(buildUrl(baseURL, clean, commonParams));
|
|
853
|
+
const alphabet = parseAlphabetInline(entryHtml, baseURL);
|
|
854
|
+
const wanted = String(opts.letter).toUpperCase();
|
|
855
|
+
let letterUrl;
|
|
856
|
+
if (alphabet) {
|
|
857
|
+
const match = alphabet.letters.find((l) => (l.value || "").toUpperCase() === wanted) || alphabet.letters.find((l) => (l.label || "").toUpperCase() === wanted);
|
|
858
|
+
letterUrl = match?.href || `/${alphabet.section}/${encodeURIComponent(wanted)}`;
|
|
859
|
+
} else {
|
|
860
|
+
const section = guessAlphabetSectionFromPath(clean);
|
|
861
|
+
letterUrl = `/${section}/${encodeURIComponent(wanted)}`;
|
|
862
|
+
}
|
|
863
|
+
const url0 = buildUrl(baseURL, letterUrl, { ...commonParams, page: 0 });
|
|
864
|
+
const html02 = await http.getHtml(url0);
|
|
865
|
+
const res0 = parseAlphabetListing(html02, baseURL, 0);
|
|
866
|
+
if (alphabet) res0.alphabet = alphabet;
|
|
867
|
+
if (page === 0) {
|
|
868
|
+
return res0;
|
|
349
869
|
}
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
870
|
+
const applied2 = Object.keys(commonParams).length ? {} : getAppliedFromHtml(html02, baseURL);
|
|
871
|
+
const pageParam2 = buildPageParam(html02, page);
|
|
872
|
+
const html2 = await http.getHtml(
|
|
873
|
+
buildUrl(baseURL, letterUrl, { ...applied2, ...commonParams, page: pageParam2 })
|
|
874
|
+
);
|
|
875
|
+
const res = parseAlphabetListing(html2, baseURL, page);
|
|
876
|
+
if (alphabet) res.alphabet = alphabet;
|
|
877
|
+
return res;
|
|
354
878
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
879
|
+
const effective = normalizeCharactersPath(clean);
|
|
880
|
+
const html0 = await http.getHtml(buildUrl(baseURL, effective, { ...commonParams, page: 0 }));
|
|
881
|
+
const parsed0 = parseHubListing(html0, baseURL, 0);
|
|
882
|
+
if (effective !== clean && !parsed0.alphabet) {
|
|
883
|
+
try {
|
|
884
|
+
const entryHtml = await http.getHtml(buildUrl(baseURL, clean, commonParams));
|
|
885
|
+
const alpha = parseAlphabetInline(entryHtml, baseURL);
|
|
886
|
+
if (alpha) parsed0.alphabet = alpha;
|
|
887
|
+
} catch {
|
|
888
|
+
}
|
|
358
889
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const html = await this.http.getHtml(url);
|
|
362
|
-
const items = this.parseListing(html);
|
|
363
|
-
const hasNext = this.parseHasNext(html);
|
|
364
|
-
return { items, page, hasNext, totalPages: hasNext ? page + 2 : page + 1 };
|
|
890
|
+
if (page === 0) {
|
|
891
|
+
return parsed0;
|
|
365
892
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
893
|
+
const applied = Object.keys(commonParams).length ? {} : parsed0.sorting?.appliedParams ?? getAppliedFromHtml(html0, baseURL);
|
|
894
|
+
const pageParam = buildPageParam(html0, page);
|
|
895
|
+
const html = await http.getHtml(
|
|
896
|
+
buildUrl(baseURL, effective, { ...applied, ...commonParams, page: pageParam })
|
|
897
|
+
);
|
|
898
|
+
const parsed = parseHubListing(html, baseURL, page);
|
|
899
|
+
if (effective !== clean && !parsed.alphabet) {
|
|
900
|
+
try {
|
|
901
|
+
const entryHtml = await http.getHtml(buildUrl(baseURL, clean, commonParams));
|
|
902
|
+
const alpha = parseAlphabetInline(entryHtml, baseURL);
|
|
903
|
+
if (alpha) parsed.alphabet = alpha;
|
|
904
|
+
} catch {
|
|
905
|
+
}
|
|
375
906
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
907
|
+
return parsed;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// src/api/posts.ts
|
|
911
|
+
var posts_exports = {};
|
|
912
|
+
__export(posts_exports, {
|
|
913
|
+
getPost: () => getPost
|
|
914
|
+
});
|
|
915
|
+
function parsePost(html, baseURL, url) {
|
|
916
|
+
const $ = cheerio3.load(html);
|
|
917
|
+
const title = $("h1").first().text().trim() || $(".page-title, .node-title, .title").first().text().trim() || url;
|
|
918
|
+
const container = $("#content, .content, article, .node, .field-items").first();
|
|
919
|
+
const imgs = [];
|
|
920
|
+
container.find("img").each((_, img) => {
|
|
921
|
+
const el = $(img);
|
|
922
|
+
const src = el.attr("data-src") || el.attr("src");
|
|
923
|
+
const abs = toAbsolute(baseURL, src || "");
|
|
924
|
+
if (abs) imgs.push(abs);
|
|
925
|
+
});
|
|
926
|
+
const images = uniq(imgs);
|
|
927
|
+
const tags = [];
|
|
928
|
+
$('.tags a, a[rel="tag"], .field-name-field-tags a').each((_, a) => {
|
|
929
|
+
const t = $(a).text().trim();
|
|
930
|
+
if (t) tags.push(t);
|
|
931
|
+
});
|
|
932
|
+
const author = $(".author a").first().text().trim() || $(".submitted .username").first().text().trim() || null;
|
|
933
|
+
return { title, url, images, tags: uniq(tags), author };
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// src/api/posts.ts
|
|
937
|
+
async function getPost(http, baseURL, urlOrSlug) {
|
|
938
|
+
const html = await http.getHtml(urlOrSlug);
|
|
939
|
+
const absolute = (() => {
|
|
940
|
+
try {
|
|
941
|
+
return new URL(urlOrSlug).toString();
|
|
942
|
+
} catch {
|
|
943
|
+
return new URL(urlOrSlug.replace(/^\//, ""), baseURL + "/").toString();
|
|
390
944
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
945
|
+
})();
|
|
946
|
+
return parsePost(html, baseURL, absolute);
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// src/api/search.ts
|
|
950
|
+
var search_exports = {};
|
|
951
|
+
__export(search_exports, {
|
|
952
|
+
search: () => search
|
|
953
|
+
});
|
|
954
|
+
function parseSearch(html, baseURL, page) {
|
|
955
|
+
const $ = cheerio3.load(html);
|
|
956
|
+
const items = [];
|
|
957
|
+
const view = $(".view").filter((_, el) => {
|
|
958
|
+
const cls = $(el).attr("class") || "";
|
|
959
|
+
return /view-id-search/.test(cls) && /view-display-id-page/.test(cls) && $(el).find(".view-content").length > 0;
|
|
960
|
+
}).first();
|
|
961
|
+
const rows = view.find(".view-content .views-row");
|
|
962
|
+
rows.each((_, el) => {
|
|
963
|
+
const row = $(el);
|
|
964
|
+
const a = row.find(".views-field-title a[href]").first().length ? row.find(".views-field-title a[href]").first() : row.find("a[href]").first();
|
|
965
|
+
const href = a.attr("href") || "";
|
|
966
|
+
const url = toAbsolute(baseURL, href);
|
|
967
|
+
const title = (a.text() || row.find(".views-field-title .field-content").text() || "").trim();
|
|
968
|
+
const pickImg = row.find(".views-field-field-preview img").first().length ? row.find(".views-field-field-preview img").first() : row.find(".views-field-field-image img").first().length ? row.find(".views-field-field-image img").first() : row.find(".views-field-field-fl-prev img").first().length ? row.find(".views-field-field-fl-prev img").first() : row.find(".views-field-field-album-preview img").first().length ? row.find(".views-field-field-album-preview img").first() : row.find(".views-field-field-vd-preciew img").first().length ? row.find(".views-field-field-vd-preciew img").first() : row.find(".views-field-field-gif-pre img").first().length ? row.find(".views-field-field-gif-pre img").first() : row.find(".views-field-field-avatar img").first().length ? row.find(".views-field-field-avatar img").first() : row.find("img").first();
|
|
969
|
+
let thumb = pickImg.attr("data-src") || pickImg.attr("src") || void 0;
|
|
970
|
+
thumb = toAbsolute(baseURL, thumb);
|
|
971
|
+
if (url && title) items.push({ title, url, thumb });
|
|
972
|
+
});
|
|
973
|
+
const totalPages = extractTotalPages(html);
|
|
974
|
+
const hasNext = page + 1 < totalPages;
|
|
975
|
+
if (items.length === 0) {
|
|
976
|
+
return { items: [], page, hasNext: false, totalPages: 1 };
|
|
977
|
+
}
|
|
978
|
+
return { items, page, hasNext, totalPages };
|
|
979
|
+
}
|
|
980
|
+
function extractViewsContextForSearch(html) {
|
|
981
|
+
const $ = cheerio3.load(html);
|
|
982
|
+
const view = $(".view").filter((_, el) => {
|
|
983
|
+
const cls2 = $(el).attr("class") || "";
|
|
984
|
+
return /view-id-search/.test(cls2) && /view-display-id-page/.test(cls2);
|
|
985
|
+
}).first();
|
|
986
|
+
const cls = view.attr("class") || "";
|
|
987
|
+
const view_name = cls.match(/view-id-([^\s]+)/)?.[1] || "search";
|
|
988
|
+
const view_display_id = cls.match(/view-display-id-([^\s]+)/)?.[1] || "page";
|
|
989
|
+
const domFromClass = cls.match(/view-dom-id-([^\s]+)/)?.[1] || "";
|
|
990
|
+
const domFromId = (view.attr("id") || "").replace(/^view-dom-id-/, "");
|
|
991
|
+
const view_dom_id = domFromClass || domFromId || "view-dom-id-1";
|
|
992
|
+
const ajax_html_id = $('[id^="views-exposed-form"]').attr("id") || view.attr("id") || void 0;
|
|
993
|
+
return { view_name, view_display_id, view_dom_id, ajax_html_id };
|
|
994
|
+
}
|
|
995
|
+
function extractHtmlFromDrupalAjax(payload, wantDomId) {
|
|
996
|
+
if (Array.isArray(payload)) {
|
|
997
|
+
for (const cmd of payload) {
|
|
998
|
+
const c = cmd;
|
|
999
|
+
const sel = String(c?.selector || "");
|
|
1000
|
+
const data = c?.data;
|
|
1001
|
+
if ((c?.command === "insert" || c?.command === "replaceWith") && typeof data === "string" && data.trim() && (!wantDomId || sel.includes(wantDomId) || sel.includes("view-content")))
|
|
1002
|
+
return data;
|
|
397
1003
|
}
|
|
1004
|
+
const concat = payload.map((x) => typeof x?.data === "string" ? x.data : "").join("");
|
|
1005
|
+
return concat.trim() ? concat : null;
|
|
1006
|
+
}
|
|
1007
|
+
const disp = payload?.display;
|
|
1008
|
+
return typeof disp === "string" ? disp : null;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/api/search.ts
|
|
1012
|
+
async function search(http, baseURL, query, page = 0) {
|
|
1013
|
+
const q = encodeURIComponent(query);
|
|
1014
|
+
const html1 = await http.getHtml(`/search?search_api_views_fulltext=${q}&page=${page}`);
|
|
1015
|
+
const parsed1 = parseSearch(html1, baseURL, page);
|
|
1016
|
+
if (parsed1.items.length > 0) return parsed1;
|
|
1017
|
+
const firstHtml = await http.getHtml(`/search?search_api_views_fulltext=${q}`);
|
|
1018
|
+
const ctx = extractViewsContextForSearch(firstHtml);
|
|
1019
|
+
const ajaxUrl = `/views/ajax?search_api_views_fulltext=${q}&undefined=Search&_wrapper_format=drupal_ajax`;
|
|
1020
|
+
const payload = {
|
|
1021
|
+
view_name: ctx.view_name || "search",
|
|
1022
|
+
view_display_id: ctx.view_display_id || "page",
|
|
1023
|
+
view_args: "",
|
|
1024
|
+
view_path: "search",
|
|
1025
|
+
view_base_path: "search",
|
|
1026
|
+
view_dom_id: ctx.view_dom_id,
|
|
1027
|
+
pager_element: "0",
|
|
1028
|
+
page: String(page)
|
|
1029
|
+
};
|
|
1030
|
+
if (ctx.ajax_html_id) payload["ajax_html_ids[]"] = [ctx.ajax_html_id];
|
|
1031
|
+
const json = await http.postForm(ajaxUrl, payload);
|
|
1032
|
+
const html2 = extractHtmlFromDrupalAjax(json, ctx.view_dom_id) || "";
|
|
1033
|
+
return parseSearch(html2, baseURL, page);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// src/api/updates.ts
|
|
1037
|
+
var updates_exports = {};
|
|
1038
|
+
__export(updates_exports, {
|
|
1039
|
+
updates: () => updates,
|
|
1040
|
+
updatesShortcuts: () => updatesShortcuts
|
|
1041
|
+
});
|
|
1042
|
+
function parseViewDisplay(viewName, html, baseURL) {
|
|
1043
|
+
const $ = cheerio3.load(html);
|
|
1044
|
+
const items = [];
|
|
1045
|
+
const pickThumb2 = (scope) => {
|
|
1046
|
+
const img = scope.find(".views-field-field-preview img").first().length ? scope.find(".views-field-field-preview img").first() : scope.find(".views-field-field-image img").first().length ? scope.find(".views-field-field-image img").first() : scope.find(".views-field-field-avatar img").first().length ? scope.find(".views-field-field-avatar img").first() : scope.find("img").first();
|
|
1047
|
+
let thumb = img.attr("data-src") || img.attr("src") || void 0;
|
|
1048
|
+
return toAbsolute(baseURL, thumb);
|
|
1049
|
+
};
|
|
1050
|
+
const liList = $("ul.jcarousel li");
|
|
1051
|
+
liList.each((_, li) => {
|
|
1052
|
+
const scope = $(li);
|
|
1053
|
+
const a = scope.find(".views-field-title a[href]").first().length ? scope.find(".views-field-title a[href]").first() : scope.find(".views-field-name a[href]").first();
|
|
1054
|
+
const href = a.attr("href") || "";
|
|
1055
|
+
const url = toAbsolute(baseURL, href);
|
|
1056
|
+
const title = (a.text() || scope.find(".views-field-title .field-content").text() || scope.find(".views-field-name .field-content").text() || "").trim();
|
|
1057
|
+
const thumb = pickThumb2(scope);
|
|
1058
|
+
if (url && title) items.push({ title, url, thumb });
|
|
1059
|
+
});
|
|
1060
|
+
return items;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/api/updates.ts
|
|
1064
|
+
var VIEW_PRESETS = {
|
|
1065
|
+
random_top_comics: { view_display_id: "block", jcarousel_dom_id: 7 },
|
|
1066
|
+
top_random_characters: { view_display_id: "block", jcarousel_dom_id: 8 }
|
|
1067
|
+
};
|
|
1068
|
+
function uniq2(arr) {
|
|
1069
|
+
return Array.from(new Set(arr));
|
|
1070
|
+
}
|
|
1071
|
+
async function updates(http, baseURL, params = {}) {
|
|
1072
|
+
const viewName = params.view_name ?? "new_mini";
|
|
1073
|
+
const preset = VIEW_PRESETS[viewName] || {};
|
|
1074
|
+
const first = Number(params.first ?? 0);
|
|
1075
|
+
const last = Number(params.last ?? 8);
|
|
1076
|
+
const basePayload = {
|
|
1077
|
+
js: "1",
|
|
1078
|
+
first: String(first),
|
|
1079
|
+
last: String(last),
|
|
1080
|
+
view_args: params.view_args ?? "",
|
|
1081
|
+
view_path: params.view_path ?? "node",
|
|
1082
|
+
view_base_path: params.view_base_path ?? "",
|
|
1083
|
+
view_name: viewName
|
|
1084
|
+
};
|
|
1085
|
+
const displayCandidates = uniq2([
|
|
1086
|
+
params.view_display_id ?? preset.view_display_id ?? "block_1",
|
|
1087
|
+
"block",
|
|
1088
|
+
"block_2",
|
|
1089
|
+
"block_3",
|
|
1090
|
+
"page",
|
|
1091
|
+
"default"
|
|
1092
|
+
]).filter(Boolean);
|
|
1093
|
+
const origDom = Number(params.jcarousel_dom_id ?? preset.jcarousel_dom_id ?? 1);
|
|
1094
|
+
const domCandidates = uniq2([
|
|
1095
|
+
origDom,
|
|
1096
|
+
origDom - 1,
|
|
1097
|
+
origDom + 1,
|
|
1098
|
+
...Array.from({ length: 10 }, (_, i) => i + 1)
|
|
1099
|
+
]).filter((n) => Number.isFinite(n) && n > 0);
|
|
1100
|
+
let displayHtml = "";
|
|
1101
|
+
for (const view_display_id of displayCandidates) {
|
|
1102
|
+
for (const jcarousel_dom_id of domCandidates) {
|
|
1103
|
+
try {
|
|
1104
|
+
const qs = new URLSearchParams({
|
|
1105
|
+
...basePayload,
|
|
1106
|
+
view_display_id: String(view_display_id),
|
|
1107
|
+
jcarousel_dom_id: String(jcarousel_dom_id)
|
|
1108
|
+
}).toString();
|
|
1109
|
+
const data = await http.getJson(`/jcarousel/ajax/views?${qs}`);
|
|
1110
|
+
const html = data?.display?.trim() ?? "";
|
|
1111
|
+
if (html) {
|
|
1112
|
+
displayHtml = html;
|
|
1113
|
+
displayCandidates.length = 0;
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
} catch {
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (!displayHtml) {
|
|
1121
|
+
return { items: [], first, last, html: "", viewName };
|
|
1122
|
+
}
|
|
1123
|
+
const items = parseViewDisplay(viewName, displayHtml, baseURL);
|
|
1124
|
+
return { items, first, last, html: displayHtml, viewName };
|
|
1125
|
+
}
|
|
1126
|
+
var updatesShortcuts = {
|
|
1127
|
+
newMini: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "new_mini" }),
|
|
1128
|
+
userUploadFront: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "user_upload_front" }),
|
|
1129
|
+
updatedManga: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "updated_manga" }),
|
|
1130
|
+
updatedMangaPromoted: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "updated_manga_promoted" }),
|
|
1131
|
+
updatedGames: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "updated_games" }),
|
|
1132
|
+
randomTopComics: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "random_top_comics" }),
|
|
1133
|
+
topRandomCharacters: (http, baseURL, p) => updates(http, baseURL, { ...p ?? {}, view_name: "top_random_characters" })
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
// src/parsers/viewer.ts
|
|
1137
|
+
var viewer_exports = {};
|
|
1138
|
+
__export(viewer_exports, {
|
|
1139
|
+
buildJuiceboxXmlUrl: () => buildJuiceboxXmlUrl,
|
|
1140
|
+
default: () => viewer_default,
|
|
1141
|
+
parseInlineJuiceboxFromHtml: () => parseInlineJuiceboxFromHtml,
|
|
1142
|
+
parseJuiceboxXml: () => parseJuiceboxXml,
|
|
1143
|
+
parseViewer: () => parseViewer,
|
|
1144
|
+
parseViewerMeta: () => parseViewerMeta
|
|
1145
|
+
});
|
|
1146
|
+
function decodeHtml(s) {
|
|
1147
|
+
return s.replace(/ /g, " ").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
1148
|
+
}
|
|
1149
|
+
function textBetween(html, openRe, close) {
|
|
1150
|
+
const m = openRe.exec(html);
|
|
1151
|
+
if (!m) return null;
|
|
1152
|
+
const i = m.index + m[0].length;
|
|
1153
|
+
const j = html.indexOf(close, i);
|
|
1154
|
+
if (j < 0) return null;
|
|
1155
|
+
return html.slice(i, j);
|
|
1156
|
+
}
|
|
1157
|
+
function stripTags(s) {
|
|
1158
|
+
return s.replace(/<[^>]*>/g, "");
|
|
1159
|
+
}
|
|
1160
|
+
function collectLinks(blockHtml, baseURL) {
|
|
1161
|
+
const out = [];
|
|
1162
|
+
const re = /<a\s+[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
1163
|
+
let m;
|
|
1164
|
+
while (m = re.exec(blockHtml)) {
|
|
1165
|
+
const url = absUrl(baseURL, m[1]) ?? "";
|
|
1166
|
+
const title = normSpace(decodeHtml(stripTags(m[2])));
|
|
1167
|
+
if (url && title) out.push({ url, title });
|
|
1168
|
+
}
|
|
1169
|
+
return out;
|
|
1170
|
+
}
|
|
1171
|
+
function findFieldNodeAndSys(html) {
|
|
1172
|
+
const re = /id="field--node--(\d+)--([a-z0-9_-]+)--full"/i;
|
|
1173
|
+
const m = re.exec(html);
|
|
1174
|
+
if (m) {
|
|
1175
|
+
const nodeId = parseInt(m[1], 10);
|
|
1176
|
+
const fieldSys = m[2].replace(/-/g, "_");
|
|
1177
|
+
if (Number.isFinite(nodeId)) return { nodeId, fieldSys };
|
|
1178
|
+
}
|
|
1179
|
+
const re2 = /\/juicebox\/xml\/field\/node\/(\d+)\/([a-z0-9_]+)\/full/gi;
|
|
1180
|
+
const m2 = re2.exec(html);
|
|
1181
|
+
if (m2) {
|
|
1182
|
+
const nodeId = parseInt(m2[1], 10);
|
|
1183
|
+
const fieldSys = m2[2];
|
|
1184
|
+
if (Number.isFinite(nodeId)) return { nodeId, fieldSys };
|
|
1185
|
+
}
|
|
1186
|
+
return null;
|
|
1187
|
+
}
|
|
1188
|
+
function buildJuiceboxXmlUrl(baseURL, nodeId, fieldSys) {
|
|
1189
|
+
const root = baseURL.replace(/\/+$/, "");
|
|
1190
|
+
return `${root}/juicebox/xml/field/node/${nodeId}/${fieldSys}/full`;
|
|
1191
|
+
}
|
|
1192
|
+
function parseJuiceboxXml(xml) {
|
|
1193
|
+
const images = [];
|
|
1194
|
+
const reImg = /<image\b([^>]+)>/gi;
|
|
1195
|
+
let m;
|
|
1196
|
+
while (m = reImg.exec(xml)) {
|
|
1197
|
+
const attrs = m[1];
|
|
1198
|
+
const map = {};
|
|
1199
|
+
let am;
|
|
1200
|
+
const reAttr = /([a-zA-Z0-9_-]+)\s*=\s*"([^"]*)"/g;
|
|
1201
|
+
while (am = reAttr.exec(attrs)) map[am[1]] = am[2];
|
|
1202
|
+
const original = map["linkURL"] || map["imageURL"] || map["largeImageURL"] || map["smallImageURL"] || "";
|
|
1203
|
+
if (!original) continue;
|
|
1204
|
+
images.push({
|
|
1205
|
+
original,
|
|
1206
|
+
large: map["largeImageURL"],
|
|
1207
|
+
medium: map["imageURL"] || map["smallImageURL"],
|
|
1208
|
+
small: map["smallImageURL"],
|
|
1209
|
+
thumb: map["thumbURL"]
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
return images;
|
|
1213
|
+
}
|
|
1214
|
+
function parseInlineJuiceboxFromHtml(html) {
|
|
1215
|
+
const out = [];
|
|
1216
|
+
const reMed = /<img[^>]+src="([^"]+\/styles\/juicebox_(?:medium|small|large)\/[^"]+)"[^>]*>/gi;
|
|
1217
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1218
|
+
let m;
|
|
1219
|
+
while (m = reMed.exec(html)) {
|
|
1220
|
+
const url = m[1];
|
|
1221
|
+
if (seen.has(url)) continue;
|
|
1222
|
+
seen.add(url);
|
|
1223
|
+
out.push({ original: url, medium: url });
|
|
1224
|
+
}
|
|
1225
|
+
return out;
|
|
1226
|
+
}
|
|
1227
|
+
function parseBreadcrumbs(html, baseURL) {
|
|
1228
|
+
const block = textBetween(html, /<div[^>]+class="breadcrumb"[^>]*>/i, "</div>");
|
|
1229
|
+
return block ? collectLinks(block, baseURL) : [];
|
|
1230
|
+
}
|
|
1231
|
+
function findLabeledFieldBlock(html, labelStartsWith) {
|
|
1232
|
+
const esc = labelStartsWith.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1233
|
+
const re = new RegExp(
|
|
1234
|
+
`<(?:h3|div)[^>]*class="[^"]*field-label[^"]*"[^>]*>\\s*${esc}\\s*:?\\s*<\\/[^>]+>`,
|
|
1235
|
+
"i"
|
|
1236
|
+
);
|
|
1237
|
+
const idx = html.search(re);
|
|
1238
|
+
if (idx < 0) return null;
|
|
1239
|
+
const open = html.lastIndexOf("<div", idx);
|
|
1240
|
+
let depth = 0;
|
|
1241
|
+
for (let i = open; i < html.length; i++) {
|
|
1242
|
+
if (html.startsWith("<div", i)) depth++;
|
|
1243
|
+
if (html.startsWith("</div>", i)) {
|
|
1244
|
+
depth--;
|
|
1245
|
+
if (depth === 0) {
|
|
1246
|
+
return html.slice(open, i + 6);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
function parseLabeledField(html, labelStartsWith) {
|
|
1253
|
+
return findLabeledFieldBlock(html, labelStartsWith);
|
|
1254
|
+
}
|
|
1255
|
+
function parsePlainValuesFromLabeledField(html, label) {
|
|
1256
|
+
const block = findLabeledFieldBlock(html, label);
|
|
1257
|
+
if (!block) return [];
|
|
1258
|
+
const text = normSpace(decodeHtml(stripTags(block))).replace(new RegExp(`^${label}\\s*:?\\s*`, "i"), "").trim();
|
|
1259
|
+
if (!text) return [];
|
|
1260
|
+
return text.split(/\s*[,;]\s*/).filter(Boolean);
|
|
1261
|
+
}
|
|
1262
|
+
function parseTitle(html) {
|
|
1263
|
+
const h1 = textBetween(html, /<h1[^>]*id="page-title"[^>]*>/i, "</h1>");
|
|
1264
|
+
if (h1) return normSpace(decodeHtml(stripTags(h1)));
|
|
1265
|
+
const m = /<meta[^>]+property="og:title"[^>]+content="([^"]+)"/i.exec(html);
|
|
1266
|
+
if (m) return normSpace(decodeHtml(m[1]));
|
|
1267
|
+
return "";
|
|
1268
|
+
}
|
|
1269
|
+
function parseVotesAndRating(html) {
|
|
1270
|
+
const block = /<div[^>]*class="[^"]*\bfivestar-summary\b[^"]*"[^>]*>([\s\S]*?)<\/div>/i.exec(html)?.[1] || /<div[^>]*class="[^"]*\bfivestar-average[^"]*"[^>]*>([\s\S]*?)<\/div>/i.exec(html)?.[1] || "";
|
|
1271
|
+
if (block) {
|
|
1272
|
+
const mAvg = /class="average-rating"[^>]*>[\s\S]*?Average[^:]*:\s*(?:<span[^>]*>)?([\d.,]+)(?:<\/span>)?/i.exec(
|
|
1273
|
+
block
|
|
1274
|
+
);
|
|
1275
|
+
const mVotes = /class="total-votes"[^>]*>\s*\(\s*(?:<span[^>]*>)?(\d+)(?:<\/span>)?\s+votes?\s*\)/i.exec(
|
|
1276
|
+
block
|
|
1277
|
+
);
|
|
1278
|
+
const rating = mAvg ? parseNumberLike(mAvg[1]) : void 0;
|
|
1279
|
+
const votes = mVotes ? parseIntLike(mVotes[1]) : void 0;
|
|
1280
|
+
if (rating != null || votes != null) return { rating, votes };
|
|
1281
|
+
}
|
|
1282
|
+
const m1 = /Average\s*:\s*(?:<span[^>]*>)?([\d.,]+)(?:<\/span>)?[\s\S]*?\(\s*(?:<span[^>]*>)?(\d+)(?:<\/span>)?\s*votes?\s*\)/i.exec(
|
|
1283
|
+
html
|
|
1284
|
+
);
|
|
1285
|
+
if (m1) {
|
|
1286
|
+
return {
|
|
1287
|
+
rating: parseNumberLike(m1[1]),
|
|
1288
|
+
votes: parseIntLike(m1[2])
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
const m2 = /Average[^<>\d]*([\d.,]+)/i.exec(html);
|
|
1292
|
+
const m3 = /\((\d+)\s+votes?\)/i.exec(html);
|
|
1293
|
+
if (m2 || m3) {
|
|
1294
|
+
const rating = m2 ? parseNumberLike(m2[1]) : void 0;
|
|
1295
|
+
const votes = m3 ? parseIntLike(m3[1]) : void 0;
|
|
1296
|
+
return { rating, votes };
|
|
1297
|
+
}
|
|
1298
|
+
return {};
|
|
1299
|
+
}
|
|
1300
|
+
function parseViews(html) {
|
|
1301
|
+
const patterns = [
|
|
1302
|
+
/<li[^>]*class="statistics_counter[^"]*"[^>]*>\s*<span>\s*([\d\s.,]+)\s+views\s*<\/span>/i,
|
|
1303
|
+
/>\s*([\d\s.,]+)\s+views\s*<\/(?:span|div|li|h\d)>/i,
|
|
1304
|
+
/>\s*Views\s*[:\-]?\s*<\/?(?:span|strong|b)?[^>]*>\s*([\d\s.,]+)\s*</i,
|
|
1305
|
+
/\bViews\s*[:\-]?\s*([\d\s.,]+)/i
|
|
1306
|
+
];
|
|
1307
|
+
for (const rx of patterns) {
|
|
1308
|
+
const m = rx.exec(html);
|
|
1309
|
+
if (m && m[1]) return parseIntLike(m[1]);
|
|
1310
|
+
}
|
|
1311
|
+
return void 0;
|
|
1312
|
+
}
|
|
1313
|
+
function parseLinksFromLabeledField(html, baseURL, label) {
|
|
1314
|
+
const block = parseLabeledField(html, label);
|
|
1315
|
+
return block ? collectLinks(block, baseURL) : [];
|
|
1316
|
+
}
|
|
1317
|
+
function parseRelated(html, baseURL) {
|
|
1318
|
+
const pieces = [];
|
|
1319
|
+
const re = /<div[^>]+class="view[^"]*down[^"]*random[^"]*hentai[^"]*manga[^"]*"[^>]*>([\s\S]*?)<\/div>\s*<\/div>/gi;
|
|
1320
|
+
let m;
|
|
1321
|
+
while (m = re.exec(html)) pieces.push(m[1]);
|
|
1322
|
+
return uniq(pieces.flatMap((p) => collectLinks(p, baseURL)));
|
|
1323
|
+
}
|
|
1324
|
+
function parseUploader(html, baseURL) {
|
|
1325
|
+
const m = /<footer[^>]*class="[^"]*\bsubmitted\b[^"]*"[^>]*>([\s\S]*?)<\/footer>/i.exec(html);
|
|
1326
|
+
if (!m) return void 0;
|
|
1327
|
+
const block = m[1];
|
|
1328
|
+
const a = /Uploaded\s+by\s*<a[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>\s*on\s*([^<]+)/i.exec(
|
|
1329
|
+
block
|
|
1330
|
+
);
|
|
1331
|
+
const img = /<div[^>]*class="user-picture"[^>]*>[\s\S]*?<img[^>]*src="([^"]+)"/i.exec(block);
|
|
1332
|
+
const out = {};
|
|
1333
|
+
if (a) {
|
|
1334
|
+
out.url = absUrl(baseURL, a[1]) ?? "";
|
|
1335
|
+
out.name = normSpace(decodeHtml(stripTags(a[2])));
|
|
1336
|
+
out.dateText = normSpace(decodeHtml(a[3]));
|
|
1337
|
+
}
|
|
1338
|
+
if (img) out.avatar = absUrl(baseURL, img[1]) ?? "";
|
|
1339
|
+
return out;
|
|
1340
|
+
}
|
|
1341
|
+
function parseViewerMeta(html, baseURL, absoluteUrl) {
|
|
1342
|
+
const title = parseTitle(html);
|
|
1343
|
+
const breadcrumbs = parseBreadcrumbs(html, baseURL);
|
|
1344
|
+
let authors = parseLinksFromLabeledField(html, baseURL, "Author");
|
|
1345
|
+
if (authors.length === 0) {
|
|
1346
|
+
const altLinks = parseLinksFromLabeledField(html, baseURL, "Artist's name");
|
|
1347
|
+
if (altLinks.length) authors = altLinks;
|
|
1348
|
+
if (authors.length === 0) {
|
|
1349
|
+
const altPlain = parsePlainValuesFromLabeledField(html, "Artist's name");
|
|
1350
|
+
if (altPlain.length) {
|
|
1351
|
+
authors = altPlain.map((t) => ({ title: t, url: "" }));
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
let sections = parseLinksFromLabeledField(html, baseURL, "Section");
|
|
1356
|
+
if (sections.length === 0) {
|
|
1357
|
+
const sPlain = parsePlainValuesFromLabeledField(html, "Section");
|
|
1358
|
+
if (sPlain.length) sections = sPlain.map((t) => ({ title: t, url: "" }));
|
|
1359
|
+
}
|
|
1360
|
+
let tags = parseLinksFromLabeledField(html, baseURL, "Tags");
|
|
1361
|
+
if (tags.length === 0) {
|
|
1362
|
+
const block = /<div[^>]*class="[^"]*field-name-field-category[^"]*"[^>]*>([\s\S]*?)<\/div>/i.exec(html);
|
|
1363
|
+
if (block) tags = collectLinks(block[1], baseURL);
|
|
1364
|
+
}
|
|
1365
|
+
const characters = parseLinksFromLabeledField(html, baseURL, "Characters");
|
|
1366
|
+
const userTags = parseLinksFromLabeledField(html, baseURL, "User tags");
|
|
1367
|
+
const { rating, votes } = parseVotesAndRating(html);
|
|
1368
|
+
const views = parseViews(html);
|
|
1369
|
+
const kind = guessKindFromPath(absoluteUrl);
|
|
1370
|
+
const field = findFieldNodeAndSys(html);
|
|
1371
|
+
const uploader = parseUploader(html, baseURL);
|
|
1372
|
+
const meta = {
|
|
1373
|
+
nodeId: field?.nodeId ?? null,
|
|
1374
|
+
fieldSys: field?.fieldSys ?? null,
|
|
1375
|
+
title,
|
|
1376
|
+
kind,
|
|
1377
|
+
breadcrumbs,
|
|
1378
|
+
authors,
|
|
1379
|
+
sections,
|
|
1380
|
+
tags,
|
|
1381
|
+
characters,
|
|
1382
|
+
userTags,
|
|
1383
|
+
rating,
|
|
1384
|
+
votes,
|
|
1385
|
+
views,
|
|
1386
|
+
related: parseRelated(html, baseURL)
|
|
1387
|
+
};
|
|
1388
|
+
if (uploader) {
|
|
1389
|
+
meta.uploader = uploader;
|
|
1390
|
+
}
|
|
1391
|
+
return { meta, nodeId: meta.nodeId, fieldSys: meta.fieldSys };
|
|
1392
|
+
}
|
|
1393
|
+
function findCanonicalUrl(html, baseURL) {
|
|
1394
|
+
const m1 = /<link[^>]+rel=["']canonical["'][^>]+href=["']([^"']+)["']/i.exec(html);
|
|
1395
|
+
if (m1?.[1]) return absUrl(baseURL, m1[1]) ?? baseURL.replace(/\/+$/, "");
|
|
1396
|
+
const m2 = /<meta[^>]+property=["']og:url["'][^>]+content=["']([^"']+)["']/i.exec(html);
|
|
1397
|
+
if (m2?.[1]) return absUrl(baseURL, m2[1]) ?? baseURL.replace(/\/+$/, "");
|
|
1398
|
+
return baseURL.replace(/\/+$/, "");
|
|
1399
|
+
}
|
|
1400
|
+
var EXCLUDE_URL_PATTERNS = [
|
|
1401
|
+
/\/styles\/avatars\//i,
|
|
1402
|
+
/\/user_avatars\//i,
|
|
1403
|
+
/\/default_images\//i,
|
|
1404
|
+
/\/styles\/taxonomy_(?:comics|manga)\//i,
|
|
1405
|
+
/\/com_preview\//i,
|
|
1406
|
+
/\/promo\//i
|
|
1407
|
+
];
|
|
1408
|
+
function isExcludedUrl(u) {
|
|
1409
|
+
const s = String(u);
|
|
1410
|
+
return EXCLUDE_URL_PATTERNS.some((re) => re.test(s));
|
|
1411
|
+
}
|
|
1412
|
+
function stripExcludedBlocks(html) {
|
|
1413
|
+
const patterns = [
|
|
1414
|
+
/<div[^>]+id="comments"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1415
|
+
/<section[^>]+id="comments"[^>]*>[\s\S]*?<\/section>/gi,
|
|
1416
|
+
/<div[^>]+class="[^"]*\bcomments?\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1417
|
+
/<div[^>]+class="[^"]*\bcomment\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1418
|
+
/<ul[^>]+class="[^"]*\bcomment\b[^"]*"[^>]*>[\s\S]*?<\/ul>/gi,
|
|
1419
|
+
/<div[^>]+class="[^"]*\brelated\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1420
|
+
/<div[^>]+class="[^"]*\bmore\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1421
|
+
/<div[^>]+class="[^"]*\bmore-comics\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1422
|
+
/<div[^>]+class="[^"]*\bpane-related\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1423
|
+
/<aside[\s\S]*?<\/aside>/gi,
|
|
1424
|
+
/<div[^>]+class="[^"]*\bsidebar\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1425
|
+
/<div[^>]+class="[^"]*\bnode-footer\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1426
|
+
/<div[^>]+class="[^"]*\bpane-views\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi,
|
|
1427
|
+
/<div[^>]+class="[^"]*\bpane-taxonomy\b[^"]*"[^>]*>[\s\S]*?<\/div>/gi
|
|
1428
|
+
];
|
|
1429
|
+
let cleaned = html;
|
|
1430
|
+
for (const re of patterns) cleaned = cleaned.replace(re, "");
|
|
1431
|
+
return cleaned;
|
|
1432
|
+
}
|
|
1433
|
+
function collectImgSrcs(html) {
|
|
1434
|
+
const out = [];
|
|
1435
|
+
const re = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
|
1436
|
+
let m;
|
|
1437
|
+
while (m = re.exec(html)) out.push(m[1]);
|
|
1438
|
+
return out;
|
|
1439
|
+
}
|
|
1440
|
+
function collectContentImages(html) {
|
|
1441
|
+
const cleaned = stripExcludedBlocks(html);
|
|
1442
|
+
return collectImgSrcs(cleaned).filter((u) => !!u && !isExcludedUrl(u));
|
|
1443
|
+
}
|
|
1444
|
+
function parseViewer(html, baseURL) {
|
|
1445
|
+
const absoluteUrl = findCanonicalUrl(html, baseURL);
|
|
1446
|
+
const { meta } = parseViewerMeta(html, baseURL, absoluteUrl);
|
|
1447
|
+
const inline = parseInlineJuiceboxFromHtml(html).map((im) => {
|
|
1448
|
+
const original = toAbsolute(baseURL, im.original || "") || "";
|
|
398
1449
|
return {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1450
|
+
original,
|
|
1451
|
+
large: im.large ? toAbsolute(baseURL, im.large) || void 0 : void 0,
|
|
1452
|
+
medium: im.medium ? toAbsolute(baseURL, im.medium) || void 0 : void 0,
|
|
1453
|
+
small: im.small ? toAbsolute(baseURL, im.small) || void 0 : void 0,
|
|
1454
|
+
thumb: im.thumb ? toAbsolute(baseURL, im.thumb) || void 0 : void 0
|
|
404
1455
|
};
|
|
1456
|
+
}).filter((im) => !!im.original);
|
|
1457
|
+
let fallback = [];
|
|
1458
|
+
if (inline.length === 0) {
|
|
1459
|
+
const srcs = collectContentImages(html).map((u) => toAbsolute(baseURL, u) || "").filter((u) => !!u);
|
|
1460
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1461
|
+
fallback = srcs.filter((u) => {
|
|
1462
|
+
if (!u || seen.has(u)) return false;
|
|
1463
|
+
seen.add(u);
|
|
1464
|
+
return true;
|
|
1465
|
+
}).map((u) => ({ original: u }));
|
|
405
1466
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
1467
|
+
const all = [...inline, ...fallback];
|
|
1468
|
+
const byOriginal = /* @__PURE__ */ new Map();
|
|
1469
|
+
for (const im of all) {
|
|
1470
|
+
const key = im.original || "";
|
|
1471
|
+
if (key && !byOriginal.has(key)) byOriginal.set(key, im);
|
|
1472
|
+
}
|
|
1473
|
+
return { meta, images: Array.from(byOriginal.values()) };
|
|
1474
|
+
}
|
|
1475
|
+
var viewer_default = parseViewer;
|
|
1476
|
+
|
|
1477
|
+
// src/parsers/video.ts
|
|
1478
|
+
var ABS_URL = /^https?:\/\//i;
|
|
1479
|
+
function absolutize(u, base) {
|
|
1480
|
+
if (!u) return "";
|
|
1481
|
+
if (ABS_URL.test(u)) return u;
|
|
1482
|
+
if (u.startsWith("//")) return "https:" + u;
|
|
1483
|
+
if (u.startsWith("/")) return base.replace(/\/+$/, "") + u;
|
|
1484
|
+
return u;
|
|
1485
|
+
}
|
|
1486
|
+
function parseVideoFromHtml(html, baseURL) {
|
|
1487
|
+
if (!html || !/node-video|class=["']video-js|<video/i.test(html)) return null;
|
|
1488
|
+
const posterMatch = html.match(/<video[^>]*\sposter=["']([^"']+)["']/i) || html.match(/class=["']video-js[^"']*["'][^>]*\sposter=["']([^"']+)["']/i);
|
|
1489
|
+
const poster = posterMatch ? absolutize(posterMatch[1], baseURL) : void 0;
|
|
1490
|
+
const sources = [];
|
|
1491
|
+
const mainVideo = html.match(/<video[^>]*\ssrc=["']([^"']+)["'][^>]*>/i);
|
|
1492
|
+
if (mainVideo) sources.push({ url: absolutize(mainVideo[1], baseURL) });
|
|
1493
|
+
const re = /<source[^>]*\ssrc=["']([^"']+)["'][^>]*?(?:\stype=["']([^"']+)["'])?[^>]*>/gi;
|
|
1494
|
+
for (let m; m = re.exec(html); ) {
|
|
1495
|
+
sources.push({ url: absolutize(m[1], baseURL), type: m[2] });
|
|
1496
|
+
}
|
|
1497
|
+
if (!sources.length) return null;
|
|
1498
|
+
return { poster, sources };
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
// src/api/viewer.ts
|
|
1502
|
+
var ABS_URL2 = /^https?:\/\//i;
|
|
1503
|
+
function absolutize2(u, base) {
|
|
1504
|
+
if (!u) return "";
|
|
1505
|
+
if (ABS_URL2.test(u)) return u;
|
|
1506
|
+
if (u.startsWith("//")) return "https:" + u;
|
|
1507
|
+
if (u.startsWith("/")) return base.replace(/\/+$/, "") + u;
|
|
1508
|
+
return base.replace(/\/+$/, "") + "/" + u.replace(/^\/+/, "");
|
|
1509
|
+
}
|
|
1510
|
+
function buildViewerUrl(base, urlOrSlug) {
|
|
1511
|
+
if (ABS_URL2.test(urlOrSlug)) return urlOrSlug;
|
|
1512
|
+
if (urlOrSlug.startsWith("/")) return base.replace(/\/+$/, "") + urlOrSlug;
|
|
1513
|
+
return base.replace(/\/+$/, "") + "/" + urlOrSlug.replace(/^\/+/, "");
|
|
1514
|
+
}
|
|
1515
|
+
async function fetchHtml(http, url) {
|
|
1516
|
+
const anyHttp = http;
|
|
1517
|
+
if (typeof anyHttp.getText === "function") return anyHttp.getText(url);
|
|
1518
|
+
if (typeof anyHttp.get === "function") return anyHttp.get(url);
|
|
1519
|
+
if (typeof anyHttp.text === "function") return anyHttp.text(url);
|
|
1520
|
+
if (typeof anyHttp.fetch === "function") {
|
|
1521
|
+
const r = await anyHttp.fetch(url);
|
|
1522
|
+
if (typeof r === "string") return r;
|
|
1523
|
+
if (r && typeof r.text === "function") return await r.text();
|
|
1524
|
+
}
|
|
1525
|
+
if (typeof fetch === "function") {
|
|
1526
|
+
const r = await fetch(url);
|
|
1527
|
+
return await r.text();
|
|
1528
|
+
}
|
|
1529
|
+
throw new Error("HttpClient: no getText/get/text/fetch available");
|
|
1530
|
+
}
|
|
1531
|
+
function proxyImgMaybe(u, opts) {
|
|
1532
|
+
if (!u) return "";
|
|
1533
|
+
return opts?.proxyImage ? opts.proxyImage(u) : u;
|
|
1534
|
+
}
|
|
1535
|
+
function proxyVidMaybe(u, opts) {
|
|
1536
|
+
if (!u) return "";
|
|
1537
|
+
const proxyVideo = opts?.proxyVideo;
|
|
1538
|
+
return proxyVideo ? proxyVideo(u) : proxyImgMaybe(u, opts);
|
|
1539
|
+
}
|
|
1540
|
+
function tryParseRichMeta(html, baseURL, absoluteUrl) {
|
|
1541
|
+
const anyParsers = viewer_exports;
|
|
1542
|
+
if (typeof anyParsers.parseViewerMeta === "function") {
|
|
1543
|
+
try {
|
|
1544
|
+
const { meta } = anyParsers.parseViewerMeta(html, baseURL, absoluteUrl);
|
|
1545
|
+
if (!meta.title) {
|
|
1546
|
+
const t = extractMeta(html, baseURL).title;
|
|
1547
|
+
if (t) meta.title = t;
|
|
1548
|
+
}
|
|
1549
|
+
return meta;
|
|
1550
|
+
} catch {
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
return extractMeta(html, baseURL);
|
|
1554
|
+
}
|
|
1555
|
+
function parseImagesWithBackoff(html, baseURL) {
|
|
1556
|
+
const anyParsers = viewer_exports;
|
|
1557
|
+
const candidate = anyParsers.parseViewer ?? anyParsers.default;
|
|
1558
|
+
if (typeof candidate === "function") {
|
|
1559
|
+
return candidate(html, baseURL);
|
|
1560
|
+
}
|
|
1561
|
+
const images = [];
|
|
1562
|
+
const re = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
|
|
1563
|
+
let m;
|
|
1564
|
+
while (m = re.exec(html)) {
|
|
1565
|
+
const original = absolutize2(m[1], baseURL);
|
|
1566
|
+
if (!original) continue;
|
|
1567
|
+
images.push({ original, medium: original });
|
|
1568
|
+
}
|
|
1569
|
+
const meta = extractMeta(html, baseURL);
|
|
1570
|
+
return { meta, images };
|
|
1571
|
+
}
|
|
1572
|
+
function hasViewerClues(html) {
|
|
1573
|
+
const hasJuicebox = /juicebox/i.test(html) || /\/juicebox\/xml\/field\/node\/\d+\/[a-z0-9_]+\/full/i.test(html);
|
|
1574
|
+
const hasFieldNode = /id=["']field--node--\d+--[a-z0-9_-]+--full["']/i.test(html);
|
|
1575
|
+
const hasJbStyles = /styles\/juicebox_(?:large|medium|small)\//i.test(html);
|
|
1576
|
+
const hasNodeBody = /<body[^>]+class=["'][^"']*\bnode\b[^"']*["']/i.test(html);
|
|
1577
|
+
const hasGalleryField = /field-name-(?:field_)?(?:pictures|images|image|post_pictures)\b/i.test(
|
|
1578
|
+
html
|
|
1579
|
+
);
|
|
1580
|
+
return hasJuicebox || hasFieldNode || hasJbStyles || hasNodeBody || hasGalleryField;
|
|
1581
|
+
}
|
|
1582
|
+
var ViewerAPI = {
|
|
1583
|
+
async resolveViewer(http, baseURL, urlOrSlug, opts = {}) {
|
|
1584
|
+
const url = buildViewerUrl(baseURL, urlOrSlug);
|
|
1585
|
+
const html = await fetchHtml(http, url);
|
|
1586
|
+
const parsedVideo = parseVideoFromHtml(html, baseURL);
|
|
1587
|
+
if (parsedVideo && parsedVideo.sources?.length) {
|
|
1588
|
+
const meta = tryParseRichMeta(html, baseURL, url);
|
|
419
1589
|
return {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
title: post.title,
|
|
429
|
-
kind: "images",
|
|
430
|
-
breadcrumbs: [],
|
|
431
|
-
authors: [],
|
|
432
|
-
sections: [],
|
|
433
|
-
tags: [],
|
|
434
|
-
characters: [],
|
|
435
|
-
userTags: []
|
|
436
|
-
},
|
|
437
|
-
images: post.images.map((u) => ({ original: u }))
|
|
438
|
-
}
|
|
1590
|
+
kind: "video",
|
|
1591
|
+
meta,
|
|
1592
|
+
video: {
|
|
1593
|
+
poster: parsedVideo.poster ? proxyImgMaybe(parsedVideo.poster, opts) : void 0,
|
|
1594
|
+
sources: parsedVideo.sources.map((s) => ({
|
|
1595
|
+
...s,
|
|
1596
|
+
proxied: proxyVidMaybe(s.url, opts)
|
|
1597
|
+
}))
|
|
439
1598
|
}
|
|
440
1599
|
};
|
|
441
1600
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
1601
|
+
if (hasViewerClues(html)) {
|
|
1602
|
+
const imgRes = parseImagesWithBackoff(html, baseURL);
|
|
1603
|
+
const images = (imgRes.images || []).map((im) => {
|
|
1604
|
+
const preferred = im.original || im.large || im.medium || im.small || im.thumb || "";
|
|
1605
|
+
return { ...im, proxied: proxyImgMaybe(preferred, opts) };
|
|
1606
|
+
});
|
|
1607
|
+
return {
|
|
1608
|
+
kind: "images",
|
|
1609
|
+
meta: imgRes.meta,
|
|
1610
|
+
images
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
return { kind: "other", meta: extractMeta(html, baseURL) };
|
|
1614
|
+
},
|
|
1615
|
+
async resolveSmart(http, baseURL, urlOrSlug, opts = {}) {
|
|
1616
|
+
const url = buildViewerUrl(baseURL, urlOrSlug);
|
|
1617
|
+
const u = new URL(url);
|
|
1618
|
+
const path = u.pathname;
|
|
1619
|
+
const html = await fetchHtml(http, url);
|
|
1620
|
+
const parsedVideo = parseVideoFromHtml(html, baseURL);
|
|
1621
|
+
if (parsedVideo && parsedVideo.sources?.length) {
|
|
1622
|
+
const meta = tryParseRichMeta(html, baseURL, url);
|
|
1623
|
+
const viewer = {
|
|
1624
|
+
kind: "video",
|
|
1625
|
+
meta,
|
|
1626
|
+
video: {
|
|
1627
|
+
poster: parsedVideo.poster ? proxyImgMaybe(parsedVideo.poster, opts) : void 0,
|
|
1628
|
+
sources: parsedVideo.sources.map((s) => ({
|
|
1629
|
+
...s,
|
|
1630
|
+
proxied: proxyVidMaybe(s.url, opts)
|
|
1631
|
+
}))
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
let recommendations;
|
|
1635
|
+
try {
|
|
1636
|
+
const recPage = parseHubListing(html, baseURL, 0);
|
|
1637
|
+
if (recPage?.items?.length) {
|
|
1638
|
+
recommendations = recPage.items.map((it) => ({
|
|
1639
|
+
...it,
|
|
1640
|
+
proxiedThumb: it.thumb ? proxyImgMaybe(it.thumb, opts) : void 0
|
|
1641
|
+
}));
|
|
1642
|
+
}
|
|
1643
|
+
} catch {
|
|
452
1644
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
async alphabetLetters(section) {
|
|
457
|
-
const path = section === "manga" ? "/munga" : `/${section}`;
|
|
458
|
-
const html = await this.http.getHtml(path);
|
|
459
|
-
const doc = this.dom.parse(html);
|
|
460
|
-
const root = doc.documentElement ?? doc;
|
|
461
|
-
const letters = [];
|
|
462
|
-
const els = this.dom.qsa(
|
|
463
|
-
root,
|
|
464
|
-
".alphabet a, .alphabet__item a, .letters a, a[href*='letter=']"
|
|
465
|
-
);
|
|
466
|
-
for (const a of els) {
|
|
467
|
-
const label = this.text(a) || this.attr(a, "data-letter");
|
|
468
|
-
if (!label) continue;
|
|
469
|
-
const href = this.attr(a, "href");
|
|
470
|
-
letters.push({ label, value: label, href });
|
|
1645
|
+
const data = { absoluteUrl: url, path, viewer };
|
|
1646
|
+
data.recommendations = recommendations;
|
|
1647
|
+
return { route: "viewer", data };
|
|
471
1648
|
}
|
|
472
|
-
if (
|
|
473
|
-
|
|
1649
|
+
if (hasViewerClues(html)) {
|
|
1650
|
+
const { meta, images } = parseImagesWithBackoff(html, baseURL);
|
|
1651
|
+
const mapped = (images || []).map((im) => {
|
|
1652
|
+
const preferred = im.original || im.large || im.medium || im.small || im.thumb || "";
|
|
1653
|
+
return { ...im, proxied: proxyImgMaybe(preferred, opts) };
|
|
1654
|
+
});
|
|
1655
|
+
const viewer = { kind: "images", meta, images: mapped };
|
|
1656
|
+
let recommendations;
|
|
1657
|
+
try {
|
|
1658
|
+
const recPage = parseHubListing(html, baseURL, 0);
|
|
1659
|
+
if (recPage?.items?.length) {
|
|
1660
|
+
recommendations = recPage.items.map((it) => ({
|
|
1661
|
+
...it,
|
|
1662
|
+
proxiedThumb: it.thumb ? proxyImgMaybe(it.thumb, opts) : void 0
|
|
1663
|
+
}));
|
|
1664
|
+
}
|
|
1665
|
+
} catch {
|
|
1666
|
+
}
|
|
1667
|
+
const data = { absoluteUrl: url, path, viewer };
|
|
1668
|
+
data.recommendations = recommendations;
|
|
1669
|
+
return { route: "viewer", data };
|
|
474
1670
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
1671
|
+
const page = await listings_exports.listByPath(http, baseURL, path, 0);
|
|
1672
|
+
return { route: "listing", data: { ...page, absoluteUrl: url, path } };
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
function extractText(html, re) {
|
|
1676
|
+
const m = html.match(re);
|
|
1677
|
+
return m ? m[1].replace(/<[^>]*>/g, "").trim() : "";
|
|
1678
|
+
}
|
|
1679
|
+
function grabLinksByLabel(html, baseURL, label) {
|
|
1680
|
+
const esc = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1681
|
+
const reLbl = new RegExp(
|
|
1682
|
+
`<(?:h3|div)[^>]*class=["'][^"']*field-label[^"']*["'][^>]*>\\s*${esc}\\s*:?\\s*<\\/[^>]+>`,
|
|
1683
|
+
"i"
|
|
1684
|
+
);
|
|
1685
|
+
const idx = html.search(reLbl);
|
|
1686
|
+
if (idx < 0) return [];
|
|
1687
|
+
const open = html.lastIndexOf("<div", idx);
|
|
1688
|
+
const close = html.indexOf("</div>", idx);
|
|
1689
|
+
if (open < 0 || close < 0) return [];
|
|
1690
|
+
const block = html.slice(open, close + 6);
|
|
1691
|
+
const out = [];
|
|
1692
|
+
const reA = /<a[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi;
|
|
1693
|
+
for (let m; m = reA.exec(block); ) {
|
|
1694
|
+
out.push({
|
|
1695
|
+
title: m[2].replace(/<[^>]*>/g, "").trim(),
|
|
1696
|
+
url: absolutize2(m[1], baseURL)
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
return out;
|
|
1700
|
+
}
|
|
1701
|
+
function grabLinks(html, blockRe, baseURL) {
|
|
1702
|
+
const alt = `(?:${blockRe.source})`;
|
|
1703
|
+
const reDiv = new RegExp(
|
|
1704
|
+
`<div[^>]*class=["'][^"']*\\bfield\\b[^"']*\\b${alt}\\b[^"']*["'][^>]*>([\\s\\S]*?)<\\/div>`,
|
|
1705
|
+
"i"
|
|
1706
|
+
);
|
|
1707
|
+
const m = reDiv.exec(html);
|
|
1708
|
+
if (!m) return [];
|
|
1709
|
+
const block = m[1];
|
|
1710
|
+
const arr = [];
|
|
1711
|
+
const reA = /<a[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi;
|
|
1712
|
+
for (let x; x = reA.exec(block); ) {
|
|
1713
|
+
arr.push({
|
|
1714
|
+
title: x[2].replace(/<[^>]*>/g, "").trim(),
|
|
1715
|
+
url: absolutize2(x[1], baseURL)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
return arr;
|
|
1719
|
+
}
|
|
1720
|
+
function extractMeta(html, baseURL) {
|
|
1721
|
+
const title = extractText(html, /<h1[^>]*id=["']page-title["'][^>]*>([\s\S]*?)<\/h1>/i) || extractText(html, /<title>([\s\S]*?)<\/title>/i);
|
|
1722
|
+
const breadcrumbs = [];
|
|
1723
|
+
const reCrumb = /<span[^>]*typeof=["']v:Breadcrumb["'][^>]*>[\s\S]*?<a[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>[\s\S]*?<\/span>/gi;
|
|
1724
|
+
for (let m; m = reCrumb.exec(html); ) {
|
|
1725
|
+
breadcrumbs.push({
|
|
1726
|
+
title: m[2].replace(/<[^>]*>/g, "").trim(),
|
|
1727
|
+
url: absolutize2(m[1], baseURL)
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
let authors = grabLinks(
|
|
1731
|
+
html,
|
|
1732
|
+
/field-name-field-vd-authors|field-name-field-authors|field-name-field-au/i,
|
|
1733
|
+
baseURL
|
|
1734
|
+
) || [];
|
|
1735
|
+
if (authors.length === 0) {
|
|
1736
|
+
authors = grabLinksByLabel(html, baseURL, "Author");
|
|
1737
|
+
}
|
|
1738
|
+
const sections = grabLinks(
|
|
1739
|
+
html,
|
|
1740
|
+
/field-name-field-vd-group|field-name-field-group|field-name-field-sections/i,
|
|
1741
|
+
baseURL
|
|
1742
|
+
);
|
|
1743
|
+
const tags = grabLinks(html, /field-name-field-(?:vd-)?tags|field-name-field-category/i, baseURL) || [];
|
|
1744
|
+
const meta = {
|
|
1745
|
+
title,
|
|
1746
|
+
breadcrumbs,
|
|
1747
|
+
authors,
|
|
1748
|
+
sections,
|
|
1749
|
+
tags,
|
|
1750
|
+
nodeId: "",
|
|
1751
|
+
fieldSys: {},
|
|
1752
|
+
kind: "viewer"
|
|
1753
|
+
};
|
|
1754
|
+
return meta;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// src/client-core.ts
|
|
1758
|
+
var MultpornClient = class {
|
|
1759
|
+
http;
|
|
1760
|
+
baseURL;
|
|
1761
|
+
constructor(opts = {}) {
|
|
1762
|
+
this.baseURL = (opts.baseURL ?? "https://multporn.net").replace(/\/+$/, "");
|
|
1763
|
+
this.http = new HttpClient({ ...opts, baseURL: this.baseURL });
|
|
1764
|
+
}
|
|
1765
|
+
// -------- Listing
|
|
1766
|
+
latest(page = 0, params) {
|
|
1767
|
+
return listings_exports.latest(this.http, this.baseURL, page, params);
|
|
1768
|
+
}
|
|
1769
|
+
listByPath(path, page = 0, params) {
|
|
1770
|
+
return listings_exports.listByPath(this.http, this.baseURL, path, page, params);
|
|
1771
|
+
}
|
|
1772
|
+
// -------- Search
|
|
1773
|
+
search(query, page = 0) {
|
|
1774
|
+
return search_exports.search(this.http, this.baseURL, query, page);
|
|
1775
|
+
}
|
|
1776
|
+
// -------- Post
|
|
1777
|
+
getPost(urlOrSlug) {
|
|
1778
|
+
return posts_exports.getPost(this.http, this.baseURL, urlOrSlug);
|
|
1779
|
+
}
|
|
1780
|
+
// -------- Viewer / Resolver
|
|
1781
|
+
/**
|
|
1782
|
+
* Жёсткое разрешение ссылки в ViewerResult (images/video/other) без маршрутизации.
|
|
1783
|
+
*/
|
|
1784
|
+
resolve(urlOrSlug, opts = {}) {
|
|
1785
|
+
return ViewerAPI.resolveViewer(this.http, this.baseURL, urlOrSlug, opts);
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Умный резолвер: возвращает либо listing-страницу (хаб), либо viewer-пейлоад (пост).
|
|
1789
|
+
*/
|
|
1790
|
+
resolveSmart(urlOrSlug, opts = {}) {
|
|
1791
|
+
return ViewerAPI.resolveSmart(this.http, this.baseURL, urlOrSlug, opts);
|
|
1792
|
+
}
|
|
1793
|
+
// -------- Updates (Drupal / jcarousel/ajax/views)
|
|
1794
|
+
updates(params = {}) {
|
|
1795
|
+
return updates_exports.updates(this.http, this.baseURL, params);
|
|
1796
|
+
}
|
|
1797
|
+
viewUpdates(viewName, params) {
|
|
1798
|
+
return this.updates({ ...params ?? {}, view_name: viewName });
|
|
1799
|
+
}
|
|
1800
|
+
// Шорткаты для популярных view_name — выше остаётся общий метод updates()
|
|
1801
|
+
updatesNewMini(p) {
|
|
1802
|
+
return updates_exports.updates(this.http, this.baseURL, { ...p ?? {}, view_name: "new_mini" });
|
|
1803
|
+
}
|
|
1804
|
+
userUploadFront(p) {
|
|
1805
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1806
|
+
...p ?? {},
|
|
1807
|
+
view_name: "user_upload_front"
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
updatedManga(p) {
|
|
1811
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1812
|
+
...p ?? {},
|
|
1813
|
+
view_name: "updated_manga"
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
updatedMangaPromoted(p) {
|
|
1817
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1818
|
+
...p ?? {},
|
|
1819
|
+
view_name: "updated_manga_promoted"
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
updatedGames(p) {
|
|
1823
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1824
|
+
...p ?? {},
|
|
1825
|
+
view_name: "updated_games"
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
randomTopComics(p) {
|
|
1829
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1830
|
+
...p ?? {},
|
|
1831
|
+
view_name: "random_top_comics"
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
topRandomCharacters(p) {
|
|
1835
|
+
return updates_exports.updates(this.http, this.baseURL, {
|
|
1836
|
+
...p ?? {},
|
|
1837
|
+
view_name: "top_random_characters"
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
// -------- Alphabet
|
|
1841
|
+
alphabetLetters(section) {
|
|
1842
|
+
return alphabet_exports.alphabetLetters(this.http, this.baseURL, section);
|
|
493
1843
|
}
|
|
494
|
-
|
|
495
|
-
return this.
|
|
1844
|
+
alphabet(section, letter, page = 0) {
|
|
1845
|
+
return alphabet_exports.alphabetItems(this.http, this.baseURL, section, letter, page);
|
|
496
1846
|
}
|
|
497
1847
|
};
|
|
498
1848
|
|
|
499
1849
|
// src/index.node.ts
|
|
500
|
-
var
|
|
1850
|
+
var MultpornClient2 = class extends MultpornClient {
|
|
501
1851
|
constructor(opts) {
|
|
502
1852
|
super({ ...opts || {}, dom: createCheerioDom() });
|
|
503
1853
|
}
|
|
504
1854
|
};
|
|
505
1855
|
|
|
506
|
-
export { HttpClient, HttpError, MultpornClient, defaultRetryPolicy };
|
|
1856
|
+
export { HttpClient, HttpError, MultpornClient2 as MultpornClient, defaultRetryPolicy };
|
|
507
1857
|
//# sourceMappingURL=index.js.map
|
|
508
1858
|
//# sourceMappingURL=index.js.map
|