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

Develop #46

Open
wants to merge 17 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
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ celerybeat-schedule
*.sage.py

# Environments
.env
*.env
.venv
env/
venv/
Expand All @@ -103,4 +103,15 @@ venv.bak/
# mypy
.mypy_cache/

*.env
# VSCode
.vscode

# SonarLint
.sonarlint

# IntelliJ
.idea/

# Downloaded Media
media/
book/
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ Script to download all your PacktPub books inspired by https://github.com/ozziep
Since PacktPub restructured their website [packtpub-library-downloader](https://github.com/ozzieperez/packtpub-library-downloader) became obsolete because the downloader used webscraping. So I figured out that now PacktPub uses a REST API. Then I found which endpoint to use for downloading books and made a simple script. Feel free to fork and PR to improve. Packtpub's API isn't documented :'(

## Usage:

pip install -r requirements.txt
python main.py -e <email> -p <password> [-d <directory> -b <book file types> -s -v -q]
python main.py -e <email> -p <password> [-d <directory> -b <book file types> -s -v -q] [-i <bookids>]

##### Example: Download books in PDF format
python main.py -e hello@world.com -p p@ssw0rd -d ~/Desktop/packt -b pdf,epub,mobi,code

python main.py -e hello@world.com -p p@ssw0rd -d ~/Desktop/packt -b pdf,epub,mobi,code

## Docker integration

You must put your data in the `.env` file.
You must put your data in the `.env` file.

```
mv data.env-sample data.env
Expand All @@ -27,21 +29,24 @@ docker-compose up

After the execution, you can see the content in the `book` directory.


## Commandline Options
- *-e*, *--email* = Your login email
- *-p*, *--password* = Your login password
- *-d*, *--directory* = Directory to download into. Default is "media/" in the current directory
- *-b*, *--books* = Assets to download. Options are: *pdf,mobi,epub,code*
- *-s*, *--separate* = Create a separate directory for each book
- *-v*, *--verbose* = Show more detailed information
- *-q*, *--quiet* = Don't show information or progress bars

- _-e_, _--email_ = Your login email
- _-p_, _--password_ = Your login password
- _-d_, _--directory_ = Directory to download into. Default is "media/" in the current directory
- _-b_, _--books_ = Assets to download. Options are: _pdf,mobi,epub,code,video_
- _-s_, _--separate_ = Create a separate directory for each book
- _-v_, _--verbose_ = Show more detailed information
- _-q_, _--quiet_ = Don't show information or progress bars
- _-i_, _--ids_ = Products to download by id (If it is not specified, it will download all products that you have purchased)
- _-R_, _--readme_ = Create a README.md file with info of the book (_--separate_ option required)

**Book File Types**

- *pdf*: PDF format
- *mobi*: MOBI format
- *epub*: EPUB format
- *code*: Accompanying source code, saved as .zip files
- _pdf_: PDF format
- _mobi_: MOBI format
- _epub_: EPUB format
- _code_: Accompanying source code, saved as .zip files
- _video_: Some courses are in video format

I'm working on Python 3.6.0
I'm working on Python 3.6.0
9 changes: 9 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@
# this is base url where i do the requests
BASE_URL = "https://services.packtpub.com/"

# this is base url for static content
BASE_STATIC_URL = "https://static.packt-cdn.com/"

# URL to request jwt token, params by post are user and pass, return jwt token
AUTH_ENDPOINT = "auth-v1/users/tokens"

# URL to get all your books, two params that i change are offset and limit, method GET
PRODUCTS_ENDPOINT = "entitlements-v1/users/me/products?sort=createdAt:DESC&offset={offset}&limit={limit}"

# URL(BASE_STATIC) to get book information from id
PRODUCT_FROM_ID_ENDPOINT = "products/{id}/summary"

# URL(BASE_STATIC) to get author information from id
AUTHOR_FROM_ID_ENDPOINT = "authors/{id}"

# URL to get types , param is book id, method GET
URL_BOOK_TYPES_ENDPOINT = "products-v1/products/{book_id}/types"

Expand Down
3 changes: 2 additions & 1 deletion data.env-sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
EMAIL=email@example.com
PASSWORD=example$password
PASSWORD=example$password
IDS=
8 changes: 7 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
pip install -r /app/requirements.txt
python /app/main.py -e $EMAIL -p $PASSWORD -d /app/book -b pdf,mobi,epub,code

if [[ -z "${IDS}" ]]; then
# python /app/main.py -e $EMAIL -p $PASSWORD -d /app/book -b pdf,mobi,epub,code,video -s -v
python /app/main.py -e $EMAIL -p $PASSWORD -d /app/book -b pdf,mobi,epub -s -v -R
else
python /app/main.py -e $EMAIL -p $PASSWORD -d /app/book -b pdf,mobi,epub,code,video -s -v -R -i $IDS
fi
Loading