E-Book Converter Bot

Telegram Badge

Open Source Love made-with-python

PayPal Patreon Liberapay

A bot that converts e-books to various formats, powered by calibre! It currently supports 34 input formats and 19 output formats.

You can start using it or adding it to your group here on Telegram.

About the code:

This project is a modular bot, made using Python 3 and the following:

Bot features:

This bot aims to provide an easy way for telegram users to convert e-books from and to different formats.

It supports converting from the following formats:

['azw', 'azw3', 'azw4', 'azw8', 'cb7', 'cbc', 'cbr', 'cbz', 'chm', 'djvu', 'docx',
 'doc', 'epub', 'fb2', 'fbz', 'html', 'htmlz', 'kfx', 'kfx-zip', 'kpf', 'lit',
 'lrf', 'mobi', 'odt', 'opf', 'pdb', 'pml', 'prc', 'rb', 'rtf', 'snb', 'tcr',
 'txt', 'txtz']

To the following formats:

['azw3', 'docx', 'epub', 'fb2', 'htmlz', 'kfx', 'lit', 'lrf', 'mobi', 'oeb',
 'pdb', 'pmlz', 'rb', 'rtf', 'snb', 'tcr', 'txt', 'txtz', 'zip']

Some more features of the bot:

  • Force book direction to be RTL
  • Multilingual support, you can contribute and add your own languages if you want :).

Usage

  • Forward any supported file to the bot and choose the required format to convert to, and in few seconds the bot will reply you with the converted file.
  • The bot works in groups too. Reply with /convert to any file then do the same steps as in private.
  • You can change the preferences of the bot such as language using /settings or /preferences commands.

Before setting up the bot

  • Copy config.json.example file to config.json and fill the required information:

    {
      "tg_bot_token": "11111111:xxxxxxxxxxxxxxxxxx",
      "tg_bot_id": 111111111,
      "api_key": 1121221,
      "api_hash": "xxxxxxxxxxxxxxxxxxxx",
      "tg_bot_admins": [
        2222222
      ]
    }
  • Compile the translation files using the following command:

    make i18n-compile 

Setting up the bot

Before all, clone this repository.

Using Docker

  • Simply, run the following command:

docker-compose up --build -d

Without Docker [NOT RECOMMENDED]

Python dependencies

It requires Python 3.7 with pip v19+ installed or poetry if you use it.

Clone the repository and run any of the following commands:

Using poetry

poetry install

Using Pip

pip install .

Database

The bot depends on sqlite database. Make sure that your system has it installed.

Other requirements

You can go through the Dockerfile to see how the bot requirements are being installed.

  • The conversion process is done by utilizing Calibre and its ebook-convert, so make sure you have it installed.
  • To convert from and to KFX, you need to install KFX Input and KFX Output plugins in calibre, this can be done from the command line by using the following commands:

    # KFX Input
    wget https://plugins.calibre-ebook.com/291290.zip 
    calibre-customize -a 291290.zip
    # KFX Output
    wget https://plugins.calibre-ebook.com/272407.zip
    calibre-customize -a 272407.zip
  • Also, KFX Output plugin requires Kindle Previewer 3, which can run on linux under Wine.

Running the bot

If you finally managed to get all pieces in its place without using docker, run the bot using:

python3 -m ebook_converter_bot

Internationalization (i18n)

The bot uses gettext for internationalization and makefile for running i18n tasks easily.

  • First, generate .pot template using make i18n-generate-messages.
  • Update the current translation files using make i18n-merge, then edit the translation strings.
  • Compile the translation files using make i18n-compile.

To add a new language to the bot, run the following command (change ‘ar’ to your language code) then edit the new language file with translation and compile.

LANG=ar make i18n-init-lang

GitHub

https://github.com/yshalsager/ebook-converter-bot