mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-10-26 01:01:35 +00:00
This commit introduces new features for controlling the download process: - **Concurrency**: Users can now specify the number of concurrent volume downloads using the `--concurrency` flag. This significantly speeds up the download of entire novels. - **Headless Mode**: A `--headless` flag has been added to control whether the browser operates in headless mode (without a visible UI). This is useful for debugging or running in environments without a display. **Changes include:** - Updated `download` command to accept `--concurrency` and `--headless` flags. - Refactored `bilinovel` downloader to support `BilinovelNewOption` for configuring headless mode and concurrency. - Implemented a page pool and concurrency control mechanism within the `bilinovel` downloader to manage concurrent browser page usage. - Added `DownloadNovel` and `DownloadVolume` methods to the `bilinovel` downloader, utilizing goroutines and wait groups for parallel processing. - Updated `.vscode/launch.json` with new configurations for testing novel and volume downloads with the new options.
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package test
|
|
|
|
import (
|
|
"bilinovel-downloader/downloader/bilinovel"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestBilinovel_GetNovel(t *testing.T) {
|
|
bilinovel, err := bilinovel.New(bilinovel.BilinovelNewOption{Headless: false, Concurrency: 5})
|
|
bilinovel.SetTextOnly(true)
|
|
if err != nil {
|
|
t.Fatalf("failed to create bilinovel: %v", err)
|
|
}
|
|
novel, err := bilinovel.GetNovel(2727, false, nil)
|
|
if err != nil {
|
|
t.Fatalf("failed to get novel: %v", err)
|
|
}
|
|
jsonBytes, err := json.Marshal(novel)
|
|
if err != nil {
|
|
t.Fatalf("failed to marshal novel: %v", err)
|
|
}
|
|
fmt.Println(string(jsonBytes))
|
|
}
|
|
|
|
func TestBilinovel_GetVolume(t *testing.T) {
|
|
bilinovel, err := bilinovel.New(bilinovel.BilinovelNewOption{Headless: false, Concurrency: 1})
|
|
bilinovel.SetTextOnly(true)
|
|
if err != nil {
|
|
t.Fatalf("failed to create bilinovel: %v", err)
|
|
}
|
|
volume, err := bilinovel.GetVolume(2727, 129092, false)
|
|
if err != nil {
|
|
t.Fatalf("failed to get volume: %v", err)
|
|
}
|
|
jsonBytes, err := json.Marshal(volume)
|
|
if err != nil {
|
|
t.Fatalf("failed to marshal volume: %v", err)
|
|
}
|
|
fmt.Println(string(jsonBytes))
|
|
}
|
|
|
|
func TestBilinovel_GetChapter(t *testing.T) {
|
|
bilinovel, err := bilinovel.New(bilinovel.BilinovelNewOption{Headless: false, Concurrency: 1})
|
|
bilinovel.SetTextOnly(true)
|
|
if err != nil {
|
|
t.Fatalf("failed to create bilinovel: %v", err)
|
|
}
|
|
chapter, err := bilinovel.GetChapter(2727, 129092, 129094)
|
|
if err != nil {
|
|
t.Fatalf("failed to get chapter: %v", err)
|
|
}
|
|
jsonBytes, err := json.Marshal(chapter)
|
|
if err != nil {
|
|
t.Fatalf("failed to marshal chapter: %v", err)
|
|
}
|
|
fmt.Println(string(jsonBytes))
|
|
}
|