You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
// -------------------- 配置常量 --------------------
|
|
const (
|
|
Concurrency = 20 // 并发页数
|
|
MaxPage = 100 // 单专辑最大翻页
|
|
RetryPerPage = 5 // 单页重试次数
|
|
Timeout = 10 // 请求超时(秒)
|
|
ImgSelector = "#gdt" // 图片入口区域选择器(用于参考,实际用正则)
|
|
FailedRecordUrl = "failed_keys.json"
|
|
DownloadsDir = "downloads"
|
|
TargetsFile = "targets.txt"
|
|
RetryPerImg = 5 // 单图重试次数
|
|
FailedRecordImg = "failed_downloads.json"
|
|
DownloadDir = "downloads"
|
|
)
|
|
|
|
// -------------------- HTTP客户端 --------------------
|
|
func createHTTPClient(proxy string) *http.Client {
|
|
if proxy == "" {
|
|
return &http.Client{
|
|
Timeout: time.Duration(Timeout) * time.Second,
|
|
}
|
|
}
|
|
|
|
proxyURL, err := url.Parse(proxy)
|
|
if err != nil {
|
|
log.Fatalf("解析代理地址失败: %v", err)
|
|
}
|
|
|
|
transport := &http.Transport{
|
|
Proxy: http.ProxyURL(proxyURL),
|
|
}
|
|
|
|
return &http.Client{
|
|
Transport: transport,
|
|
Timeout: time.Duration(Timeout) * time.Second,
|
|
}
|
|
}
|
|
|