lördag 11 mars 2017

E-books in Linux with Adobe Digital Editions

I've read a lot of e-books. And since I use Linux devices, it is sometimes a bit problematic. How do you read e-books that you have bought in Linux?

One way is to read public domain and free e-books. There are a lot, just search for them on the Internet. But they are mostly old books. Some writers actually publish some of their books explicitly without DRM. I like those writers. Then it is easy to transfer the book to any of your devices.

There are many e-book readers on linux. I like Calibre and Fbreader. Calibre for managing and converting ebooks and also reading on the PC, and fbreader for reading on smaller devices, like my linux phone and tablet.

The DRM-equipped e-books that I have bought are all the Adobe DRM type that have to be read in Linux using Adobe Digital Edition (ADE) using wine. So far the old 1.7 ADE version has been sufficient. The good thing with that version is that it just works. No runtime installation in wine or nothing, just install and fire it up in wine.

But when I bought the last e-book, I couldn't download the book anymore using ADE. It just timed out and said that it couldn't download the book due to an error. So I began looking at newer versions of ADE.

The problem with the later versions of ADE is that they require .NET Framework 3.5 SP1, also the 1.8 pre-release version. So far I've tried the 1.8 pre-release, 2.0 and 3.0. At least the ADE 3.0 version was successfully installed and now works without problems.

Here are the steps to install ADE in wine.

It is good to start with a clean wine prefix. If you are familiar with wine, you know that wine stores the Windows environment in a directory called a wine prefix. By default this is a hidden directory in your home named .wine. You can create as many separate wine prefixes as you want, but then you need to launch them explicitly with:

 WINEPREFIX="path/to/directory" wine <program to launch>

otherwise it just uses the default .wine directory. There are entire programs for managing your wineprefixes and windows programs, e.g. PlayOnLinux comes to mind.

Anyway, to get the .NET Framework installed, the following is recommended:

 mv .wine .wine_old
Exit winecfg. Now you have a clean wine prefix. Download the winetricks script. This is a helper script to install runtimes in the wine Windows environment.

wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks
Now you can either start winetricks with ./winetricks and there is a GUI that you can use to install runtimes. But in this case it is preferred to just run:

./winetricks dotnet35sp1
 This will automatically download all .NET runtimes in the 2.0 to 3.5sp1 range and install them. Beware that it is several hundred megabytes and takes many minutes. Sometimes the installation fails, and you just have to start over again by deleting the .wine directory. You have to click through some of the .NET dialogs. Be patient, at some point the installation seems to stall, but continues in a few minutes.

I think it depends on the wine version, but there is a .NET component that causes problems, at least for me. When running an application through wine I always got a message that "mscorsvw.exe" crasched. At some point this executable just hanged and ate a lot of CPU. The solution was to start winecfg and add the problematic component to the Libraries page. Enter mscorsvw.exe in the topmost field and click Add. It should have native as the first option. Now it doesn't crash anymore.

You also have to install a second component in wine:
./winetricks windowscodecs
Now download the ADE 3.0 installer from https://www.adobe.com/support/digitaleditions/downloads.html. Install it with:

 wine ADE_3.0_Installer.exe
Now you should be able to launch ADE (the shortcut should be available also in your desktop start menu). I noticed that the window sometimes didn't refresh, but it wasn't a big problem. Enter your existing Adobe account or create a new one. Note that you have to use the same account to read your existing ebooks. Now you can download ebooks from online stores and it will automatically download and put them in your ~/Documents/My Digital Editions directory in Linux.

If you need to try several versions and they clutter up your wine prefix, just uninstall them with:

wine .wine/drive_c/Program\ Files/Adobe/Adobe\ Digital\ Editions\ 3.0/uninstall.exe
The shortcuts can be removed by e.g.

rm -rf .local/share/applications/wine/Programs/Adobe/Adobe\ Digital\ Editions\ 3.0
 And about that DRM and other devices? Well, lets keep it for another article...