Skip to content

Python CLI Tool tải sách từ VNULIB

License

Notifications You must be signed in to change notification settings

KevinNitroG/VNULIB-Downloader

Repository files navigation

✨ VNULIB DOWNLOADER ✨

██╗   ██╗███╗   ██╗██╗   ██╗██╗     ██╗██████╗ 
██║   ██║████╗  ██║██║   ██║██║     ██║██╔══██╗
██║   ██║██╔██╗ ██║██║   ██║██║     ██║██████╔╝
╚██╗ ██╔╝██║╚██╗██║██║   ██║██║     ██║██╔══██╗
 ╚████╔╝ ██║ ╚████║╚██████╔╝███████╗██║██████╔╝
  ╚═══╝  ╚═╝  ╚═══╝ ╚═════╝ ╚══════╝╚═╝╚═════╝ 

██████╗  ██████╗ ██╗    ██╗███╗   ██╗██╗      ██████╗  █████╗ ██████╗ ███████╗██████╗ 
██╔══██╗██╔═══██╗██║    ██║████╗  ██║██║     ██╔═══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
██║  ██║██║   ██║██║ █╗ ██║██╔██╗ ██║██║     ██║   ██║███████║██║  ██║█████╗  ██████╔╝
██║  ██║██║   ██║██║███╗██║██║╚██╗██║██║     ██║   ██║██╔══██║██║  ██║██╔══╝  ██╔══██╗
██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║███████╗╚██████╔╝██║  ██║██████╔╝███████╗██║  ██║
╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═══╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝ ╚══════╝╚═╝  ╚═╝

Python CLI tool download sách từ VNULIB
GitHub last commit (by committer) Lines of code GitHub repo size GitHub contributors Hit

Wakatime CodeFactor Grade Release Status Code check status

DeepSource active issues DeepSource resolved issues

Python Shell Script Selenium Pre-commit GitHub Actions Docker

Release Download Count Docker Pull Count Docker Image Size


🎆 CHỨC NĂNG

  • Tải sách (có thể đọc preview online) trên VNULIB (HCM)

    Ví dụ: https://ir.vnulib.edu.vn/handle/VNUHCM/8108

  • Hỗ trợ link: book, preview, page ?
  • Hỗ trợ tải nhiều sách (lần lượt từng sách)
  • Tải sách - Multithreading?
  • Tạo PDF các file sách - Multiprocessing?
  • Xoá ảnh sau khi tải (phù hợp khi dùng tạo PDF)

🥂 DEMO

  • Chưa có nha chờ kiếp sau

🪴 HƯỚNG DẪN SỬ DỤNG

1️⃣ Tải tool

  • Windows
  • Mac OS
  • Linux

Important

  • Các bản prebuilt chỉ dành cho máy chip AMD64.
  • Với các máy dùng chip ARM64 hãy dùng phương pháp 📦 Docker hoặc 🤐 Python.
  • Các máy dùng chip khác có thể sẽ không dùng được vì một số thư viện không hỗ trợ. Hãy dùng tool đơn giản hơn như tlatonf/vnulib (Windows only).

Note

Linux + Mac: Nếu file executable không có quyền thực thi thì hãy dùng lệnh chmod +x ./VNULIB-Downloader*

2️⃣ Sử dụng

Important

Cần cài đặt trình duyệt Chrome hoặc Chromium (cần cho Selenium Webdriver)

Có thể dùng phương pháp 📦 Docker để không cần phải cài đặt Chrome hoặc Chromium

  1. Mở tool
  2. Input
VARIABLE VALUE DEFAULT DESCRIPTION EXAMPLE
USERNAME string Username tài khoản 1500023520000
PASSWORD string Password tài khoản examplePass
LINKS string string ... Link ảnh trang sách
(Có thể nhiều sách, cách nhau bằng khoảng cách)
link_1 link_2
TIMEOUT int 20 Timeout (s) khi sử dụng Selenium và request lấy mỗi ảnh từ server 20
BROWSER chrome,
path/to/local/chrome_driver
chrome Trình duyệt để sử dụng Selenium Webdriver khi có cần xử lý book, preview chrome
HEADLESS? y, n, ... y Selenium Webdriver headless mode y
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/
  • Kiểm tra log tại ./log/
  • Trong quá trình tải ảnh của sách, nếu quá thời gian TIMEOUT thì trang sẽ huỷ tải, thay bằng ảnh error

Tip

  • Khi có >= 1 link là book / preview: Tool sẽ sử dụng Selenium Webdriver để xử lý, cần phải dùng tài khoản thư viện để login
  • Trái lại, khi toàn bộ link là page: Tool không cần dùng Selenium Webdriver, nên USERNAME, PASSWORD, BROSWER, HEADLESS không còn quan trọng (nhập bừa / để trống)
  • 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ÂNG CAO

Note

Thứ tự ưu tiên giá trị biến: arguments > config.yml > user input

