--download=all
This commit is contained in:
parent
aac345833b
commit
94c6ade9cf
3 changed files with 30 additions and 16 deletions
|
@ -81,7 +81,11 @@ on conflict(reader_url)
|
|||
}
|
||||
|
||||
const path = `${bookDir.path}/${bookDir.name}`;
|
||||
const out = createWriteStream(`${path}.cbz`);
|
||||
const book = await this.get(bookDir.name);
|
||||
const title = book
|
||||
? `${book.authors.join("、")}「${book.title}」`.replace(/[/]/g, "%2F")
|
||||
: bookDir.name;
|
||||
const out = createWriteStream(`${dir}/${title}.cbz`);
|
||||
const zip = new Zip(function cb(err, data, final) {
|
||||
if (err) {
|
||||
out.destroy(err);
|
||||
|
|
34
main.ts
34
main.ts
|
@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
|||
import util from "node:util";
|
||||
import { chromium } from "./browser";
|
||||
import { createDatabase } from "./database";
|
||||
import { createLibrary } from "./library";
|
||||
import { type Book, createLibrary } from "./library";
|
||||
import { createPlatform } from "./platform";
|
||||
|
||||
const options = {
|
||||
|
@ -27,6 +27,7 @@ const options = {
|
|||
const browser = await chromium.launch({ headless: false });
|
||||
const platform = createPlatform({ db, browser });
|
||||
await platform.login();
|
||||
await browser.close();
|
||||
},
|
||||
},
|
||||
logout: {
|
||||
|
@ -36,6 +37,7 @@ const options = {
|
|||
const browser = await chromium.launch();
|
||||
const platform = createPlatform({ db, browser });
|
||||
await platform.logout();
|
||||
await browser.close();
|
||||
},
|
||||
},
|
||||
add: {
|
||||
|
@ -98,6 +100,8 @@ const options = {
|
|||
for await (const book of platform.pull()) {
|
||||
await library.add(book);
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
},
|
||||
},
|
||||
download: {
|
||||
|
@ -105,17 +109,29 @@ const options = {
|
|||
async run() {
|
||||
const db = await createDatabase(args.values.db!);
|
||||
const library = createLibrary(db);
|
||||
const book = await library.get(Number(args.values.download!));
|
||||
|
||||
if (!book) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const browser = await chromium.launch();
|
||||
const platform = createPlatform({ db, browser });
|
||||
const dir = `${args.values["out-dir"]!}/${book.id}`;
|
||||
await platform.download(dir, book);
|
||||
const books: Array<Book> = [];
|
||||
|
||||
if (args.values.download === "all") {
|
||||
books.push(...(await library.getBooks()));
|
||||
} else {
|
||||
const book = await library.get(Number(args.values.download!));
|
||||
|
||||
if (!book) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
books.push(book);
|
||||
}
|
||||
|
||||
for (const book of books) {
|
||||
const dir = `${args.values["out-dir"]!}/${book.id}`;
|
||||
await platform.download(dir, book);
|
||||
}
|
||||
|
||||
await library.archive(args.values["out-dir"]!);
|
||||
await browser.close();
|
||||
},
|
||||
},
|
||||
json: {
|
||||
|
|
|
@ -243,7 +243,6 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
|||
page.waitForURL("https://www.dmm.co.jp/top/", { timeout: 0 }),
|
||||
]);
|
||||
const secrets = await ctx.storageState();
|
||||
await browser.close();
|
||||
await db.run(
|
||||
`update platforms set secrets = ? where name = 'dmm-books'`,
|
||||
JSON.stringify(secrets),
|
||||
|
@ -251,7 +250,6 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
|||
},
|
||||
|
||||
async logout() {
|
||||
await browser.close();
|
||||
await db.run(
|
||||
`update platforms set secrets = 'null' where name = 'dmm-books'`,
|
||||
);
|
||||
|
@ -263,8 +261,6 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
|||
yield* getAllBooks(ctx);
|
||||
|
||||
process.stderr.write(`\n`);
|
||||
|
||||
await browser.close();
|
||||
},
|
||||
|
||||
async download(dir: string, book: Book) {
|
||||
|
@ -302,8 +298,6 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
|||
}
|
||||
|
||||
process.stderr.write(`\n`);
|
||||
|
||||
await browser.close();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue