view
This commit is contained in:
parent
ef7445ab10
commit
f242adb848
3 changed files with 32 additions and 9 deletions
|
@ -20,6 +20,14 @@ export function createLibrary(db: Database) {
|
||||||
async delete(id: number) {
|
async delete(id: number) {
|
||||||
await db.run(`delete from books where id = ?`, id);
|
await db.run(`delete from books where id = ?`, id);
|
||||||
},
|
},
|
||||||
|
async get(id: number): Promise<Book | undefined> {
|
||||||
|
const book: Book | undefined = await db.get(
|
||||||
|
`select books.id, platforms.name as platform, books.reader_url as readerUrl from books left join platforms on books.platform_id = platforms.id where books.id = ?`,
|
||||||
|
id,
|
||||||
|
);
|
||||||
|
|
||||||
|
return book;
|
||||||
|
},
|
||||||
async getBooks(): Promise<Array<Book>> {
|
async getBooks(): Promise<Array<Book>> {
|
||||||
const books: Array<Book> = await db.all(
|
const books: Array<Book> = await db.all(
|
||||||
`select books.id, platforms.name as platform, books.reader_url as readerUrl from books left join platforms on books.platform_id = platforms.id`,
|
`select books.id, platforms.name as platform, books.reader_url as readerUrl from books left join platforms on books.platform_id = platforms.id`,
|
||||||
|
|
23
main.ts
23
main.ts
|
@ -60,15 +60,34 @@ const options = {
|
||||||
console.dir(books, { depth: null });
|
console.dir(books, { depth: null });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
view: {
|
||||||
|
type: "string",
|
||||||
|
async run() {
|
||||||
|
const db = await createDatabase(args.values.db!);
|
||||||
|
const library = createLibrary(db);
|
||||||
|
const book = await library.get(Number(args.values.view!));
|
||||||
|
|
||||||
|
if (!book) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.dir(book, { depth: null });
|
||||||
|
},
|
||||||
|
},
|
||||||
download: {
|
download: {
|
||||||
type: "string",
|
type: "string",
|
||||||
async run() {
|
async run() {
|
||||||
const db = await createDatabase(args.values.db!);
|
const db = await createDatabase(args.values.db!);
|
||||||
const library = createLibrary(db);
|
const library = createLibrary(db);
|
||||||
const books = await library.getBooks();
|
const book = await library.get(Number(args.values.download!));
|
||||||
|
|
||||||
|
if (!book) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const platform = createPlatform({ db, browser });
|
const platform = createPlatform({ db, browser });
|
||||||
await platform.download(args.values.download!, books);
|
await platform.download(args.values.download!, book);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
help: {
|
help: {
|
||||||
|
|
|
@ -143,16 +143,12 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
||||||
`update platforms set secrets = 'null' where name = 'dmm-books'`,
|
`update platforms set secrets = 'null' where name = 'dmm-books'`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
async download(dir: string, books: Array<Book>) {
|
async download(dir: string, book: Book) {
|
||||||
await fs.mkdir(dir);
|
|
||||||
|
|
||||||
const ctx = await loadBrowserContext();
|
const ctx = await loadBrowserContext();
|
||||||
const page = await ctx.newPage();
|
const page = await ctx.newPage();
|
||||||
|
|
||||||
// TODO: 複数ブックのサポート
|
// TODO: --all
|
||||||
const book = books[0];
|
await fs.mkdir(dir);
|
||||||
|
|
||||||
// TODO: downloadBook() にまとめる
|
|
||||||
await page.goto(book.readerUrl);
|
await page.goto(book.readerUrl);
|
||||||
|
|
||||||
const files = await page.evaluate(getFiles);
|
const files = await page.evaluate(getFiles);
|
||||||
|
|
Loading…
Add table
Reference in a new issue