@astrofoundry/trendarr 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +56 -3
- package/dist/clients/audiobookshelf.js +15 -2
- package/dist/commands/books.js +28 -0
- package/dist/format.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,11 +25,13 @@ trendarr books releases <bookId> --format audiobook|ebook [--max-entries 10] [--
|
|
|
25
25
|
trendarr books grab <chaptarrId> <guid> <indexerId> [--json]
|
|
26
26
|
trendarr books ready <chaptarrId> [--json]
|
|
27
27
|
trendarr books send <chaptarrId> <device> [--json]
|
|
28
|
+
trendarr books ebooks [--json]
|
|
29
|
+
trendarr books send-item <itemId> <device> [--json]
|
|
28
30
|
```
|
|
29
31
|
|
|
30
32
|
`trendarr <command> --help` shows parameters and output shapes. Movies below the IMDb min-rating (default 6.5) are dropped from trending; unrated movies are kept; `--min-rating 0` disables the filter. `recommend` ranks the titles TMDB recommends for your Radarr and Sonarr library by how many library titles lead to them, and keeps released titles not in the library with IMDb 7.0+ and 5,000 votes (movies) or 2,000 (series).
|
|
31
33
|
|
|
32
|
-
`books` works with Chaptarr, which keeps an audiobook and an ebook entry per work. `add` lets Chaptarr pick the release and waits up to 2 minutes to report whether it grabbed one; `releases` then `grab` let you pick one yourself (narrator, size, format). `ready` tells whether a book has its file and, for an ebook, whether Audiobookshelf has it. `send` emails an ebook to a Kindle through Audiobookshelf's e-reader devices.
|
|
34
|
+
`books` works with Chaptarr, which keeps an audiobook and an ebook entry per work. `add` lets Chaptarr pick the release and waits up to 2 minutes to report whether it grabbed one; `releases` then `grab` let you pick one yourself (narrator, size, format). `ready` tells whether a book has its file and, for an ebook, whether Audiobookshelf has it. `send` emails an ebook to a Kindle through Audiobookshelf's e-reader devices. `ebooks` lists every ebook in Audiobookshelf, newest first, and `send-item` emails one of them by its item id.
|
|
33
35
|
|
|
34
36
|
## Development
|
|
35
37
|
|
package/dist/cli.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { Command, InvalidArgumentError } from 'commander';
|
|
4
4
|
import { addMovies, addSeries, hasFailure } from './commands/add.js';
|
|
5
|
-
import { addBook, bookReady, bookReleases, grabRelease, searchBooks, sendBook } from './commands/books.js';
|
|
5
|
+
import { addBook, bookReady, bookReleases, grabRelease, listEbooks, searchBooks, sendBook, sendItem } from './commands/books.js';
|
|
6
6
|
import { runInit } from './commands/init.js';
|
|
7
7
|
import { runSabnzbd } from './commands/sabnzbd.js';
|
|
8
8
|
import { CANDIDATE_LIMIT, getRecommendations } from './commands/recommend.js';
|
|
9
9
|
import { getSearch } from './commands/search.js';
|
|
10
10
|
import { getTrending } from './commands/trending.js';
|
|
11
11
|
import { ConfigError, loadConfig } from './config.js';
|
|
12
|
-
import { renderAddTable, renderBookAdd, renderBookGrab, renderBookReady, renderBookSearchTable, renderBookSend, renderReleasesTable, renderRecommendTable, renderSabStatus, renderSearchDiscord, renderSearchTable, renderTrendingDiscord, renderTrendingTable, toJson, } from './format.js';
|
|
12
|
+
import { renderAddTable, renderBookAdd, renderBookGrab, renderBookReady, renderBookSearchTable, renderBookSend, renderEbookList, renderItemSend, renderReleasesTable, renderRecommendTable, renderSabStatus, renderSearchDiscord, renderSearchTable, renderTrendingDiscord, renderTrendingTable, toJson, } from './format.js';
|
|
13
13
|
import { describeError } from './http.js';
|
|
14
14
|
const pkg = createRequire(import.meta.url)('../package.json');
|
|
15
15
|
const program = new Command();
|
|
@@ -330,7 +330,9 @@ Actions:
|
|
|
330
330
|
releases <bookId> --format <f> List the releases you can pick from (narrator, size, quality).
|
|
331
331
|
grab <chaptarrId> <guid> <indexerId> Download one release from that list.
|
|
332
332
|
ready <chaptarrId> Whether the book has a file and, for an ebook, is in Audiobookshelf.
|
|
333
|
-
send <chaptarrId> <device> Email the ebook to a Kindle through Audiobookshelf
|
|
333
|
+
send <chaptarrId> <device> Email the ebook to a Kindle through Audiobookshelf.
|
|
334
|
+
ebooks List every ebook in Audiobookshelf, newest first, with the Kindles.
|
|
335
|
+
send-item <itemId> <device> Email one Audiobookshelf ebook item to a Kindle.`);
|
|
334
336
|
books
|
|
335
337
|
.command('search')
|
|
336
338
|
.description('search Chaptarr for books by title or author')
|
|
@@ -505,6 +507,57 @@ Examples:
|
|
|
505
507
|
fail(err);
|
|
506
508
|
}
|
|
507
509
|
});
|
|
510
|
+
books
|
|
511
|
+
.command('ebooks')
|
|
512
|
+
.description('list every ebook in Audiobookshelf, newest first, with the Kindle devices')
|
|
513
|
+
.option('--json', 'output JSON')
|
|
514
|
+
.addHelpText('after', `
|
|
515
|
+
Behavior: reads every book library of Audiobookshelf and keeps the items with an ebook file,
|
|
516
|
+
including ebooks Chaptarr does not manage. Changes nothing.
|
|
517
|
+
|
|
518
|
+
Output (--json): { "ebooks": EbookItem[], "kindles": string[] }
|
|
519
|
+
EbookItem: { item_id, title, author, added_at } — item_id is Audiobookshelf's library item id,
|
|
520
|
+
for send-item; added_at is ISO 8601 or null.
|
|
521
|
+
|
|
522
|
+
Examples:
|
|
523
|
+
trendarr books ebooks --json`)
|
|
524
|
+
.action(async (opts) => {
|
|
525
|
+
try {
|
|
526
|
+
const { output, warnings } = await listEbooks(loadConfig());
|
|
527
|
+
printWarnings(warnings);
|
|
528
|
+
process.stdout.write(`${opts.json === true ? toJson(output) : renderEbookList(output)}\n`);
|
|
529
|
+
}
|
|
530
|
+
catch (err) {
|
|
531
|
+
fail(err);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
books
|
|
535
|
+
.command('send-item')
|
|
536
|
+
.description('email one Audiobookshelf ebook item to a Kindle')
|
|
537
|
+
.argument('<itemId>', 'item_id from books ebooks')
|
|
538
|
+
.argument('<device>', 'Audiobookshelf e-reader device name, from books ebooks "kindles"')
|
|
539
|
+
.option('--json', 'output JSON')
|
|
540
|
+
.addHelpText('after', `
|
|
541
|
+
Behavior: asks Audiobookshelf to email that item's ebook to the device. The sender must be approved
|
|
542
|
+
on the Amazon account.
|
|
543
|
+
|
|
544
|
+
Output (--json): { item_id, device, status, detail }
|
|
545
|
+
status is one of: sent | unknown_device | error. Exit code 1 unless sent.
|
|
546
|
+
|
|
547
|
+
Examples:
|
|
548
|
+
trendarr books send-item ed3cbf09-3303-4714-ae11-f190d8279af5 "Kindle Astro"`)
|
|
549
|
+
.action(async (itemId, device, opts) => {
|
|
550
|
+
try {
|
|
551
|
+
const { output, warnings } = await sendItem(loadConfig(), itemId, device);
|
|
552
|
+
printWarnings(warnings);
|
|
553
|
+
process.stdout.write(`${opts.json === true ? toJson(output) : renderItemSend(output)}\n`);
|
|
554
|
+
if (output.status !== 'sent')
|
|
555
|
+
process.exitCode = 1;
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
fail(err);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
508
561
|
if (process.argv.slice(2).length === 0) {
|
|
509
562
|
program.outputHelp();
|
|
510
563
|
process.exit(0);
|
|
@@ -8,7 +8,13 @@ const itemsSchema = z.object({
|
|
|
8
8
|
results: z.array(z.object({
|
|
9
9
|
id: z.string(),
|
|
10
10
|
path: z.string(),
|
|
11
|
-
|
|
11
|
+
addedAt: z.number().nullish(),
|
|
12
|
+
media: z
|
|
13
|
+
.object({
|
|
14
|
+
ebookFormat: z.string().nullish(),
|
|
15
|
+
metadata: z.object({ title: z.string().nullish(), authorName: z.string().nullish() }).nullish(),
|
|
16
|
+
})
|
|
17
|
+
.nullish(),
|
|
12
18
|
})),
|
|
13
19
|
});
|
|
14
20
|
export class AudiobookshelfClient {
|
|
@@ -30,7 +36,14 @@ export class AudiobookshelfClient {
|
|
|
30
36
|
}
|
|
31
37
|
async items(libraryId) {
|
|
32
38
|
const parsed = itemsSchema.parse(await this.request(`/api/libraries/${encodeURIComponent(libraryId)}/items?limit=0`));
|
|
33
|
-
return parsed.results.map((i) => ({
|
|
39
|
+
return parsed.results.map((i) => ({
|
|
40
|
+
id: i.id,
|
|
41
|
+
path: i.path,
|
|
42
|
+
ebookFormat: i.media?.ebookFormat ?? null,
|
|
43
|
+
title: i.media?.metadata?.title ?? null,
|
|
44
|
+
author: i.media?.metadata?.authorName ?? null,
|
|
45
|
+
addedAt: i.addedAt ?? null,
|
|
46
|
+
}));
|
|
34
47
|
}
|
|
35
48
|
async sendEbook(libraryItemId, deviceName) {
|
|
36
49
|
await this.request('/api/emails/send-ebook-to-device', {
|
package/dist/commands/books.js
CHANGED
|
@@ -266,3 +266,31 @@ export async function sendBook(config, bookId, device) {
|
|
|
266
266
|
return { output: { ...base, title, status: 'error', detail: httpDetail(err) }, warnings: [] };
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
+
export async function listEbooks(config) {
|
|
270
|
+
const abs = audiobookshelf(config);
|
|
271
|
+
const found = [];
|
|
272
|
+
for (const library of (await abs.libraries()).filter((l) => l.mediaType === 'book')) {
|
|
273
|
+
for (const i of await abs.items(library.id)) {
|
|
274
|
+
if (i.ebookFormat === null)
|
|
275
|
+
continue;
|
|
276
|
+
const added_at = i.addedAt === null ? null : new Date(i.addedAt).toISOString();
|
|
277
|
+
found.push({ item: { item_id: i.id, title: i.title ?? i.path, author: i.author, added_at }, addedAt: i.addedAt ?? 0 });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const ebooks = found.sort((a, b) => b.addedAt - a.addedAt).map((f) => f.item);
|
|
281
|
+
return { output: { ebooks, kindles: await abs.ereaderDevices() }, warnings: [] };
|
|
282
|
+
}
|
|
283
|
+
export async function sendItem(config, itemId, device) {
|
|
284
|
+
const abs = audiobookshelf(config);
|
|
285
|
+
const base = { item_id: itemId, device };
|
|
286
|
+
try {
|
|
287
|
+
if (!(await abs.ereaderDevices()).includes(device)) {
|
|
288
|
+
return { output: { ...base, status: 'unknown_device', detail: null }, warnings: [] };
|
|
289
|
+
}
|
|
290
|
+
await abs.sendEbook(itemId, device);
|
|
291
|
+
return { output: { ...base, status: 'sent', detail: null }, warnings: [] };
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
return { output: { ...base, status: 'error', detail: httpDetail(err) }, warnings: [] };
|
|
295
|
+
}
|
|
296
|
+
}
|
package/dist/format.js
CHANGED
|
@@ -148,3 +148,15 @@ export function renderBookReady(output) {
|
|
|
148
148
|
const kindles = output.kindles.length === 0 ? '' : `\nKindles: ${output.kindles.join(', ')}`;
|
|
149
149
|
return `${output.title} [${output.format}] ${file}${abs}${kindles}`;
|
|
150
150
|
}
|
|
151
|
+
export function renderEbookList(output) {
|
|
152
|
+
if (output.ebooks.length === 0)
|
|
153
|
+
return 'No ebooks.';
|
|
154
|
+
const header = `${cell('TITLE', 44)} ${cell('AUTHOR', 24)} ${cell('ADDED', 10)} ITEM`;
|
|
155
|
+
const rows = output.ebooks.map((e) => `${cell(e.title, 44)} ${cell(dash(e.author), 24)} ${cell(e.added_at?.slice(0, 10) ?? '-', 10)} ${e.item_id}`);
|
|
156
|
+
const kindles = output.kindles.length === 0 ? 'Kindles: none' : `Kindles: ${output.kindles.join(', ')}`;
|
|
157
|
+
return [pc.bold(header), ...rows, '', kindles].join('\n');
|
|
158
|
+
}
|
|
159
|
+
export function renderItemSend(output) {
|
|
160
|
+
const detail = output.detail === null ? '' : ` (${output.detail})`;
|
|
161
|
+
return `${output.item_id} → ${output.device}: ${statusColor(output.status, ['sent'])}${detail}`;
|
|
162
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrofoundry/trendarr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "TMDB trending → OMDb ratings → Radarr/Sonarr adds → SABnzbd control, from the terminal",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -p tsconfig.build.json && chmod +x dist/cli.js",
|