Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
💥 add docker, chromium support, version style change
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Jun 7, 2024
1 parent f6d2d7a commit 308ef33
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 11 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Docker

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "v*"

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: build
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: kevinnitro/vnulib-downloader

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- src/constants.py
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
prepare:
name: prepare
Expand Down
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.12.3-alpine

LABEL authors="KevinNitro <[email protected]>"
LABEL name="VNULIB Downloader"
LABEL repository="https://github.com/KevinNitroG/VNULIB-Downloader"
LABEL latest=true

WORKDIR /app

COPY requirements/requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

COPY assets/images/error_page.jpg /app/assets/images/
COPY assets/utils/ascii_banner.txt /app/assets/utils/
COPY config-docker.yml /app/config.yml

COPY main.py /app/
COPY src/ /app/src/

RUN apk update
RUN apk add chromium
RUN apk add chromium-chromedriver

CMD ["python", "main.py"]
17 changes: 17 additions & 0 deletions config-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CONFIG FILE FOR RUNNING DOCKER

USERNAME:

PASSWORD:

LINKS:

TIMEOUT:

BROWSER: /usr/bin/chromedriver

HEADLESS: true

CREATE_PDF:

CLEAN_IMG:
2 changes: 1 addition & 1 deletion config-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LINKS:
TIMEOUT:

# Browser you are using (to use Selenium webdriver)
# Options: "chrome", "path/to/local/google_chromedriver" (google chromedriver only)
# Options: "chrome", "chromium", "path/to/local/google_chromedriver" (google chromedriver only)
# Ex: BROSWER: chrome
BROWSER:

Expand Down
24 changes: 17 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Python CLI tool download sách từ <strong>VNULIB</strong>
- [⚙️ 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ữ)
Expand Down Expand Up @@ -110,7 +111,7 @@ Python CLI tool download sách từ <strong>VNULIB</strong>

> [!IMPORTANT]
>
> Cần cài đặt trình duyệt [Chrome](https://www.google.com/chrome/) _(cần cho Selenium Webdriver)_
> Cần cài đặt trình duyệt [Chrome](https://www.google.com/chrome/) hoặc Chromium _(cần cho Selenium Webdriver)_
1. Mở tool
2. Input
Expand Down Expand Up @@ -153,11 +154,6 @@ Python CLI tool download sách từ <strong>VNULIB</strong>

## ⚙️ NÂNG CAO

- Có thể chạy tool theo các cách:
- [Pre config](#️-pre-config)
- [Command line arguments](#️-command-line-arguments)
- [Python](#-python)

> [!NOTE]
>
> Thứ tự ưu tiên giá trị biến: `arguments` > `config.yml` > `user input`
Expand Down Expand Up @@ -188,9 +184,22 @@ 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 "./chrome_driver.exe" --headless --create-pdf --clean-imgs
```

### 📦 Docker

- Có thể tải và sử dụng thông qua docker image _(chỉ chạy theo kiểu `user input`)_
```sh
docker run -it --rm -v "$(pwd)/Downloads/:/app/Downloads/" kevinnitro/vnulib-downloader
```

> [!NOTE]
>
> - Tải chạy docker image [`kevinnitro/vnulib-donwloader`](https://hub.docker.com/r/kevinnitro/vnulib-downloader) từ dockerhub
> - File tải về sẽ được lưu ở `./Downloads/`
> - Tự động xoá image sau khi chạy
### 🤐 Python

1. Install [Python](https://www.python.org/downloads/)
Expand Down Expand Up @@ -278,6 +287,7 @@ Python CLI tool download sách từ <strong>VNULIB</strong>

## 📓 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
Expand Down
11 changes: 11 additions & 0 deletions src/bot/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType

from src.constants import BROWSER_ARGUMENTS

Expand Down Expand Up @@ -42,6 +43,8 @@ def __enter__(self) -> WebDriver:
match self._browser.strip():
case "chrome" | "":
self.driver = self._setup_chrome_browser()
case "chromium":
self.driver = self._setup_chromium_browser()
case _:
self.driver = self._setup_local_chrome_browser()
self.driver.implicitly_wait(self._timeout)
Expand Down Expand Up @@ -69,6 +72,14 @@ def _setup_chrome_browser(self) -> WebDriver:
"""
return webdriver.Chrome(options=self._options, service=Service(ChromeDriverManager().install()))

def _setup_chromium_browser(self) -> WebDriver:
"""Setup Chromium Browser.
Returns:
WebDriver: Selenium WebDriver.
"""
return webdriver.Chrome(options=self._options, service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))

def _setup_local_chrome_browser(self) -> WebDriver:
"""Setup Local Chrome Browser.
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
BUNDLE_DIR = ""


VERSION: str = "1.17.1"
VERSION: str = "v1.17.2"
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
4 changes: 2 additions & 2 deletions src/modules/user_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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 Expand Up @@ -220,7 +220,7 @@ def _setup_clean_img(self) -> bool:
self._log_set_by_config("clean_img")
return self._config["CLEAN_IMG"]
self._log_set_by_user_input("clean_img")
return input("Create images of book(s) after being merged into PDF [y/N]: ").strip().upper() in USER_INPUT_NO
return input("Clean images of book(s) after being merged into PDF [y/N]: ").strip().upper() in USER_INPUT_NO

@staticmethod
def _log_set_by_argparse(var: str) -> None:
Expand Down

0 comments on commit 308ef33

Please sign in to comment.