All Projects → xyfir → node-calibre

xyfir / node-calibre

Licence: MIT license
📖 A Node wrapper for Calibre's command line tools.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to node-calibre

Calibre
The official source code repository for the calibre ebook manager
Stars: ✭ 11,221 (+53333.33%)
Mutual labels:  calibre, ebooks
kobo-book-downloader
A tool to download and remove DRM from your purchased Kobo.com ebooks and audiobooks.
Stars: ✭ 171 (+714.29%)
Mutual labels:  calibre, ebooks
CalibreLibgenStore
A Libgen Fiction store plugin for Calibre
Stars: ✭ 117 (+457.14%)
Mutual labels:  calibre
LibGenesis
An API workaround the library genesis platform to enable query search
Stars: ✭ 46 (+119.05%)
Mutual labels:  ebooks
build-calibre
Build the calibre installers, including all dependencies from scratch
Stars: ✭ 29 (+38.1%)
Mutual labels:  calibre
calibre-kindle-comics
A calibre plugin that converts your comics into a readable format for kindle.
Stars: ✭ 32 (+52.38%)
Mutual labels:  calibre
calibre-docker
docker 一键部署 calibre 在线书库
Stars: ✭ 15 (-28.57%)
Mutual labels:  calibre
Open Publisher
Using Jekyll to create outputs that can be used as Pandoc inputs. In short - input markdown, output mobi, epub, pdf, and print-ready pdf. With a focus on fiction.
Stars: ✭ 242 (+1052.38%)
Mutual labels:  ebooks
doujinshi metadata plugins
the calibre metadata plugins for doujinshi
Stars: ✭ 55 (+161.9%)
Mutual labels:  calibre
douban-book-api
第三方豆瓣读书 api 接口
Stars: ✭ 44 (+109.52%)
Mutual labels:  calibre
Safaribooks
Download and generate EPUB of your favorite books from O'Reilly Learning (aka Safari Books Online) library.
Stars: ✭ 3,208 (+15176.19%)
Mutual labels:  calibre
acsm-calibre-plugin
Calibre plugin for ACSM->EPUB and ACSM->PDF conversion.
Stars: ✭ 118 (+461.9%)
Mutual labels:  calibre
biblioteca-guerrilla
Simple static website generator to share books 🕮
Stars: ✭ 15 (-28.57%)
Mutual labels:  calibre
Calibre Web
📚 Web app for browsing, reading and downloading eBooks stored in a Calibre database
Stars: ✭ 5,616 (+26642.86%)
Mutual labels:  calibre
advanced-php-crawler
新浪博客文章/wenku8轻小说文库爬虫,可抓取图片保存,一键制作电子书。kindle读书党的神器!
Stars: ✭ 26 (+23.81%)
Mutual labels:  calibre
unpaprd
An audiobook 🎧 📔 app made using Flutter
Stars: ✭ 73 (+247.62%)
Mutual labels:  ebooks
ebook-converter-bot
Convert ebooks with few clicks on Telegram!
Stars: ✭ 47 (+123.81%)
Mutual labels:  calibre
ebook-converter
Commandline tool for converting between several e-books formats, based on Calibre project.
Stars: ✭ 21 (+0%)
Mutual labels:  calibre
bookwyrm
ncurses utility for downloading publicly available ebooks, plugin support
Stars: ✭ 31 (+47.62%)
Mutual labels:  ebooks
anyfesto
Low cost Raspberry Pi /Linux based access point with audio, education and communications local content server. Inspired by the ideas of sharing with others. Anyfesto - a platform from which to speak.
Stars: ✭ 66 (+214.29%)
Mutual labels:  calibre

A simple Node wrapper for Calibre's command line tools.

Built and maintained by the Xyfir Network.

node-calibre is mostly a simple wrapper around Calibre's CLI using Node's child_process.exec(), without many extra features added. In the future this package will contain more methods unique to each of Calibre's binaries and with both better error checking and improved results provided on success.

Examples

import { Calibre } from 'node-calibre';

// Create Calibre instance
const calibre = new Calibre({ library: '/path/to/calibre/library' });

