support zip file
This commit is contained in:
parent
5135d5121f
commit
7547a34e03
5 changed files with 67 additions and 10 deletions
23
library.ts
23
library.ts
|
@ -107,6 +107,27 @@ on conflict(reader_url)
|
||||||
book.title
|
book.title
|
||||||
}`.replace(/[/]/g, "%2F");
|
}`.replace(/[/]/g, "%2F");
|
||||||
|
|
||||||
|
const files = await fs.readdir(path);
|
||||||
|
|
||||||
|
if (files.every((f) => f.match(/[.](zip|cbz)$/))) {
|
||||||
|
const digits = String(files.length).length;
|
||||||
|
|
||||||
|
function pad(n: string) {
|
||||||
|
return n.padStart(digits, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [n, f] of Object.entries(files)) {
|
||||||
|
await fs.rename(
|
||||||
|
`${path}/${f}`,
|
||||||
|
`${opts.outDir}/${title}${
|
||||||
|
files.length > 1 ? ` - ${pad(n)}` : ""
|
||||||
|
}.${f.split(".").at(-1)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await fs.rmdir(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const out = createWriteStream(`${opts.outDir}/${title}.cbz`);
|
const out = createWriteStream(`${opts.outDir}/${title}.cbz`);
|
||||||
|
|
||||||
const zip = new Zip(function cb(err, data, final) {
|
const zip = new Zip(function cb(err, data, final) {
|
||||||
|
@ -118,8 +139,6 @@ on conflict(reader_url)
|
||||||
out[final ? "end" : "write"](data);
|
out[final ? "end" : "write"](data);
|
||||||
});
|
});
|
||||||
|
|
||||||
const files = await fs.readdir(path);
|
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const data = new ZipPassThrough(file);
|
const data = new ZipPassThrough(file);
|
||||||
zip.add(data);
|
zip.add(data);
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@fogtype/gadl",
|
"name": "@fogtype/gadl",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@fogtype/gadl",
|
"name": "@fogtype/gadl",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fflate": "^0.8.1",
|
"fflate": "^0.8.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@fogtype/gadl",
|
"name": "@fogtype/gadl",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": "bin/run.js",
|
"bin": "bin/run.js",
|
||||||
|
|
|
@ -55,6 +55,8 @@ export function createPlatform(opts: {
|
||||||
const supportedTypes = {
|
const supportedTypes = {
|
||||||
"image/png": "png",
|
"image/png": "png",
|
||||||
"image/jpeg": "jpg",
|
"image/jpeg": "jpg",
|
||||||
|
"application/zip": "zip",
|
||||||
|
"application/vnd.comicbook+zip": "cbz",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [n, dataUrl] of Object.entries(files)) {
|
for (const [n, dataUrl] of Object.entries(files)) {
|
||||||
|
|
|
@ -72,13 +72,49 @@ export function FanzaDoujin(browser: Browser) {
|
||||||
const page = await ctx.newPage();
|
const page = await ctx.newPage();
|
||||||
|
|
||||||
await page.goto(book.readerUrl);
|
await page.goto(book.readerUrl);
|
||||||
|
|
||||||
|
const [, productId] = /product_id=([^/]*)/.exec(book.readerUrl) ?? [];
|
||||||
|
|
||||||
|
if (!productId) {
|
||||||
|
throw new Error(`product_id is not included: ${book.readerUrl}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await ctx.request.get(
|
||||||
|
`https://www.dmm.co.jp/dc/doujin/api/mylibraries/details/${productId}/`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res.ok()) {
|
||||||
|
throw new Error(`${res.status()} ${res.statusText()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body: {
|
||||||
|
data: {
|
||||||
|
drm: {
|
||||||
|
dmmBooks: boolean;
|
||||||
|
softDenchi: boolean;
|
||||||
|
};
|
||||||
|
downloadLinks: Record<number, string>;
|
||||||
|
};
|
||||||
|
} = await res.json();
|
||||||
|
|
||||||
|
const imageFiles: Array<ImageFile> = [];
|
||||||
|
|
||||||
|
if (body.data.drm.dmmBooks) {
|
||||||
await page.waitForSelector(`li[class^="fileTreeItem"]`);
|
await page.waitForSelector(`li[class^="fileTreeItem"]`);
|
||||||
await page.click(`li[class^="fileTreeItem"]>a`);
|
await page.click(`li[class^="fileTreeItem"]>a`);
|
||||||
await page.waitForURL((url) =>
|
await page.waitForURL((url) =>
|
||||||
url.href.startsWith("https://www.dmm.co.jp/dc/-/viewer/=/product_id="),
|
url.href.startsWith(
|
||||||
|
"https://www.dmm.co.jp/dc/-/viewer/=/product_id=",
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const imageFiles: Array<ImageFile> = await page.evaluate(getImageFiles);
|
imageFiles.push(...(await page.evaluate(getImageFiles)));
|
||||||
|
} else {
|
||||||
|
for (const link of Object.values(body.data.downloadLinks)) {
|
||||||
|
const url = new URL(link, "https://www.dmm.co.jp/").href;
|
||||||
|
imageFiles.push({ url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return imageFiles.map((imageFile) => async () => {
|
return imageFiles.map((imageFile) => async () => {
|
||||||
const dataUrl = await browser.drawImage(page, imageFile);
|
const dataUrl = await browser.drawImage(page, imageFile);
|
||||||
|
|
Loading…
Add table
Reference in a new issue