Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jul 14, 2024
2 parents 5656dc3 + 1963a77 commit aba09e4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config.yml
**/tempCodeRunnerFile.py
.vscode/
node_modules/
Downloads/

# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,pycharm+all,virtualenv
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,pycharm+all,virtualenv
Expand Down
78 changes: 39 additions & 39 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,28 @@ Python CLI tool download sách từ <strong>VNULIB</strong>

---

- [✨ VNULIB DOWNLOADER ✨](#-vnulib-downloader-)
- [🎆 CHỨC NĂNG](#-chức-năng)
- [🥂 DEMO](#-demo)
- [🪴 HƯỚNG DẪN SỬ DỤNG](#-hướng-dẫn-sử-dụng)
- [1️⃣ Tải tool](#1️⃣-tải-tool)
- [2️⃣ Sử dụng](#2️⃣-sử-dụng)
- [⚙️ NÂNG CAO](#️-nâng-cao)
- [🗃️ Pre-config](#️-pre-config)
- [⛏️ Command line arguments](#️-command-line-arguments)
- [📦 Docker](#-docker)
- [🤐 Python](#-python)
- [🤔 NOTES](#-notes)
- [Giải thích thuật ngữ](#giải-thích-thuật-ngữ)
- [👨‍💻 DEVELOP / CONTRIBUTE](#-develop--contribute)
- [📓 TODO](#-todo)
- [📝 LICENSE](#-license)
- [🤥 DISCLAIMER](#-disclaimer)
- [😌 CREDIT](#-credit)
- [⭐ STARGAZER](#-stargazer)
<!-- toc -->

- [🎆 CHỨC NĂNG](#%F0%9F%8E%86-ch%E1%BB%A9c-nang)
- [🥂 DEMO](#%F0%9F%A5%82-demo)
- [🪴 HƯỚNG DẪN SỬ DỤNG](#%F0%9F%AA%B4-h%C6%B0%E1%BB%9Bng-d%E1%BA%ABn-s%E1%BB%AD-d%E1%BB%A5ng)
- [1️⃣ Tải tool](#1%EF%B8%8F%E2%83%A3-t%E1%BA%A3i-tool)
- [2️⃣ Sử dụng](#2%EF%B8%8F%E2%83%A3-s%E1%BB%AD-d%E1%BB%A5ng)
- [⚙️ NÂNG CAO](#%E2%9A%99%EF%B8%8F-nang-cao)
- [🗃️ Pre-config](#%F0%9F%97%83%EF%B8%8F-pre-config)
- [⛏️ Command line arguments](#%E2%9B%8F%EF%B8%8F-command-line-arguments)
- [📦 Docker](#%F0%9F%93%A6-docker)
- [🤐 Python](#%F0%9F%A4%90-python)
- [🤔 NOTES](#%F0%9F%A4%94-notes)
- [Giải thích thuật ngữ](#gi%E1%BA%A3i-thich-thu%E1%BA%ADt-ng%E1%BB%AF)
- [👨‍💻 DEVELOP / CONTRIBUTE](#%F0%9F%91%A8%E2%80%8D%F0%9F%92%BB-develop--contribute)
- [📓 TODO](#%F0%9F%93%93-todo)
- [📝 LICENSE](#%F0%9F%93%9D-license)
- [🤥 DISCLAIMER](#%F0%9F%A4%A5-disclaimer)
- [😌 CREDIT](#%F0%9F%98%8C-credit)
- [⭐ STARGAZER](#%E2%AD%90-stargazer)

<!-- tocstop -->

---

Expand Down Expand Up @@ -138,16 +141,6 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
| `CREATE_PDF` | `y`, `n`, ... | `y` | Tạo file PDF từ các ảnh đã tải về | `y` |
| `CLEAN_IMG` | `y`, `n`, ... | `y` | Xoá ảnh sau khi đã tạo PDF | `y` |

> [!WARNING]
>
> - Vì sử dụng Multithreading, nếu tải quá nhiều sách có thể ảnh hưởng đến server
> - Thi thoảng `[browser] driver` không tự tắt dẫn đến ngốn RAM và CPU. Hãy check và tắt _(Task Manager, pkill,...)_
> [!IMPORTANT]
>
> - Nếu trong tương lai việc sử dụng link `book` hay `preview` không được, hãy thử link `page` _(vì các phần tử trang web
> có thể thay đổi)_
> [!NOTE]
>
> - Ảnh và sách sẽ được tải về `./Downloads/`
Expand All @@ -161,6 +154,13 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
> - `page` link: Trong link có query `&page=`:
> - `1`: Tool sẽ tự động check và tải trang sách đến khi đạt giới hạn _(Single thread)_
> - \> `1`: Tool tự nhận đấy là limit của file sách hoặc chủ đích sử dụng _(Multithreading)_
> - Nếu trong tương lai việc sử dụng link `book` hay `preview` không được, hãy thử link `page` _(vì các phần tử trang web
> có thể thay đổi)_
> [!WARNING]
>
> - Vì sử dụng Multithreading, nếu tải quá nhiều sách có thể ảnh hưởng đến server
> - Thi thoảng `[browser] driver` không tự tắt dẫn đến ngốn RAM và CPU. Hãy check và tắt _(Task Manager, pkill,...)_
---

Expand Down Expand Up @@ -202,8 +202,13 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
```
- Ví dụ _(Windows)_:
```.ps1
.\VNULIB-Downloader-windows.exe --link "link1" "link2" --username "1500023520000" --password "examplePass" --browser "./chrome_driver.exe" --headless --create-pdf --clean-imgs
.\VNULIB-Downloader-windows.exe --link "link1" "link2" --username="1500023520000" --password "examplePass\!" --browser="" --headless --create-pdf --clean-img --timeout="20"
```
> Đảm bảo các arguments như trên sẽ không yêu cầu nhập từ stdin
> [!NOTE]
>
> Vui lòng để ý nếu mật khẩu chứa ký tự đặc biệt cần escape _(`\`, `\``, `^` tùy shell)_ hoặc hãy sử dụng [🗃️ Pre-config](#%F0%9F%97%83%EF%B8%8F-pre-config)
### 📦 Docker

Expand Down Expand Up @@ -231,7 +236,6 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
git clone "https://github.com/KevinNitroG/VNULIB-Downloader" --depth 1 --filter=blob:none
```
3. Create virtual environment _(optional)_

- Create virtual environment
```.ps1
python -m venv .venv
Expand All @@ -245,22 +249,18 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
```.sh
source .venv/bin/activate
```
- Deactive virtual environment
```.sh
deactivate
```
4. Install requirements
```ps1
pip install -r requirements/requirements.txt
```

5. Run tool

```ps1
python main.py
```
6. Deactive virtual environment _(optional)_
```.sh
deactivate
```

> [!NOTE]
>
Expand Down
4 changes: 1 addition & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from multiprocessing import freeze_support
from pprint import pformat

from urllib3 import PoolManager
from urllib3 import disable_warnings as urllib3_disable_warnings
from urllib3.exceptions import InsecureRequestWarning

from src import Action, Browser, CleanIMG, Config, CreatePDF, DownloadIMG, LinkParse, Login, PrintIntro, ToolLogger, UserOptions, create_directory, delete_old_meipass, pause, print_title
from src.constants import DOWNLOAD_DIR, NUMBER_OF_THREADS
from src.constants import DOWNLOAD_DIR


def main() -> None:
Expand Down Expand Up @@ -62,5 +61,4 @@ def main() -> None:
if __name__ == "__main__":
freeze_support() # For pyinstaller to fix multiprocessing in Windows due to freeze scheme
urllib3_disable_warnings(InsecureRequestWarning)
PoolManager(num_pools=NUMBER_OF_THREADS)
main()
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ img2pdf==0.5.1
print-color==0.4.6
pyyaml==6.0.1
requests==2.32.3
selenium==4.21.0
urllib3==2.2.1
selenium==4.22.0
urllib3==2.2.2
webdriver-manager==4.0.1
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _get_number_of_thread(max_number_of_threads: int) -> int:
return number_of_thread if number_of_thread * 5 < max_number_of_threads else max_number_of_threads


VERSION: str = "v1.17.4"
VERSION: str = "v1.17.5"
AUTHORS: str = "KevinNitroG & NTGNguyen"
BANNER_FILE: str = f"{BUNDLE_DIR}assets/utils/ascii_banner.txt"
with open(BANNER_FILE, encoding="utf-8") as banner_content:
Expand Down
2 changes: 1 addition & 1 deletion src/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from .argpase import setup_argparse
from .argparse import setup_argparse
from .clean_img import CleanIMG
from .config import Config
from .create_pdf import CreatePDF
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/modules/user_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from yaml import safe_load

from ..constants import CONFIG_FILE, USER_INPUT_NO, USER_INPUT_YES
from .argpase import setup_argparse
from .argparse import setup_argparse

logger = getLogger(__name__)

Expand Down Expand Up @@ -155,7 +155,7 @@ def _setup_timeout(self) -> int:
"""
if self.argparse.timeout is not None:
self._log_set_by_argparse("timeout")
return int(self.argparse.browser)
return int(self.argparse.timeout)
if self._config["TIMEOUT"] is not None:
self._log_set_by_config("timeout")
return int(self._config["TIMEOUT"])
Expand All @@ -175,7 +175,7 @@ def _setup_browser(self) -> str:
self._log_set_by_config("browser")
return self._config["BROWSER"].lower()
self._log_set_by_user_input("browser")
return input('Enter browser you are using ["CHROME", "CHROMIUM", "path/to/chrome_driver"]: ').strip().lower()
return input('Enter browser you are using ["chrome", "chromium", "path/to/chrome_driver"]: ').strip().lower()

def _setup_headless(self) -> bool:
"""Setup headless mode.
Expand Down
4 changes: 2 additions & 2 deletions src/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from logging import DEBUG, WARNING, Logger, getLogger
from logging import DEBUG, ERROR, WARNING, Logger, getLogger
from logging.config import dictConfig
from logging.handlers import QueueHandler
from multiprocessing import Queue
Expand Down Expand Up @@ -49,7 +49,7 @@ def _setup_other_logger() -> None:
getLogger("PIL.PngImagePlugin").setLevel(WARNING)
getLogger("PIL.Image").setLevel(WARNING)
getLogger("charset_normalizer").setLevel(WARNING)
getLogger("urllib3.connectionpool").setLevel(WARNING)
getLogger("urllib3.connectionpool").setLevel(ERROR)
getLogger("selenium.webdriver.remote.remote_connection").disabled = True
os_environ["WDM_LOG"] = str(DEBUG)
os_environ["WDM_SSL_VERIFY"] = "0"
Expand Down

0 comments on commit aba09e4

Please sign in to comment.