// Convert ebook from pdf to epub
const newFile = await calibre.ebookConvert('/path/to/book.pdf', 'epub', {
  epubFlatten: null
});
console.log(newFile); // "/path/to/book.pdf.epub"

let result: string;

// Add book to Calibre library
result = await calibre.run('calibredb add', ['/path/to/book.epub']);
console.log(result); // "Added book ids: ..."

// List books in Calibre Library
result = await calibre.run('calibredb list', [], { limit: 10 });
console.log(result); // first 10 books

// You can optionally pass `options` as the second parameter
// `forMachine: null` gets converted to `--for-machine`
result = await calibre.run('calibredb list', {
  limit: 10,
  forMachine: null
});
console.log(Array.isArray(JSON.parse(result))); // true

API

constructor(options)

  • options.library: string - optional, default ''
    • Full path to the Calibre library to work with.
    • Only needed if the commands this instance will run will use any of the calibredb commands.
    • The path will be used as the value for the --library-path option for calibredb commands.
  • options.log: boolean - optional, default false
    • If true, the command string that is run by Node's child_process.exec() is logged to console before running.
  • options.execOptions: object - optional, default {maxBuffer: 2048000}
    • The object passed to Node's child_process.exec() as the options argument.

run(command[, args][, options])

Runs a command on one of Calibre's binaries (calibredb, ebook-convert, etc). Find all here.

  • command: string
    • The name of the bin and command to run. For example 'calibredb add' or 'ebook-convert'.
  • args: any[] - optional, default []
    • An array of arguments that the command will accept.
    • All arguments are converted to strings, wrapped in "", and escaped.
  • options: object - optional, default {}
    • A key:value object containing options that the command will accept.
    • All values (but not keys) are wrapped in "" and escaped.
    • If you want to pass on option that doesn't take a value, set the value to null: {'some-option': null}.
    • You can also use camelCase keys and they'll be converted to kebab-case: {forMachine: null} -> --for-machine.
    • If an option can be used multiple times (like --field in calibredb set_metadata), you can pass an array with all of the values: {field: ['tags:tag1,tag2', 'title:Some New Title']} -> --field "tags:tag1,tag2" --field "title:Some New Title".

Return

A promise that is rejected if the callback of Node's child_process.exec() has a value for error or stderr and resolves to the callback's stdout if no error occurred. Due to how Calibre's command line tools work, most of the time the promise should resolve regardless of whether Calibre encountered an issue. It's up to you to check the resolved result to determine if the command was successful.

ebookConvert(input, format, options)

Wrapper for ebook-convert.

  • input: string
    • Path to the input file to convert.
  • format: string
    • The format (file extension) to convert input to.
  • options: object
    • Any CLI options for the ebook-convert command.

Return

Full path to the new file.

exec(command[, options])

This method should only be used if for some reason you need to build your own command string. It's essentially just a Promise-wrapped child_process.exec() that gets passed the execOptions from the constructor.

  • command: string
    • The full command that you want to run.
    • For example: calibredb list --for-machine --limit 10.
  • options: object
    • Will be merged with the execOptions object that was passed to the constructor.
    • Properties passed will override properties with the same name from execOptions.

Return

Same as run(), which builds a command string and passes it to exec().

Notes

  • You should be aware of the maxBuffer property of the options object accepted by Node's child_process.exec(). It limits the size of output that can be received from a process, in this case one of Calibre's binaries. Unless you set maxBuffer as a property in the execOptions object, the maximum buffer size will be increased from the default of 200KB to 2MB. The vast majority of commands will get nowhere near this number, however certain commands like calibredb list with all fields requested on a large library can get close or even surpass that limit in certain cases. If a command's output exceeds the maxBuffer limit, an error will be thrown.
  • You can safely pass use input as a value in the args array and options object of run(), but not as a command or an option name. In other words, args and option values are are wrapped in double quotes and escaped.
  • This package does not install Calibre. You must have Calibre already installed and either have Calibre's bin directory in your system's PATH or use the cwd property of execOptions (see constructor options) to set Calibre's bin directory.
  • Calibre v3 is recommended, but lower versions will most likely work.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].