Tuesday, July 20, 2010

iBooks♥B&N: Let's Get Ignoble!

ignoble is the moniker that I♥CABBAGES has chosen for his tools to decrypt e-books from Barnes & Noble that are in the EPUB format. This post by him tells generally how to use these tools. Herein, I show how to do that on a Mac running OS X 10.5 "Leopard."

First, some background information. B&N sell e-books here. For purposes of making my post more concrete, later on in this post I'm going to buy and decrypt the e-book version of Stieg Larsson's The Girl with the Dragon Tattoo, which is the first of (currently) three books in the author's Millennium Trilogy Series. The books in Larsson's series are among the most popular e-books around, and presently you cannot buy them in Apple's iBookstore. So one of the things I'll be doing in this post is showing how to use ignoble to decrypt that B&N e-book so that it can be imported into an iBooks library.

What is iBooks? It's the main e-book reader app for Apple's new iPad, and it also works on iPhones and iPods that run the new iOS 4.0 operating software. Using iBooks, you can buy e-books at the iBookstore, part of Apple's familiar iTunes Store. However, Apple has failed to line up iBookstore support from the largest publishing concern, Random House. Hence a huge number of e-book titles are missing from the iBookstore!

That's presumably why Larsson's books are absent. Their absence is not intolerable for those who are OK with, using their iDevice, switching between iBooks and the B&N eReader app, available for free at the iTunes Store. But then they have to remember which books are in which apps — not fun! In this post I'll show how to move your B&N downloads into iTunes and hence into iBooks.

Here's what you have to do to get and use ignoble:

• Get a Python interpreter

For the Mac platform, you do not need to download Python at all, as Python 2.5 (which works fine for purposes of ignoble) can be installed from the "Leopard" install DVD.

Even though Python 2.5 is part of the Mac OS X software package, in order to use it you do need to make sure the optionally installed Apple Developer package is present on your Mac. If you already, at the outermost root level of your Mac's folder hierarchy, have a folder called Developer, you're fine. If not, create it by inserting your OS X 10.5 Install DVD and navigating to and then double-clicking Mac OS X Install DVD:Optional Installs:Xcode Tools:Xcode Tools.mpkg. You will be led by the installer program which opens through the necessary steps to install the Developer Tools package.

• Get PyCrypto, the Python cryptography toolkit

Go here and click on the "Download" button for PyCrypto 2.0.1. The pycrypto-2.0.1.tar.gz file you'll receive will most likely land right on your Desktop (depending on how you have your browser configured for downloads; if it doesn't download right to the Desktop, you can just move it there). Upon being double-clicked, the pycrypto-2.0.1.tar.gz file expands into a pycrypto-2.0.1 folder, also on the Desktop. You can move this folder wherever you like, or leave it right on the Desktop.

Next, click here to download PyCrypto_2.0.1_Installer.app.zip, which, when unzipped — which will probably happen for you automatically — expands into an AppleScript app called PyCrypto_2.0.1_Installer. Double-click PyCrypto_2.0.1_Installer to run the installer itself. It will ask you to navigate to and "Choose" your pycrypto-2.0.1 folder, the one you created in the preceding paragraph of these instructions. Once you have clicked "Choose," PyCrypto_2.0.1_Installer will open a window in the Mac's Terminal application and execute some Unix commands in it.

The first time you use the PyCrypto_2.0.1_Installer, the Unix commands will produce a large amount of output in the Terminal window, due to the fact that the PyCrypto software is, for the first time on your computer, undergoing a full "build." Any subsequent times you use PyCrypto_2.0.1_Installer, an "install" without a preliminary "build" will be done, and you will see less output in the Terminal window. In either case, the final line of the Terminal-window output should say Writing /Library/Python/2.5/site-packages/pycrypto-2.0.1-py2.5.egg-info.

