Removing DRM from Kindle books

From Stack Overflow
Jump to: navigation, search

The following is a mirror of http://nyquil.org/archives/1128-Converting-Kindle-Books-a-painful-process-that-works-for-reading-Kindle-books-without-a-Kindle.html. The text belongs to the original author and is not my research or work. I am merely mirroring it here in case the original site goes down. Although I have purchased a Kindle, I have not yet received it (backorder'd!), so cannot verify that the following instructions even work, but they appear to be sound.

Converting Kindle Books: a painful process that works for reading Kindle books without a Kindle


D recently bought one of those new-fangled Amazon Kindle thingies for purchasing and reading books in an electronic form. (She loves it.)


I like to read books in an electronic form on my iPhone, but find that it’s pretty hard to come by them legally; there are many different sellers and formats, some of which have certain books but not others. Sometimes they have the book, but not in a format I can do anything with. It’s generally easier just to illegally download them from torrent sites.


Amazon has tons and tons of books available for Kindle, and have chosen the standard MobiPocket format as the one their reader uses, meaning it is theoretically trivial to purchase them and convert them to something else. Except that they won’t sell them to you unless you have already purchased a $400ish Kindle on which to read them. Meaning you don’t need to convert them…


In any case, now that our household has a Kindle, it frees me up to purchase books from Amazon in Kindle format without actually having a Kindle myself. I then just remove the DRM that Amazon puts in the files (to keep people from converting them, natch), and then convert them to HTML or txt to read in Books.app on iPhone. Want to know how to do the same thing?


Howto:


Step 1) Find someone with a Kindle.


Step 2) On their Kindle, go to the Settings menu, and type ‘411’ on the keypad. This will bring up a little information dialog with a bunch of things in it, of which you only need the Serial. It is a 16-character string of letters and numbers. Write it down.


Step 3) Ask the Kindle’s owner to buy a book for you. Give them some money so you don’t look like a mooch. Once you’ve given them the money, ask them to log in to their Amazon account and navigate to their ‘Kindle Downloads‘ page from your computer. When they complain, mention that you’ve already given them money. The Kindle Downloads page will list all the books they’ve purchased, and yours should be right at the top. Click ‘Download to computer’ and you’ll get a file named ‘Title-of-Book.azw’


Step 4) Download MobiDeDRM.zip, which is a small suite of Python scripts that some kind soul wrote and then distributed through links that expire all the time and can be kind of a pain to track down. I’ve hosted them from my site so that they won’t expire. This .zip file contains mobidedrm.py, mobidedrm2.py, kindlepid.py and mobihuff.py.


(These scripts require that you install Python on your system, which is something outsite the scope of this howto. I’m on linux, but there’s a Python for Windows called “ActiveState Python.” Google will help.)


After unzipping the archive, open up a terminal window and pass the Kindle’s serial # (which you previously wrote down) to kindlepid.py. Something like this:


python kindlepid.py XXXXXXXXXXXXXXXX


Where all those Xs are replaced with the Kindle serial number. It will return something that looks like this:


Mobipocked PID for Kindle serial# XXXXXXXXXXXXXXXX is Z1QFCDQ*74


Make note of that last 10-character gibberish. That’s the secret code (or PID) we’ll need to remove the DRM from any books purchased for that Kindle.


Step 5) Now it’s time to remove the DRM. Do this:


python mobidedrm.py Title-of-Book.azw Title-of-Book.mobi Z1QFCDQ*74


where my 10-character gibberish string is replaced with the one you made note of in the last step. This will take about a minute, and when it finishes you’ll see:


Decrypting. Please wait... done


Now you will have a decrypted MobiPocket-formatted ebook that you can read in any MobiPocket reader.


If, however, you want to convert it to HTML to read on any device you wish, you’ll want to install MobiPerl. (This, of course, will require you to install Perl. MobiPerl’s website will walk you through that.)


6) With MobiPerl installed, do this:


mobi2html Title-of-Book.mobi


This will create a directory named ‘unpacked’ that will contain Title-of-Book.html


Things that can go wrong:


Amazon seems to compress longer books in a slightly different manner than shorter books. If your resulting .mobi file and/or .html file are oddly gibberishy (for example, if the first line starts in the middle of a sentence, and clearly not the beginning of the book), let’s go back to step 5.


Step 5b) These ‘huffdic-compressed’ books require a slightly different script to remove the DRM. Do this:


python mobidedrm2.py Title-of-Book.azw Title-of-Book.mobi Z1QFCDQ*74


Note the ‘2’ in ‘mobidedrm2.py’ in this one and remember to replace my gibberish PID with yours.


6b) The ‘huffdic-compressed’ files also require a different script to convert them to HTML. Do this:


python mobihuff.py Title-of-Book.mobi Title-of-Book.html


This script will output the .html file in the directory from which you are running it.


All in all, this is as much of a pain as it looks, but the selection and availability of books on Amazon makes it worthwhile to me. They have far more books than The Pirate Bay does, and I feel better paying for them


Good luck.

Personal tools