🗃️ Pre-config

  • Để không phải nhập input mỗi lần chạy
  1. Tạo file config.yml bằng 1 trong 2 cách:
    • Chạy trước tool 1 lần sẽ tự tạo file config.yml
    • Copy nội dung của file config-sample.yml và paste vào file config.yml
  2. Chỉnh config.yml

⛏️ Command line arguments

  • Windows:
    .\VNULIB-Downloader-windows.exe --help
  • Mac OS:
    ./VNULIB-Downloader-macos --help
  • Linux:
    ./VNULIB-Downloader-linux --help
  • Ví dụ (Windows):
    .\VNULIB-Downloader-windows.exe --link "link1" "link2" --username "1500023520000" --password "examplePass" --browser "./chrome_driver.exe" --headless --create-pdf --clean-imgs

📦 Docker

  • bash, zsh, powershell
    docker run -it --rm -v "$(pwd)/Downloads/:/app/Downloads/" kevinnitro/vnulib-downloader
  • cmd
    docker run -it --rm -v %CD%/Downloads/:/app/Downloads/ kevinnitro/vnulib-downloader

Note

  • Chỉ chạy theo kiểu user input
  • Tải chạy docker image kevinnitro/vnulib-donwloader từ DockerHub
  • File sách tải về sẽ được lưu ở ./Downloads/ (folder hiện tại / Downloads)
  • Tự động xoá container sau khi chạy

🤐 Python

  1. Install Python

  2. Clone repo

    git clone "https://github.com/KevinNitroG/VNULIB-Downloader" --depth 1 --filter=blob:none
  3. Create virtual environment (optional)

    • Create virtual environment
      python -m venv .venv
    • Active virtual environment
      • For Windows
        .venv\Scripts\activate
      • For Mac / Linux
        source .venv/bin/activate
    • Deactive virtual environment
      deactivate
  4. Install requirements

    pip install -r requirements/requirements.txt
  5. Run tool

    python main.py

Note

Linux / Mac hãy thử pip3python3 nếu pippython không chạy


🤔 NOTES

Giải thích thuật ngữ

TERM EXPLANTION EXAMPLE
book Link của sách https://ir.vnulib.edu.vn/handle/VNUHCM/8108
preview Preview link của sách https://ir.vnulib.edu.vn/flowpaper/?bitsid=4e5aa1b6-d1fb-4478-9740-ad9a8558ee62
or
https://ir.vnulib.edu.vn/flowpaper/simple_document.php?subfolder=69/37/45/&doc=69374546227582323703697992942653251709&bitsid=4e5aa1b6-d1fb-4478-9740-ad9a8558ee62&uid=63a80468-b67g-4ab0-855b-f4df246b123iy
page Link ảnh của 1 trang sách https://ir.vnulib.edu.vn/flowpaper/services/view.php?doc=69374546227582323703697992942653251709&format=jpg&page=1&subfolder=69/37/45/
Selenium Webdriver Hỗ trợ automation bằng trình duyệt -
headless Khi chạy trình duyệt sẽ không hiện ra thành cửa sổ, chỉ ẩn dưới nền -
Multithreading Đa luồng -
Multiprocessing Đa xử lý -

Note

  • Download các ảnh cho lần lượt từng link. 1 link sẽ có nhiều ảnh. Multithreading để tải các ảnh của 1 sách đồng thời (concurrent)
  • Merge song song từng folder thành PDF, phụ thuộc vào số nhân CPU (parallel)

👨‍💻 DEVELOP / CONTRIBUTE

TYPE NAME NOTE
LSP Pylance / Pyright Use either Pylance or Pyright
Linter Ruff Include Isort rules
Formatter Ruff
Formatter Prettier -
Docstring Google - Ex 1
- Ex 2
Package Manager Pip Need specifying dependencies' versions
Commit message Gitmoji I have messed up the commit messages 🥴
End of line LF -

Note

Use Google's docstring format with always noting the types of variables even they are in parameters of functions / methods


📓 TODO

  • Docker version, auto build and push
  • Support more browsers (inherited from which class?)
  • Options to enable Multithreading, Multiprocessing
  • Update tool option using command line arguments
  • Merge PDF for book which has multiple files

Cần người có lòng hảo tâm contribute 🫠


📝 LICENSE

License: MIT


🤥 DISCLAIMER

Dự án không dưới quyền VNULIB hay bất kì tổ chức nào khác. Dự án chỉ mang tính học tập (thực hành, làm việc nhóm, sử dụng ngôn ngữ lập trình, tổ chức một dự án, sử dụng Git, Github, CI/CD), không có mục đích thương mại, phá hoại (DDOS,...). Xin hãy tuân thủ luật sở hữu trí tuệ, không in ấn có tổ chức,... Chúng tôi không chịu trách nhiệm cho bất kì kết quả và hậu quả nào của việc sử dụng tool.


😌 CREDIT


⭐ STARGAZER

Star History Chart