@astrofoundry/trendarr 0.14.0 → 0.15.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
@@ -29,12 +29,13 @@ trendarr books best <bookId> --format audiobook|ebook [--edition <id>] [--json]
29
29
  trendarr books ready <chaptarrId> [--json]
30
30
  trendarr books send <chaptarrId> <device> [--json]
31
31
  trendarr books ebooks [--json]
32
+ trendarr books audiobooks [--json]
32
33
  trendarr books send-item <itemId> <device> [--json]
33
34
  ```
34
35
 
35
36
  `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).
36
37
 
37
- `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). `narrators` lists an audiobook's narrations, most rated first; `--edition` on `releases` and `best` monitors the one you pick first. Audiobook releases come best first: the narrator's surname in the name, then M4B, then the bitrate estimated from the edition's length. Chaptarr refuses some public trackers (its indexer test finds no book in their recent list), so with Prowlarr configured, audiobook releases also include the torrents of Prowlarr indexers Chaptarr lacks; `push` sends one to Chaptarr, which checks it like an RSS release and files it under the monitored book its name matches. `best` grabs or pushes the first of them without a Chaptarr rejection, or leaves the book wanted. `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.
38
+ `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). `narrators` lists an audiobook's narrations, most rated first; `--edition` on `releases` and `best` monitors the one you pick first. Audiobook releases come best first: the narrator's surname in the name, then M4B, then the bitrate estimated from the edition's length. Chaptarr refuses some public trackers (its indexer test finds no book in their recent list), so with Prowlarr configured, audiobook releases also include the torrents of Prowlarr indexers Chaptarr lacks; `push` sends one to Chaptarr, which checks it like an RSS release and files it under the monitored book its name matches. `best` grabs or pushes the first of them without a Chaptarr rejection, or leaves the book wanted. `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. `audiobooks` lists every audiobook in Audiobookshelf, newest first, with narrator and length.
38
39
 
39
40
  ## Development
