Sunday, January 3, 2021

E-Books and DeDRM on Ubuntu

 So, my son got me an eBook from eBook.com.  First, I just tried the simplest approach.  Install their official app from Google Play and read it there.  The app is crude but it seemed to work.  Until I changed the font to bigger using the preferences menu. Once, I did this, I noticed the tops and/or bottoms of pages were lost.  If I could slide the page up down a bit to read the missing text, I'd live with it.  But no.  No such feature in the eBooks.com app.  

I wasn't going to guess 1-2 lines of text on each page.  So, it was time to DeDRM the ebook and read it in the Android app that I use usually - Moon Reader.  After all, it's geal in US to remove DRM from an file you legally own.

And here we go.  Oh, I use Linux for the last 2-3 years unless I really have to boot into my old WinXP, Ubuntu 18.04 to be precise. 

Install Wine, ADO and download the eBook

  1. Wine, I installed using the Ubuntu application management UI:


  2.  It installed for me version "wine-3.0"
  3. That was my first contact with Wine.  How do I use it?  I has no UI.  I found that it is quite reliable for some applications.  Here're couple pointers:
    • In the folder ~/.wine (it can be configred to something else, you can have even multiple ones - I just used the default). it creates a whole Windows-like file system.  Look inside the drive-c folder.  Every application installed, is copied to Program Files folder below there.
    • There is winecfg app for configuration and wine uninstaller for, you know, uninstalling applications (command: wine uninstaller).
    • To install from an .msi file, use command: wine msiexec /i msi-file-name
    • To install an application from an installer exe use command: wine installer-file-name.  Once it ran fine, find the executable for the application in Program Files and run a command: wine application-executable-file-name.
  4. For a test, I installed Notepad++ first.  It worked fine.
  5. Then to Adobe Digital Edition.  eBooks.com site provide a link to its installer file.  It installed fine using the tips for wine I have shown above.  It was ADO ver. 1.7 (trying to install ADO ver. 2.0 was unsuccessful - it needs .Net frmework which didn't install via Wine successfully).
  6. I have found the ADO executable in the Wine's Program Files and started it.
  7. The ADO upon first start asked me to register it with Adobe ID which I did.  Just as usually.  
  8. Now, while keeping the ADO running, I requested eBooks.com website to download my eBook.  The only thing I got was an .acm file.  That download didn't trigger any action from the ADO side, as it does on Windows if I remember correctly.  Why?
  9. However, when I requested the .acm file to be opened with a text editot through Ubuntu Files application, ADO woke up and started downloading the eBook.  Hooray!  Although, I don't like magic as it doesn't leave pointers when it doesn't work.
At this point, I was able to read the book on my laptop.  First goal achieved.  However, I don't read books on my laptop.  I need to have them on my Android phone.  So, I needed to remove the DRM from the epub file (I have found it in My Documents/My Digital Editions).

Making Calibre Plugin DeDRM Work

I've used Calibre and its DeDRM plugin before successfully but it was on Windows.  On Linux, it was the first time for me.  Here, we go again:
  1. Installed Calibre using Ubuntu application manager.  It installed version 3.2.1.
  2. From the Apprentice Alf's Blog, download the DeDRM plugin (I chose version 6.8.1 - the most recent version 7+ is for new version of Calibre).  Unpack once.
  3. From the Calibre preferences, choose Plugins and Load from File, choose the DeDRM_plugin.zip (it showed as version 6.8.0).
  4. Now, I restarted Calibre and added the epub to the Calibre collection at which the DeDRM should trigger behind the scene and do its job.  But, it didn't.  When I tried to open the book, I've got the DRM error explaining the book is protected and can't be read.
  5. Now, something was wrong with the DeDRM.  I removed the book from the collection, restarted Calibre in debug mode (see Preferences menu) and retried adding the book.  Immediately after that, I closed Calibre.  When closing, it showed the log file.  
  6. From the log file, I found that DeDRM is trying to run Python using Wine.  I had Python installed on my Ubuntu but it wasn't found.  I need to install it on Wine.
  7. I found version 2.7 installer from Python website and installed with Wine.
  8. Next attempt to DeDRM showed some changes in the debug log.  This time, DeDRM complained it couldn't find PyCrypto package.
  9. Installing this package via command wine pip install pycrypto wasn't successful. But from this website, I found a compiled pycrypto as an exec file (Used the 2.6.1 version with sha512sum since for the asc signature, I wasn't able to find the right public key).  Command wine pycrypto-2.1.0.win32-py2.7.exe did the trick just fine.
At this point, repeating the attempt to add the book to Calibre worked fine.  I could read the book in Calibre.  Then, from the right book details panel that showed the format EPUB, I right clicked on the EPUB link and chose Save as File on Disk.  Select the folder and the books was saved into that folder as a DRM-free epub file.  

Now, transferred the file onto my phone and I can read it complete, the book purchased from eBooks.com.