@astrofoundry/trendarr 0.10.2 → 0.11.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 CHANGED
@@ -23,12 +23,13 @@ trendarr books search <query> [--max-entries 10] [--json]
23
23
  trendarr books add <bookId> --format audiobook|ebook [--json]
24
24
  trendarr books releases <bookId> --format audiobook|ebook [--max-entries 10] [--json]
25
25
  trendarr books grab <chaptarrId> <guid> <indexerId> [--json]
26
+ trendarr books ready <chaptarrId> [--json]
26
27
  trendarr books send <chaptarrId> <device> [--json]
27
28
  ```
28
29
 
29
30
  `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).
30
31
 
31
- `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). `send` emails an ebook to a Kindle through Audiobookshelf's e-reader devices.
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.
32
33
 
33
34
  ## Development
34
35
 
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, bookReleases, grabRelease, searchBooks, sendBook } from './commands/books.js';
5
+ import { addBook, bookReady, bookReleases, grabRelease, searchBooks, sendBook } 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, renderBookSearchTable, renderBookSend, renderReleasesTable, renderRecommendTable, renderSabStatus, renderSearchDiscord, renderSearchTable, renderTrendingDiscord, renderTrendingTable, toJson, } from './format.js';
12
+ import { renderAddTable, renderBookAdd, renderBookGrab, renderBookReady, renderBookSearchTable, renderBookSend, 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();
@@ -329,6 +329,7 @@ Actions:
329
329
  add <bookId> --format <f> Monitor one format and let Chaptarr pick and download a release.
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
+ ready <chaptarrId> Whether the book has a file and, for an ebook, is in Audiobookshelf.
332
333
  send <chaptarrId> <device> Email the ebook to a Kindle through Audiobookshelf.`);
333
334
  books
334
335
  .command('search')
@@ -451,6 +452,31 @@ Examples:
451
452
  fail(err);
452
453
  }
453
454
  });
455
+ books
456
+ .command('ready')
457
+ .description('report whether a book has its file and, for an ebook, whether Audiobookshelf has it')
458
+ .argument('<chaptarrId>', 'book_id from books add, releases, or search', parsePositiveInt)
459
+ .option('--json', 'output JSON')
460
+ .addHelpText('after', `
461
+ Behavior: reads the book and its files from Chaptarr. For an ebook with a file, it looks for the
462
+ Audiobookshelf item in that folder, as send does, and lists the Kindles. Changes nothing.
463
+
464
+ Output (--json): { book_id, title, format, has_file, in_audiobookshelf, kindles }
465
+ in_audiobookshelf is false and kindles empty for an audiobook or a book without a file.
466
+ An ebook is ready to send when has_file and in_audiobookshelf are both true.
467
+
468
+ Examples:
469
+ trendarr books ready 6237 --json`)
470
+ .action(async (chaptarrId, opts) => {
471
+ try {
472
+ const { output, warnings } = await bookReady(loadConfig(), chaptarrId);
473
+ printWarnings(warnings);
474
+ process.stdout.write(`${opts.json === true ? toJson(output) : renderBookReady(output)}\n`);
475
+ }
476
+ catch (err) {
477
+ fail(err);
478
+ }
479
+ });
454
480
  books
455
481
  .command('send')
456
482
  .description('email an ebook to a Kindle through Audiobookshelf')
@@ -21,6 +21,9 @@ function audiobookshelf(config) {
21
21
  }
22
22
  return new AudiobookshelfClient(config.audiobookshelf.url, config.audiobookshelf.apiKey);
23
23
  }
24
+ function formatOf(mediaType) {
25
+ return mediaType === 'ebook' ? 'ebook' : 'audiobook';
26
+ }
24
27
  function preferred(books) {
25
28
  return books.find((b) => b.hasFiles) ?? books.find((b) => b.monitored) ?? books[0] ?? null;
26
29
  }
