Skip to content

Commit 76f81b5

Browse files
1 parent 2732b5d commit 76f81b5

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"type": "git",
1010
"url": "git+https://github.com/transitive-bullshit/kindle-ai-export.git"
1111
},
12-
"packageManager": "pnpm@9.11.0",
12+
"packageManager": "pnpm@10.18.3",
1313
"engines": {
14-
"node": ">=18"
14+
"node": ">=20"
1515
},
1616
"type": "module",
1717
"scripts": {
@@ -33,6 +33,7 @@
3333
"node-id3": "^0.2.6",
3434
"openai-fetch": "^3.3.1",
3535
"p-map": "^7.0.2",
36+
"patchright": "^1.56.1",
3637
"pdfkit": "^0.15.0",
3738
"playwright": "^1.48.0",
3839
"playwright-core": "^1.48.0",

pnpm-lock.yaml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extract-kindle-book.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import path from 'node:path'
55

66
import { input } from '@inquirer/prompts'
77
import delay from 'delay'
8-
import { chromium, type Locator } from 'playwright'
8+
// import { chromium, type Locator } from 'playwright'
9+
import { chromium, type Locator } from 'patchright'
910

1011
import type { BookInfo, BookMeta, BookMetadata, PageChunk } from './types'
1112
import {
@@ -34,6 +35,7 @@ async function main() {
3435
assert(asin, 'ASIN is required')
3536
assert(amazonEmail, 'AMAZON_EMAIL is required')
3637
assert(amazonPassword, 'AMAZON_PASSWORD is required')
38+
const asinL = asin.toLowerCase()
3739

3840
const outDir = path.join('out', asin)
3941
const userDataDir = path.join(outDir, 'data')
@@ -44,18 +46,31 @@ async function main() {
4446
const krRendererMainImageSelector = '#kr-renderer .kg-full-page-img img'
4547
const bookReaderUrl = `https://read.amazon.com/?asin=${asin}`
4648

49+
// const context = await chromium.launchPersistentContext(userDataDir, {
50+
// headless: false,
51+
// channel: 'chrome',
52+
// executablePath:
53+
// '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
54+
// args: ['--hide-crash-restore-bubble'],
55+
// ignoreDefaultArgs: ['--enable-automation'],
56+
// deviceScaleFactor: 2,
57+
// viewport: { width: 1280, height: 720 }
58+
// })
59+
4760
const context = await chromium.launchPersistentContext(userDataDir, {
4861
headless: false,
4962
channel: 'chrome',
50-
executablePath:
51-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
52-
args: ['--hide-crash-restore-bubble'],
63+
args: [
64+
'--hide-crash-restore-bubble',
65+
'--disable-features=PasswordAutosave',
66+
'--disable-features=WebAuthn'
67+
],
5368
ignoreDefaultArgs: ['--enable-automation'],
5469
deviceScaleFactor: 2,
5570
viewport: { width: 1280, height: 720 }
5671
})
57-
const page = await context.newPage()
5872

73+
const page = context.pages()[0] ?? (await context.newPage())
5974
let info: BookInfo | undefined
6075
let meta: BookMeta | undefined
6176

@@ -68,7 +83,7 @@ async function main() {
6883
if (
6984
url.hostname === 'read.amazon.com' &&
7085
url.pathname === '/service/mobile/reader/startReading' &&
71-
url.searchParams.get('asin')?.toLowerCase() === asin.toLowerCase()
86+
url.searchParams.get('asin')?.toLowerCase() === asinL
7287
) {
7388
const body: any = await response.json()
7489
delete body.karamelToken

src/transcribe-book-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function main() {
4545

4646
do {
4747
const res = await openai.createChatCompletion({
48-
model: 'gpt-4o',
48+
model: 'gpt-4.1-mini',
4949
temperature: retries < 2 ? 0 : 0.5,
5050
messages: [
5151
{

0 commit comments

Comments
 (0)