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