Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple simultaneous BOOK_IDs and/or playlist ID #89

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 63 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SafariBooks
Download and generate *EPUB* of your favorite books from [*Safari Books Online*](https://www.safaribooksonline.com) 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](https://learning.oreilly.com/terms/).
Download and generate *EPUB* of your favorite books from [*Safari Books Online*](https://www.safaribooksonline.com) 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](https://learning.oreilly.com/terms/).

## Overview:
* [Requirements & Setup](#requirements--setup)
Expand All @@ -20,33 +20,34 @@ $ pip3 install -r requirements.txt
OR

$ pipenv install && pipenv shell
```
```

The program depends of only two **Python 3** modules:
```python3
lxml>=4.1.1
requests>=2.18.4
```

## 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.
* X-es with the IDs of the books you want to download,
* `email:password` with your own.

```shell
$ python3 safaribooks.py --cred "account_mail@mail.com:password01" XXXXXXXXXXXXX
$ python3 safaribooks.py --cred "account_mail@mail.com:password01" XXXXXXXXXXXXX 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/`
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:
```shell
$ python3 safaribooks.py --help
usage: safaribooks.py [--cred <EMAIL:PASS>] [--no-cookies] [--no-kindle]
[--preserve-log] [--help]
<BOOK ID>
usage: safaribooks.py [--cred <EMAIL:PASS>] [--playlist ID]
[--no-cookies] [--no-kindle] [--preserve-log]
[--help]
<BOOK ID> <BOOK ID> ...

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

Expand All @@ -55,98 +56,101 @@ positional arguments:
You can find it in the URL (X-es):
`https://www.safaribooksonline.com/library/view/book-
name/XXXXXXXXXXXXX/`
You can specify as many of these as you want

optional arguments:
--cred <EMAIL:PASS> Credentials used to perform the auth login on Safari
Books Online.
Es. ` --cred "account_mail@mail.com:password01" `.
--playlist ID Download an entire playlist of books at once.
Overrides any positional book ids provided.
--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
--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`](/../../issues/15) 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`](/../../issues/2#issuecomment-367726544)).
Pay attention if you use a shared PC, because everyone that has access to your files can steal your session.
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`](/../../issues/2#issuecomment-367726544)).

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`.

You can configure proxies by setting on your system the environment variables `HTTP_PROXY` and `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](https://calibre-ebook.com/).
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](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_calibre_IgnoreMargins.png "Select Ignore margins")
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](https://calibre-ebook.com/).
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](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_calibre_IgnoreMargins.png "Select Ignore margins")

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.

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.

## Examples:
* ## Download [Test-Driven Development with Python, 2nd Edition](https://www.safaribooksonline.com/library/view/test-driven-development-with/9781491958698/):
* ## Download [Test-Driven Development with Python, 2nd Edition](https://www.safaribooksonline.com/library/view/test-driven-development-with/9781491958698/):
```shell
$ python3 safaribooks.py --cred "XXXX@gmail.com:XXXXX" 9781491958698

____ ___ _
____ ___ _
/ __/__ _/ _/__ _____(_)
_\ \/ _ `/ _/ _ `/ __/ /
/___/\_,_/_/ \_,_/_/ /_/
_\ \/ _ `/ _/ _ `/ __/ /
/___/\_,_/_/ \_,_/_/ /_/
/ _ )___ ___ / /__ ___
/ _ / _ \/ _ \/ '_/(_-<
/____/\___/\___/_/\_\/___/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[-] Logging into Safari Books Online...
[*] Retrieving book info...
[-] Title: Test-Driven Development with Python, 2nd Edition
[-] Authors: Harry J.W. Percival
[-] Identifier: 9781491958698
[-] ISBN: 9781491958704
[-] Publishers: O'Reilly Media, Inc.
[-] Rights: Copyright © O'Reilly Media, Inc.
[-] Description: By taking you through the development of a real web application
from beginning to end, the second edition of this hands-on guide demonstrates the
practical advantages of test-driven development (TDD) with Python. You’ll learn
[*] Retrieving book info...
[-] Title: Test-Driven Development with Python, 2nd Edition
[-] Authors: Harry J.W. Percival
[-] Identifier: 9781491958698
[-] ISBN: 9781491958704
[-] Publishers: O'Reilly Media, Inc.
[-] Rights: Copyright © O'Reilly Media, Inc.
[-] Description: By taking you through the development of a real web application
from beginning to end, the second edition of this hands-on guide demonstrates the
practical advantages of test-driven development (TDD) with Python. You’ll learn
how to write and run tests before building each part of your app, and then develop
the minimum amount of code required to pass those tests. The result? Clean code
that works.In the process, you’ll learn the basics of Django, Selenium, Git,
that works.In the process, you’ll learn the basics of Django, Selenium, Git,
jQuery, and Mock, along with curre...
[-] Release Date: 2017-08-18
[-] URL: https://www.safaribooksonline.com/library/view/test-driven-development-with/9781491958698/
[*] Retrieving book chapters...
[*] Output directory:
[*] Retrieving book chapters...
[*] Output directory:
/XXXX/XXXX/Books/Test-Driven Development with Python, 2nd Edition
[-] Downloading book contents... (73 chapters)
[-] Downloading book contents... (73 chapters)
[#########################################----------------------------] 60%
...
[-] Creating EPUB file...
[*] Done: Test-Driven Development with Python, 2nd Edition.epub
[-] Creating EPUB file...
[*] Done: Test-Driven Development with Python, 2nd Edition.epub

If you like it, please * this project on GitHub to make it known:
https://github.com/lorenzodifuccia/safaribooks
e don't forget to renew your Safari Books Online subscription:
https://www.safaribooksonline.com/signup/

[!] Bye!!
```
The result will be (opening the `EPUB` file with Calibre):
```
The result will be (opening the `EPUB` file with Calibre):

![Book Appearance](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_example01_TDD.png "Book opened with Calibre")

![Book Appearance](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_example01_TDD.png "Book opened with Calibre")

* ## Use or not the `--no-kindle` option:
```bash
$ python3 safaribooks.py --no-kindle 9781491958698
```
On the left book created with `--no-kindle` option, on the right without (default):
![NoKindle Option](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_example02_NoKindle.png "Version compare")
---
```
On the left book created with `--no-kindle` option, on the right without (default):

![NoKindle Option](https://github.com/lorenzodifuccia/cloudflare/raw/master/Images/safaribooks/safaribooks_example02_NoKindle.png "Version compare")

---

## Thanks!!
For any kind of problem, please don't hesitate to open an issue here on *GitHub*.
For any kind of problem, please don't hesitate to open an issue here on *GitHub*.

*Lorenzo Di Fuccia*
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lxml>=4.1.1
requests>=2.20.0

Loading