At this point you can quit Terminal. If you look in Finder — starting at the root-level directory, not at the Home folder for your user account — and navigate to /Library/Python/2.5/, you should find a site-packages folder. In it there should now be a Crypto folder and a pycrypto-2.0.1-py2.5.egg-info file.

• Get the any-platform key-generation script, ignoblekeygen

ignoblekeygen is a Python script that will generate, and save to a file, a Barnes & Noble EPUB user key derived from your name and credit card number.

Before you download this script, create a folder on your Desktop called ignoble. In Finder, click on the Desktop and type Command-Shift-N. A new folder appears with the name untitled folder highlighted for editing. Type ignoble to replace that generic name, and hit Return.

Open the Safari web browser and type Command-, (Command-comma). In the Preferences window that opens, click on General at top left. In the Save downloaded files: popup, choose Other... . In the File Open dialog which appears, navigate to and select the ignoble folder you just created. Click on the red close button at the upper left of the Preferences window.

Now, go here to download the ignoblekeygen script. This is a page at Pastie.org, and in the upper right corner is a Download link. Click on it. A downloaded file called pastie-753985.py will appear in your ignoble folder. (If Safari's Downloads window remains open at this point, click on the red close button at the upper left of the window to close it.)

Rename the pastie-753985.py file ignoblekeygen.py. To do that, double-click on the ignoble folder to open it in Finder, then click twice (but do not do the second click too fast, or it will cause a double-click) on the filename pastie-753985.py. The main part of the filename, pastie-753985, will be highlighted. Type ignoblekeygen in its place and hit Return. This will cause the name of the file to become ignoblekeygen.py.

Now right-click on the ignoblekeygen.py file. In the resulting popup menu, select Open With: Build Applet (default).

If you do not see that option in the popup menu, chances are you do not in fact have Python installed on your Mac. Go back to the first step of this post to see how to install it.

If you see multiple Build Applet choices, choose the one whose version number begins with 2.5.

When you select Build Applet, you may see a warning dialog, "ignoblekeygen.py" is a script application which was downloaded from the Internet. Are you sure you want to open it? Click Open.

After you have run Build Applet — which takes only a second, after which Build Applet disappears — an application file called ignoblekeygen appears in your ignoble folder.

• Run ignoblekeygen

Double-click the ignoblekeygen application file (not ignoblekeygen.py itself). You will see:



Click on the ... button to the right of the Output file field. Type bnepubkey.b64 (or use any other filename you prefer, but make sure you use the .b64 extension) into the Save As: field of the window that appears, then navigate to your ignoble folder and click Save. The Output file field will now contain a fully qualified path name to the key file that is about to be created in your ignoble folder.

Now type your name and credit card number into the appropriate fields. The name should be the one on your account at Barnes & Noble.com. (If you don't yet have a B&N account, click here to set one up.) Likewise, the credit card number you enter should be the one you are using for your B&N account.

Forgotten those details? If you sign in at B&N and then click on the My Account link, you'll see, under PERSONAL INFORMATION just above your e-mail address, the name you specified for your B&N account. You need to make sure that you use that name exactly in Ignoble EPUB Keyfile Generator. For example, if it contains your middle initial on the B&N website, then be sure to use the middle initial for Ignoble EPUB Keyfile Generator.

Under PAYMENT SETTINGS on the website you'll see Default Payment and, beneath that, ****nnnn, with nnnn representing the last four digits of your credit card number. Type the name on your account into the Name field of Ignoble EPUB Keyfile Generator, and the full 16-digit number of your credit card (without spaces or dashes) into the CC# field. Then click on the Generate button to generate the key file (by whatever name you have chosen to give it).

After you have done that, click on the Quit button. You only have to run the Ignoble EPUB Keyfile Generator once ... unless you have multiple B&N accounts, that is, in which case you should generate one key file for each, and the filename you enter in the the Output file field should be different for each — for example, bob's B&N key.b64 and mary's B&N key.b64.

The Ignoble EPUB Keyfile Generator saves your name and credit card number in its output key file in encrypted form, so no one who inspects the contents of the key file will be able to steal the information.

• Get the any-platform book-decryption script, ignobleepub

ignobleepub is a Python script that will use the key file just generated to decrypt any encrypted B&N EPUB e-book.

Go here to download the ignobleepub script. This is a page at Pastie.org, and in the upper right corner is a Download link. Click on it. A downloaded file called pastie-751366.py will appear in your ignoble folder. (If Safari's Downloads window remains open at this point, click on the red close button at the upper left of the window to close it.)

Rename the pastie-751366.py file ignobleepub.py. To do that, double-click on the ignoble folder to open it in Finder, then click twice (but do not do the second click too fast, or it will cause a double-click) on the filename pastie-751366.py. The main part of the filename, pastie-751366, will be highlighted. Type ignobleepub in its place and hit Return. This will cause the name of the file to become ignobleepub.py.

Now right-click on the ignobleepub.py file. In the resulting popup menu, select Open With: Build Applet (default).

If you do not see that option in the popup menu, chances are you do not in fact have Python installed on your Mac. Go back to the first step of this post to see how to install it.

If you see multiple Build Applet choices, choose the one whose version number begins with 2.5.

When you select Build Applet, you may see a warning dialog, "ignobleepub.py" is a script application which was downloaded from the Internet. Are you sure you want to open it? Click Open.

After you have run Build Applet — which takes only a second, after which Build Applet disappears — an application file called ignobleepub appears in your ignoble folder.

• Buy and download a Barnes & Noble EPUB e-book

I'm going to buy Stieg Larsson's The Girl with the Dragon Tattoo, which at the moment of this writing costs a reasonable $7.16 as a B&N e-book. To do that, I go to the webpage for that book and (having already signed in) click on the BUY NOW button. A dialog box appears in which I need to confirm my order. I click on the Confirm button. A "Thank You for Your Order" page appears, on which I click the Go to Your eBooks Library link.

On my My eBooks Library page there now appears:



I click on the  Download Now  .   button. That causes Safari to download the file 9780307272119_Stie_TheGirl.epub into my ignoble folder. (Close the Safari Downloads window manually at this point if you desire.)

The filename extension, .epub, indicates that this file is indeed an EPUB. B&N used to sell e-books with a .pdb filename extension. That outdated so-called "eReader format" does not work with ignoble. It cannot easily be converted for use with iBooks.

Tip: If you have e-books that you downloaded some time ago from B&N, go to your e-books library and re-download the books. Click here, then sign in, then click on the  Download Now   button next to each e-book you want to re-download in turn. The newly downloaded copy of each book will very likely have an .epub extension and will therefore work with ignoble. If you like, you can trash the old .pdb versions. Likewise, if you are using a Nook or any mobile device (such as an iPhone) with the B&N eReader app, you can and probably should re-download your legacy .pdb e-books that are already on that device, so that you will have up-to-date .epub versions on the device instead.

• Decrypt your e-book

To convert 9780307272119_Stie_TheGirl.epub, I just double-click on ignobleepub (not the original script, ignobleepub.py) in my ignoble folder, and I see:




Using the ... button next to the Key file field, I navigate to and select the bnepubkey.b64 key file I generated earlier, using ignoblekeygen.

Using the ... button next to the Input file field, I navigate to and open 9780307272119_Stie_TheGirl.epub from my ignoble folder.

Using the ... button next to the Output file field, I navigate to my ignoble folder and enter Girl Decrypted.epub as the output filename. It does not really matter what output filename I use ... but I must be sure to specify the .epub filename extension.

To see what the full contents of the three fields are, I drag the resize corner at lower right of the window rightward, to see:


Now I click the Decrypt button and quickly see:


Unless I want to buy and decrypt another e-book, I click Quit to exit the ignobleepub application. At any future time I can buy more B&N e-books, download them, and use ignobleepub all over again to decrypt them. I do not have to run ignoblekeygen again, unless of course I have misplaced my bnepubkey.b64 file.

At this point, I have a file called Girl Decrypted.epub that is no longer encrypted, so iBooks can use it. I now have to ...

• Import the Decrypted E-Book into iTunes

I simply drag the Girl Decrypted.epub file onto the LIBRARY area at the top left of my main iTunes window (click image to enlarge it):



This causes The Girl with the Dragon Tattoo to be imported into the Books area of iTunes (click image to enlarge it):



Behind the scenes, iTunes has copied the e-book into a /Books/StiegLarsson/ folder it creates in the folder structure of my iTunes library (click image to enlarge it):



The filename is The Girl with the Dragon Tattoo.epub. iTunes has figured out what the actual title of the book is, along with the author's name!

This all happens in part because I have used the following iTunes Advanced Preferences (click image to enlarge it):


You may need to type Command-, (Command-comma) while in iTunes, click on the Advanced icon at top right, and click on the check marks for Keep iTunes Media folder organized and Copy files to iTunes Media folder when adding to library, if you haven't already done so.

Notice that after I imported my e-book into iTunes, its cover image showed up automatically in Cover Flow view. That doesn't always happen. If you end up with a missing cover image, you can ...

• Manually Give the E-Book a Cover Image

First, go back to the B&N page from which you purchased your e-book. In my case, it was The Girl with the Dragon Tattoo.

Now, click on the cover image you see there, bringing up a new window with a larger version of the cover image.

Right click on the larger cover image and choose Copy Image from the pop-up menu that appears.

Now, switch to iTunes and, with the new e-book selected in the Books portion of the Library (here, my e-book already shows its cover image, but never mind )...


... type Command-I to bring up its Get Info window. Then click on the Artwork tab, to see:



Now, click in the empty artwork box — it's empty even though my cover image was already visible in my main iTunes window — and type Command-V to paste into it the cover artwork that presently is residing on the Clipboard, in order to see:



Click OK to dismiss the iTunes Get Info window. A few seconds later, the new cover artwork appears in the main Tunes window (replacing the cover image, if any, that was already visible there).

Now you're ready to ...

• Sync your iDevice to iTunes

Your iPad, iPhone, or iPod Touch will generally be synced to iTunes automatically, each time you connect it to your Mac. Syncing books requires iTunes version 9.2 or later. But syncing doesn't necessarily include e-books, unless you (click image to enlarge it) ...



... have Sync Books checkmarked in the iDevice's Books tab, as I do here. I've likewise checked Selected books rather than All books, so only the e-books that I've put individual checkmarks by are going to get synced to my iDevice. Notice The Girl with the Dragon Tattoo is shown at lower left of the Books pane, and it does have a checkmark by it. So when I click on the Sync button, at lower right of the window, I expect it (and all other checkmarked books) to be synced to my iDevice.

And that is exactly what happens in iBooks on my iPhone:



Here's my e-book actually being read in iBooks:




You can read more about iBooks, the free app from Apple that runs on iOS 4.0 iDevices — iPad, iPhone 3GS, iPod Touch — in my iBooks Cook! post.

The iBooks app itself can be downloaded here.

Apple offers this iBooks: Frequently Asked Questions (FAQ) to fill you in on the basic capabilities of iBooks.

If you read that FAQ, notice that there is no mention of any ability to read iBooks e-books right on your Mac, in iTunes or in any other app, even though the e-books reside within the iTunes library. For B&N books that you have decrypted according to the procedure herein given, you can just open them in the B&N eReader app for your Mac, available here.

Unfortunately, I know of no way to read, on your Mac, e-books (other than those that are not DRM-encrypted) from the iBookstore.

• What about Windows?

Windows users can also use ignoble, but installing Python and PyCrypto requires a different strategy.

Python:


If you use Windows you can currently get Python version 2.6, which you can download and install in Windows by going to the
 Python download page and then clicking on (as of this writing) the hotlink to Python 2.6.4 Windows installer. (There is also a version 3.1, but I can't guarantee it will work with this procedure.) You'll download a file called python-2.6.4.msi which you'll proceed to double-click, and then you'll follow the installer's on-screen prompts that allow you to install the Python 2.6 package in a directory the installer creates,C:\Python26. The actual app within that folder is called python.

PyCrypto:


Windows users can obtain PyCrypto
 here (on that page, click on the link to pycrypto-2.0.1.win32-py2.6.exe). After downloading the .exe file, double-click on it to run the Setup Wizard. As long as you have already downloaded and installed Python as detailed above, the Wizard (after you click "Next >" on the introductory panel) will indicate Python 2.6 has been duly found in the Windows Registry, in C:\Python26\. The Wizard will accordingly use the subfolder C:\Python26\Lib\site-packages\ as its installation directory. After you click on "Next >" once more, you will see a "Ready to install" panel. Click "Next >" yet again to actually perform the installation. Then click "Finish" to exit the Wizard. You should now be able to locate a Crypto folder and also a pycrypto-2.0.1-py2.6.egg-info file in C:\Python26\Lib\site-packages\.

Notice that Windows users are going to be using Python version 2.6, not 2.5 as on a Mac. As far as I know, this is not a problem.

There will also be different OS-dependent mechanics involved with downloading, installing, and using ignoblekeygen and ignobleepub. I'm not going to go into detail on all of those mechanics, but I will give some hints.

After downloading the two Python scripts, you need to arrange for them to have the filenames ignoblekeygen.pyw and ignobleepub.pyw, respectively. Notice that the filename extensions in each case are .pyw, with a "w" at the end. The "w" stands for "Windows." It allows you to do the following ...

When you want to run, say, ignoblekeygen, you right-click on ignoblekeygen.pyw and select Open With: python to designate the python.exe app (which in turn is "hosted" by the cmd.exe interface, whose window, though empty, appears behind that of the Python script's user interface). Or, if you instead select Open With: Choose Program ... , you can check "Always use the selected program to open this kind of file," and then select python and click "OK." From then on, you will be able to double-click any Python script file whose filename extension is .pyw, and it will automatically open in python.exe.

• What about Mac OS X 10.6 "Snow Leopard"?

I myself have yet to upgrade to Mac OS X 10.6, so I don't have hands-on experience with "Snow Leopard." You will have to take what I say with a grain of salt ...

Based on comments that users have made to my iPhone: Reading Adobe/EPUB eBooks post, which involves using similar Python scripts from I♥CABBAGES to decrypt e-books that have Adobe DRM, it is my understanding that the instructions I gave above basically work on Snow Leopard, except ...

... some Snow Leopard users have had trouble with installing PyCrypto, the Python Cryptography Toolkit. The basic problem has to do with Snow Leopard's use of two Python versions. Version 2.5 is the one that you need to use to run the two Python scripts, ignoblekeygen and ignobleepub, that my instructions call for.

Some users of Snow Leopard have been finding that the PyCrypto installer is putting PyCrypto in

/Library/Frameworks/Python.frameworks/versions/2.6/lib/python2.6/site-packages/

That is the wrong place! The right place for it is

/Library/Python/2.5/site-packages/

Solution: after installing PyCrypto as per the procedure above, simply copy all of the contents of the

/Library/Frameworks/Python.frameworks/versions/2.6/lib/python2.6/site-packages/

folder to

/Library/Python/2.5/site-packages/

In Finder, you can do this by highlighting all of the items contained in the Python 2.6 /site-packages/ folder and dragging them with the option key held down to the Python 2.5 /site-packages/ folder. (Be aware that you may have to create the latter folder manually in the /Library/Python/2.5/ folder.) This option-drag procedure makes a copy in the destination /site-packages/ folder of all of the highlighted items.

Among the items that need to be highlighted and copied in this way are a folder called Crypto, along with all of its contents, and a file called pycrypto-2.0.1-py2.5.egg-info. You should check to make sure that these items and (in the case of the Crypto folder) their contained items get properly copied. If the latter file is named pycrypto-2.0.1-py2.6.egg-info, you should change the name to pycrypto-2.0.1-py2.5.egg-info manually.

Once you have manually copied the PyCrypto installation folder/files to where they need to be, I believe the remaining steps in the procedure above should work.


Well, that's about it for now. Happy iBooking, everyone!

8 comments:

Anonymous said...

Wow. That was complifreakincated. Kudos though.

My local library uses e-books from OverDrive in DRM'd Adobe EPUB and PDF formats.

I've stripped DRM on library WMA audiobooks (solely for the ability to play on my iPhone and to keep the book for as long as it takes me to listen to it, after which I delete it). Do you know of a process like the one you've outlined that will work with LIBRARY DRM'd files in Adobe EPUB and/or PDF formats (as opposed to B&N files)?

eric said...

Anonymous said...

Wow. That was complifreakincated. Kudos though.

My local library uses e-books from OverDrive in DRM'd Adobe EPUB and PDF formats.

I've stripped DRM on library WMA audiobooks (solely for the ability to play on my iPhone and to keep the book for as long as it takes me to listen to it, after which I delete it). Do you know of a process like the one you've outlined that will work with LIBRARY DRM'd files in Adobe EPUB and/or PDF formats (as opposed to B&N files)?


Anon,

To unlock Adobe EPUBs, see iPhone: Reading Adobe/EPUB eBooks. If for any reason you don't find that that works correctly for you, I posted some solutions to common problems in Breaking Adobe DRM — Tips, Tricks, Workarounds.

As for Adobe PDFs, in step 6 of the procedure where ineptepub is used, substitute ineptpdf. You can download version 7.4 of the ineptpdf.pyw Python script (which is either the latest version or close to it) here. You use it the same way you would use ineptepub, i.e., you open it in python and specify to it your adeptkey.der, the file containing the Adobe PDF e-book you want to decrypt, and the output file name and path.

Agreed ... these procedures are complicated, but if you do them two or three times, you get so you can do them in your sleep ...

Anonymous said...

anyone know where else the ignoblekeygen is located, seems that pastie is down.

eric said...

Anonymous said...

anyone know where else the ignoblekeygen is located, seems that pastie is down.

Yes, I can confirm that. At this moment at least, http://pastie.org/ seems to have its server(s) down.

Meanwhile, download

http://epstewart.home.comcast.net/ignoble.zip

and (since it is a ZIP file) unzip it, using Archive Utility or Stuffit Expander, if it diesn't unzip automatically when it is downloaded. You will get a folder containing two files

ignoblekeygen.py

and

igonbleepub.py

that you can use (without having to rename them) in the procedure I described in the main post above. These are the source Python scripts that you will open in Build Applet to generate the double-clickable applications ignoblekeygen and igonbleepub, respectively.

TJovian said...

I used to use this same method to strip the DRM from my eBook purchases from B&N, but now it seems the decryption tool is no longer working for me. I did notice that my most recent downloads from B&N are in PDB format and not EPUB. Can anyone else verify this as the cause of the "Error: Not a ZIP file" problem I'm experiencing?

eric said...

TJovian said...

I used to use this same method to strip the DRM from my eBook purchases from B&N, but now it seems the decryption tool is no longer working for me. I did notice that my most recent downloads from B&N are in PDB format and not EPUB. Can anyone else verify this as the cause of the "Error: Not a ZIP file" problem I'm experiencing?

TJ,

Turning DRM'ed PDB eBooks into iBooks may tell you how to convert those "Error: Not a ZIP file" PDBs!

Eric

artı 18 dizisi said...

nice post ;)

eric said...

artı 18 dizisi said...


nice post ;)


Thanks! Enjoy!