Calibre DRM Removal for Ebooks on Linux - Linux Tutorials - Learn Linux Configuration

Objective

Install Calibre and use it to remove ebook DRM.

Distributions

This will work on any Linux distribution.

Requirements

A working Linux install with root privileges.

Conventions

  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user

Introduction

DRM sucks. There, now that that’s out of the way, you can focus on getting rid of it from all of your ebooks. It’s pretty hard to deny that DRM has a negative impact on ebooks. You can’t share them. You can’t use them across devices. In short, it prevents you from using your legally purchased property the way you want.

Calibre is one of the best ebook tools out there. It’s much more than a reader and a library. Calibre even helps you author your own ebooks. In addition to all that, it lets you remove DRM and convert your ebooks between formats. Think of it like a cross between Kodi and Handbrake, but for ebooks.

Install Calibre

Start off by installing Calibre. It’s a popular open source program, so you’ll find it in most repositories.

Ubuntu/Debian

$ sudo apt install calibre

Fedora

# dnf install calibre

OpenSUSE

# zypper in calibre

Arch

# pacman -S calibre

Install The Plugin

Fresh Calibre Install

Calibre doesn’t come with the capability to remove DRM out of the box. That comes from a plugin, and you’re going to need to install it. Download the latest release of the plugin from the developer’s Github page, and unzip it. There will be several folders, but the one you need is obviously the Calibre one.

Calibre Preferences

Open up Calibre. The screen should look pretty empty at first. On the main menu, click on the preferences icon. From there, locate and click the plugins icon under the “Advanced” heading.

Calibre Plugins

At the very bottom of the plugins window, you’ll see a button that lets you import a plugin from a file. Click on that. Browse to the Calibre plugin folder that you extracted from the .zip. Select the .zip within that folder. Calibre will warn you that importing an external plugin is a potential security risk. Confirm your choice. Afterward, Calibre will show you a success message telling you to restart the program for the changes to take effect. Do that.

Calibre Plugin Installed

Remove The DRM

The plugin removes DRM automatically when an ebook is added to your library. That’s actually the only time that it works, so if you have ebooks already in your library(you shouldn’t) that have DRM, you’ll need to remove them and import them again.

Try it out. Find an ebook that has DRM. Click on the “Add Book” button in Calibre and browse to your book. Import it. You should be able to open up your newly imported book in the Calibre viewer. Click on your book in the library list to highlight it. Then, click the “View” button on the main menu. Your previously DRM’d book will open up in a new window for viewing. The DRM is gone, and the book is free to use however you choose.

If you want to get more creative with it, click on the “Convert books” button. You can select from a variety of output formats. By letting you convert your now-unencumbered book to different formats, it’s much easier to use your ebook on just about any device.

Closing Thoughts

It’s fairly easy to set Calibre up to automatically rip all of the DRM out of your ebook library and put the control back in your hands. Remember that Calibre can also be your ebook library on your Linux desktop. It’s actually great for that. Then, you can use it to export your books in whichever format works best for your mobile devices.


This is a companion discussion topic for the original entry at https://linuxconfig.org/calibre-drm-removal-for-ebooks-on-linux

For me, installing and using Calibre on Linux wasn’t that simple. To actually be able to remove DRM, the plugin needs the user’s keys for the respective DRM platform. To be able to remove Adobe DRM from epub books, either Adobe Digital Editions, a Windows application, must be installed through Wine and DeDRM must point to the correct wineprefix path (which sometimes might be found automatically by the plugin, sometimes not, depending on how you use Wine), or those keys must be imported manually from somewhere. The procedure is similar for Kindle e-books, but even slightly more tricky, since it involves using an older Kindle for Windows application which has to be configured to not automatically update.

I’m having alot of difficulty with this. After many hours I was finally able to install ADE using winetricks (was impossible with just Wine) . Then in the final step in calibre, trying to customize the plugin, and it asks for the Wineprefix, nothing is working. I found some discussion online and it suggests “~/.local/share/wineprefixes/adobe_diged”, so I tried that but it doesn’t work, nor another suggestion on that page: “In WINEPREFIX put in /home/YOURUSERNAME/.adewine” . Whatever I enter for the wineprefix it just says “The Default encryption key for Adobe Digital editions could not be found”. So I’m giving up for now after struggling with this all night…

Have you managed to add the encryption key? I’m having the same problem, and I would need some help with this.