@@ -208,7 +211,7 @@ export async function grabRelease(config, bookId, guid, indexerId) {
208
211
  try {
209
212
  const book = await client.book(bookId);
210
213
  title = book.title;
211
- format = book.mediaType === 'ebook' ? 'ebook' : 'audiobook';
214
+ format = formatOf(book.mediaType);
212
215
  await client.setMonitored([bookId], true);
213
216
  await client.grab(guid, indexerId);
214
217
  result = { status: 'grabbed', detail: null };
@@ -219,6 +222,27 @@ export async function grabRelease(config, bookId, guid, indexerId) {
219
222
  const sabnzbd_paused = await sabPausedFor(config, client, format, warnings);
220
223
  return { output: { book_id: bookId, title, ...result, sabnzbd_paused }, warnings };
221
224
  }
225
+ async function audiobookshelfItem(abs, paths) {
226
+ const folders = new Set(paths.map((p) => dirname(p)));
227
+ for (const library of (await abs.libraries()).filter((l) => l.mediaType === 'book')) {
228
+ const item = (await abs.items(library.id)).find((i) => folders.has(i.path) && i.ebookFormat !== null);
229
+ if (item !== undefined)
230
+ return item.id;
231
+ }
232
+ return null;
233
+ }
234
+ export async function bookReady(config, bookId) {
235
+ const client = chaptarr(config);
236
+ const book = await client.book(bookId);
237
+ const paths = await client.bookFilePaths(bookId);
238
+ const base = { book_id: bookId, title: book.title, format: formatOf(book.mediaType), has_file: paths.length > 0 };
239
+ if (base.format !== 'ebook' || paths.length === 0) {
240
+ return { output: { ...base, in_audiobookshelf: false, kindles: [] }, warnings: [] };
241
+ }
242
+ const abs = audiobookshelf(config);
243
+ const item = await audiobookshelfItem(abs, paths);
244
+ return { output: { ...base, in_audiobookshelf: item !== null, kindles: await abs.ereaderDevices() }, warnings: [] };
245
+ }
222
246
  export async function sendBook(config, bookId, device) {
223
247
  const client = chaptarr(config);
224
248
  const abs = audiobookshelf(config);
@@ -229,17 +253,14 @@ export async function sendBook(config, bookId, device) {
229
253
  if (!(await abs.ereaderDevices()).includes(device)) {
230
254
  return { output: { ...base, title, status: 'unknown_device', detail: null }, warnings: [] };
231
255
  }
232
- const folders = new Set((await client.bookFilePaths(bookId)).map((p) => dirname(p)));
233
- if (folders.size === 0)
256
+ const paths = await client.bookFilePaths(bookId);
257
+ if (paths.length === 0)
234
258
  return { output: { ...base, title, status: 'no_file', detail: null }, warnings: [] };
235
- for (const library of (await abs.libraries()).filter((l) => l.mediaType === 'book')) {
236
- const item = (await abs.items(library.id)).find((i) => folders.has(i.path) && i.ebookFormat !== null);
237
- if (item === undefined)
238
- continue;
239
- await abs.sendEbook(item.id, device);
240
- return { output: { ...base, title, status: 'sent', detail: null }, warnings: [] };
241
- }
242
- return { output: { ...base, title, status: 'not_in_audiobookshelf', detail: null }, warnings: [] };
259
+ const item = await audiobookshelfItem(abs, paths);
260
+ if (item === null)
261
+ return { output: { ...base, title, status: 'not_in_audiobookshelf', detail: null }, warnings: [] };
262
+ await abs.sendEbook(item, device);
263
+ return { output: { ...base, title, status: 'sent', detail: null }, warnings: [] };
243
264
  }
244
265
  catch (err) {
245
266
  return { output: { ...base, title, status: 'error', detail: httpDetail(err) }, warnings: [] };
package/dist/format.js CHANGED
@@ -142,3 +142,9 @@ export function renderBookSend(output) {
142
142
  const detail = output.detail === null ? '' : ` (${output.detail})`;
143
143
  return `${output.title ?? `book ${output.book_id}`} → ${output.device}: ${statusColor(output.status, ['sent'])}${detail}`;
144
144
  }
145
+ export function renderBookReady(output) {
146
+ const file = output.has_file ? pc.green('file') : pc.yellow('no file');
147
+ const abs = output.format !== 'ebook' ? '' : output.in_audiobookshelf ? `, ${pc.green('in Audiobookshelf')}` : `, ${pc.yellow('not in Audiobookshelf')}`;
148
+ const kindles = output.kindles.length === 0 ? '' : `\nKindles: ${output.kindles.join(', ')}`;
149
+ return `${output.title} [${output.format}] ${file}${abs}${kindles}`;
150
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/trendarr",
3
- "version": "0.10.2",
3
+ "version": "0.11.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",