diff --git a/tts.ts b/tts.ts index 5f37923..fc131a5 100644 --- a/tts.ts +++ b/tts.ts @@ -13,8 +13,8 @@ const { values: args } = parseArgs({ options: { wait: { type: "boolean" }, w: { type: "boolean" }, - url: { type: "boolean" }, - u: { type: "boolean" }, + url: { type: "string" }, + u: { type: "string" }, }, strict: true, allowPositionals: true, @@ -22,23 +22,23 @@ const { values: args } = parseArgs({ const wait = args.wait ?? args.w; const url = args.url ?? args.u; -let text = await Bun.stdin.text(); +let input = url ? url : await Bun.stdin.text(); -if (url) { - const result = await fetch(text.trim()); - const window = new Window({ url: text.trim() }); +if (url !== undefined) { + const result = await fetch(input.trim()); + const window = new Window({ url: input.trim() }); const doc = window.document; doc.write(await result.text()); await window.happyDOM.waitUntilComplete(); const readable = new Readability(doc).parse(); - if (readable?.textContent) text = readable.textContent; - if (text.trim() === result.url) { + if (readable?.textContent) input = readable.textContent; + if (input.trim() === result.url) { console.error("Unable to read web page."); process.exit(1); } } -if (!text) { +if (!input) { console.error("No input given."); process.exit(1); } @@ -59,7 +59,7 @@ console.log( const koko = Bun.spawn({ cmd: ["uv", "run", "--", "python", "-u", "main.py"], cwd, - stdin: Buffer.from(text), + stdin: Buffer.from(input), stdout: "pipe", stderr: "inherit", });