36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const { parse } = require('../plugins/registry');
|
|
|
|
function mangaPillInfo(value) {
|
|
let url;
|
|
try { url = new URL(String(value)); } catch { return null; }
|
|
if (url.protocol !== 'https:' || url.hostname !== 'mangapill.com' || url.username || url.password || url.port) return null;
|
|
const match = /^\/manga\/(\d+)\/([a-z0-9-]+)\/?$/i.exec(url.pathname);
|
|
if (!match) return null;
|
|
return { source: 'mangapill', id: match[1], title: match[2].replace(/-/g, ' '),
|
|
url: `https://mangapill.com/manga/${match[1]}/${match[2]}` };
|
|
}
|
|
|
|
async function discoverMangaPillCatalog(seriesUrl, http) {
|
|
const html = await (await http.get(seriesUrl, { accept: 'text/html' })).text();
|
|
const parsed = parse('mangapill', 'catalog', { html, url: seriesUrl });
|
|
const chapters = parsed.chapters.sort((a, b) => Number(a.number) - Number(b.number));
|
|
return { ...parsed, chapters,
|
|
...(parsed.chapterLinks && !chapters.length ? { availability: { reason: 'unrecognized-labels',
|
|
message: `MangaPill lists ${parsed.chapterLinks} chapter links, but their numbering labels are not recognized.` } } : {}),
|
|
};
|
|
}
|
|
|
|
async function discoverMangaPillChapter(ref, http) {
|
|
const html = await (await http.get(ref.url, { accept: 'text/html' })).text();
|
|
const parsed = parse('mangapill', 'pages', { html, url: ref.url });
|
|
if (!parsed.pages.length) throw new Error(`No pages found for MangaPill chapter ${ref.number}`);
|
|
return { number: ref.number, title: ref.title || '',
|
|
source: { name: 'MangaPill', url: ref.url },
|
|
pages: parsed.pages.map(url => ({ url, headers: { referer: ref.url } })),
|
|
};
|
|
}
|
|
|
|
module.exports = { mangaPillInfo, discoverMangaPillCatalog, discoverMangaPillChapter };
|