40
41
 
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, bestBook, bookNarrators, bookReady, bookReleases, grabRelease, pushRelease, listEbooks, searchBooks, sendBook, sendItem, } from './commands/books.js';
5
+ import { addBook, bestBook, bookNarrators, bookReady, bookReleases, grabRelease, pushRelease, listAudiobooks, 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, renderBookBest, renderBookGrab, renderBookReady, renderBookSearchTable, renderBookSend, renderEbookList, renderItemSend, renderNarrators, renderReleasesTable, renderRecommendTable, renderSabStatus, renderSearchDiscord, renderSearchTable, renderTrendingDiscord, renderTrendingTable, toJson, } from './format.js';
12
+ import { renderAddTable, renderBookAdd, renderBookBest, renderAudiobookList, renderBookGrab, renderBookReady, renderBookSearchTable, renderBookSend, renderEbookList, renderItemSend, renderNarrators, 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();
@@ -341,6 +341,7 @@ Actions:
341
341
  ready <chaptarrId> Whether the book has a file and, for an ebook, is in Audiobookshelf.
342
342
  send <chaptarrId> <device> Email the ebook to a Kindle through Audiobookshelf.
343
343
  ebooks List every ebook in Audiobookshelf, newest first, with the Kindles.
344
+ audiobooks List every audiobook in Audiobookshelf, newest first.
344
345
  send-item <itemId> <device> Email one Audiobookshelf ebook item to a Kindle.`);
345
346
  books
346
347
  .command('search')
@@ -646,6 +647,29 @@ Examples:
646
647
  fail(err);
647
648
  }
648
649
  });
650
+ books
651
+ .command('audiobooks')
652
+ .description('list every audiobook in Audiobookshelf, newest first')
653
+ .option('--json', 'output JSON')
654
+ .addHelpText('after', `
655
+ Behavior: reads the items with audio files of every Audiobookshelf book library, including
656
+ audiobooks Chaptarr does not manage. Changes nothing.
657
+
658
+ Output (--json): { "audiobooks": AudiobookItem[] }
659
+ AudiobookItem: { item_id, title, author, narrator, duration_seconds, added_at }
660
+
661
+ Examples:
662
+ trendarr books audiobooks --json`)
663
+ .action(async (opts) => {
664
+ try {
665
+ const { output, warnings } = await listAudiobooks(loadConfig());
666
+ printWarnings(warnings);
667
+ process.stdout.write(`${opts.json === true ? toJson(output) : renderAudiobookList(output)}\n`);
668
+ }
669
+ catch (err) {
670
+ fail(err);
671
+ }
672
+ });
649
673
  books
650
674
  .command('send-item')
651
675
  .description('email one Audiobookshelf ebook item to a Kindle')
@@ -12,7 +12,11 @@ const itemsSchema = z.object({
12
12
  media: z
13
13
  .object({
14
14
  ebookFormat: z.string().nullish(),
15
- metadata: z.object({ title: z.string().nullish(), authorName: z.string().nullish() }).nullish(),
15
+ numAudioFiles: z.number().nullish(),
16
+ duration: z.number().nullish(),
17
+ metadata: z
18
+ .object({ title: z.string().nullish(), authorName: z.string().nullish(), narratorName: z.string().nullish() })
19
+ .nullish(),
16
20
  })
17
21
  .nullish(),
18
22
  })),
@@ -40,8 +44,11 @@ export class AudiobookshelfClient {
40
44
  id: i.id,
41
45
  path: i.path,
42
46
  ebookFormat: i.media?.ebookFormat ?? null,
47
+ audioFiles: i.media?.numAudioFiles ?? 0,
48
+ durationSeconds: i.media?.duration != null && i.media.duration > 0 ? i.media.duration : null,
43
49
  title: i.media?.metadata?.title ?? null,
44
50
  author: i.media?.metadata?.authorName ?? null,
51
+ narrator: i.media?.metadata?.narratorName || null,
45
52
  addedAt: i.addedAt ?? null,
46
53
  }));
47
54
  }
@@ -615,6 +615,29 @@ export async function listEbooks(config) {
615
615
  const ebooks = found.sort((a, b) => b.addedAt - a.addedAt).map((f) => f.item);
616
616
  return { output: { ebooks, kindles: await abs.ereaderDevices() }, warnings: [] };
617
617
  }
618
+ export async function listAudiobooks(config) {
619
+ const abs = audiobookshelf(config);
620
+ const found = [];
621
+ for (const library of (await abs.libraries()).filter((l) => l.mediaType === 'book')) {
622
+ for (const i of await abs.items(library.id)) {
623
+ if (i.audioFiles === 0)
624
+ continue;
625
+ const added_at = i.addedAt === null ? null : new Date(i.addedAt).toISOString();
626
+ found.push({
627
+ item: {
628
+ item_id: i.id,
629
+ title: i.title ?? i.path,
630
+ author: i.author,
631
+ narrator: i.narrator,
632
+ duration_seconds: i.durationSeconds === null ? null : Math.round(i.durationSeconds),
633
+ added_at,
634
+ },
635
+ addedAt: i.addedAt ?? 0,
636
+ });
637
+ }
638
+ }
639
+ return { output: { audiobooks: found.sort((a, b) => b.addedAt - a.addedAt).map((f) => f.item) }, warnings: [] };
640
+ }
618
641
  export async function sendItem(config, itemId, device) {
619
642
  const abs = audiobookshelf(config);
620
643
  const base = { item_id: itemId, device };
package/dist/format.js CHANGED
@@ -184,6 +184,13 @@ export function renderEbookList(output) {
184
184
  const kindles = output.kindles.length === 0 ? 'Kindles: none' : `Kindles: ${output.kindles.join(', ')}`;
185
185
  return [pc.bold(header), ...rows, '', kindles].join('\n');
186
186
  }
187
+ export function renderAudiobookList(output) {
188
+ if (output.audiobooks.length === 0)
189
+ return 'No audiobooks.';
190
+ const header = `${cell('TITLE', 40)} ${cell('AUTHOR', 22)} ${cell('NARRATOR', 22)} ${cell('LENGTH', 8)} ADDED`;
191
+ const rows = output.audiobooks.map((a) => `${cell(a.title, 40)} ${cell(dash(a.author), 22)} ${cell(dash(a.narrator), 22)} ${cell(hours(a.duration_seconds), 8)} ${a.added_at?.slice(0, 10) ?? '-'}`);
192
+ return [pc.bold(header), ...rows].join('\n');
193
+ }
187
194
  export function renderItemSend(output) {
188
195
  const detail = output.detail === null ? '' : ` (${output.detail})`;
189
196
  return `${output.item_id} → ${output.device}: ${statusColor(output.status, ['sent'])}${detail}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/trendarr",
3
- "version": "0.14.0",
3
+ "version": "0.15.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",