Skip to content

Download and generate EPUB of your favorite books from O'Reilly Learning (aka Safari Books Online) library.

License

Notifications You must be signed in to change notification settings

makhalaf/safaribooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafariBooks

Download and generate EPUB of your favorite books from Safari Books Online library.
I'm not responsible for the use of this program, this is only for personal and educational purpose.
Before any usage please read the O'Reilly's Terms of Service.

Overview:

Requirements & Setup:

$ git clone https://github.com/lorenzodifuccia/safaribooks.git
Cloning into 'safaribooks'...

$ cd safaribooks/
$ pip3 install -r requirements.txt

OR

$ pipenv install && pipenv shell

The program depends of only two Python 3 modules:

lxml>=4.1.1
requests>=2.20.0

Usage:

It's really simple to use, just choose a book from the library and replace in the following command:

  • X-es with its ID,
  • email:password with your own.
$ python3 safaribooks.py --cred "[email protected]:password01" XXXXXXXXXXXXX

The ID is the digits that you find in the URL of the book description page:
https://www.safaribooksonline.com/library/view/book-name/XXXXXXXXXXXXX/
Like: https://www.safaribooksonline.com/library/view/test-driven-development-with/9781491958698/

Program options:

$ python3 safaribooks.py --help
usage: safaribooks.py [--cred <EMAIL:PASS> | --login] [--no-cookies] [--no-kindle]
                      [--preserve-log] [--help]
                      <BOOK ID>

Download and generate EPUB of your favorite books from Safari Books Online.

positional arguments:
  <BOOK ID>            Book digits ID that you want to download.
                       You can find it in the URL (X-es):
                       `https://www.safaribooksonline.com/library/view/book-
                       name/XXXXXXXXXXXXX/`

optional arguments:
  --cred <EMAIL:PASS>  Credentials used to perform the auth login on Safari
                       Books Online.
                       Es. ` --cred "[email protected]:password01" `.
  --login              Prompt for credentials used to perform the auth login
                       on Safari Books Online.
  --no-cookies         Prevent your session data to be saved into
                       `cookies.json` file.
  --no-kindle          Remove some CSS rules that block overflow on `table`
                       and `pre` elements. Use this option if you're not going
                       to export the EPUB to E-Readers like Amazon Kindle.
  --preserve-log       Leave the `info_XXXXXXXXXXXXX.log` file even if there 
                       isn't any error.
  --help               Show this help message.

The first time you use the program, you'll have to specify your Safari Books Online account credentials (look here for special character). The next times you'll download a book, before session expires, you can omit the credential, because the program save your session cookies in a file called cookies.json (for SSO look the file format here).

Pay attention if you use a shared PC, because everyone that has access to your files can steal your session. If you don't want to cache the cookies, just use the --no-cookies option and provide all time your --cred to perform --login.

You can configure proxies by setting on your system the environment variable HTTPS_PROXY.

The program default options are thought for ensure best compatibilities for who want to export the EPUB to E-Readers like Amazon Kindle. If you want to do it, I suggest you to convert the EPUB to AZW3 with Calibre.
You can also convert the book to MOBI and if you'll do it with Calibre be sure to select Ignore margins in the conversion options:

Calibre IgnoreMargins

In the other hand, if you're not going to export the EPUB, you can use the --no-kindle option to remove the CSS that blocks overflow on table and pre elements, see below in the examples.