I came across this thread and wanted to add the steps that I had to follow to get DeDRM working on Linux using Wine.

  1. Install Adobe Digital Editions. I followed instructions I found in a Reddit thread (sorry, I can’t post the link) called installing_adobe_digital_editions_wine These instructions are for Arch Linux, so for Ubuntu the exact commands will be different, but the key is you need wine, winetricks, samba, and lib32-gnutils.
  2. After you install ADE, open it and activate your computer.
  3. Download and install Python 2.7 (32-bit) and PyCrypto using Wine, e.g.:
    WINEPREFIX="$HOME/.wine32" wine msiexec /i ~/Downloads/python-2.7.18.msi
    WINEPREFIX="$HOME/.wine32" wine ~/Downloads/pycrypto-2.6.win32-py2.7.exe
  4. In Calibre, install DeDRM and configure it. Set the WINEPREFIX to whatever you used (in my case, you can see it was /home/username/.wine32… if you used /home/yourusername/.adewine then you should use this, it’s totally dependent on how you installed ADE!)

This worked for me… if it doesn’t work for you I suggest running Calibre from the command line, you’ll be able to see the errors that DeDRM throws when it tries to decrypt your ADE activation key

Like rainbowgoblin, I came across this thread and wanted to post some updated instructions that worked for me when using Calibre v5.12 and version 7.1.0 of the DeDRM plugin (as earlier versions of DeDRM don’t work with Calibre v5).

  • Install Adobe Digital Edition (ADE) through Wine, by following the instructions in the Reddit post referred to by rainbowgoblin above. I installed version 4.5.11, so that is what these instructions are tailored for. Some posts online suggest that it is a better idea to download ADE version 2 or 3 as those versions apparently use a more easily removed form of DRM.

For the rest of the steps I’ll assume your WINEPREFIX is “$HOME/.wine32”.

  • ADE should open automatically upon installing it; if not, you should find it somewhere like “$WINEPREFIX/drive_c/Program Files/Adobe/Adobe Digital Edition 4.5”.

  • Open ADE and authenticate your computer. If you have an ACSM file (called “URLLink.acsm” or similar), rather than an EPUB, click File > Add to Library and open the ACSM file.

  • Next, install Python 3 and pyOpenSSL under Wine. Download a Python 3 installer from the Python website. Choose a 32-bit .exe installer and be sure to choose a sub-version that works with the version of Windows your Wine is configured to run as (for example, if Wine runs as Windows 7, 3.9 won’t work). Run WINEPREFIX="$HOME/.wine32" wine cmd /c "[path to python installer .exe]" and follow the install process. Make sure pip is installed too (it should be by default). Then run WINEPREFIX="$HOME/.wine32" wine cmd /c py -m pip install pyopenssl to install pyOpenSSL.

This should put a file called “libcrypto-1_1.dll” or similar into your Python DLLs directory in your Wine directory. For me, this was “$WINEPREFIX/drive_c/users/[username]/Local Settings/Application Data/Programs/Python/Python38-32/DLLs/”.

  • Get release 7.1.0 of the Calibre DeDRM plugin by downloading the zip file from the GitHub Releases page. Unzipping the file you have downloaded will extract a number of other zip files, including “DeDRM_plugin.zip”.

  • In Calibre, go to Preferences > Plugins > Load plugin from file, and select the DeDRM_plugin.zip file referred to above. Once installed, you’ll need to configure it with a key. The plugin will attempt to find this key for you using a Python script, but I had to tweak it slightly to get it to work. I found the script at $HOME/.config/calibre/plugins/DeDRM/libraryfiles/adobekey.py.

On or about line 119 of the adobekey.py script, there is a line libcrypto = find_library("libeay32"). This doesn’t seem to work under Wine (at least, it didn’t for me) so comment the line out and include another line directly after it setting the “libcrypto” variable to the absolute path to your librcrypto DLL file. Note that you have to use the Windows convention here, with (escaped) backslashes and using “C:” at the beginning instead of $WINEPREFIX/drive_c. So for me, the line I had to include was: libcrypto = 'C:\\users\\[username]\\Local Settings\\Application Data\\Programs\\Python\\Python38-32\\DLLs\\libcrypto-1_1.dll'.

  • Back in Calibre, go to Preferences > Plugins and locate the DeDRM plugin (eg, by searching for “drm”) and click “Customize plugin”. Select “Adobe Digital Editions ebooks”. In the dialog box that pops up, enter the absolute path of your WINEPREFIX in the relevant field (eg, “/home/[username]/.wine32”) and click on the green “+”. With a bit of luck DeDRM will find a key and ask you to name it. If you get an error about not being able to find default keys, it may help to run Calibre from a terminal so you can see what errors the Python script is reporting, as suggested above.

  • Once the key has been added, click “Apply” in the Plugins configuration dialog and add your DRM’d ebook. The plugin should automatically remove the DRM when it is added to Calibre.

2 Likes

The only reason I created this account is to thanks Feisty. Lifesaver.

1 Like

Thank you so much for these instructions! They helped me get to where I could finally import my ADE key.

In my case*, I had to install the Python module pycryptodome instead of libcrypto and didn’t have to make any changes to adobekey.py.

*Linux Mint 20.3 Cinnamon, Calibre 6.2.1, DeDRM 10.0.3 (NoDRM’s fork)