mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-04-27 18:55:55 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c9a7853cef | |||
b2130f60d5 | |||
d80c6053ab | |||
0c746c984b |
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -2,12 +2,20 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Debug download volume",
|
"name": "volume",
|
||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}",
|
"program": "${workspaceFolder}",
|
||||||
"args": ["download", "volume", "-n", "2013", "-v", "165880"]
|
"args": ["download", "volume", "-n", "2013", "-v", "165880"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "novel",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"args": ["download", "novel", "-n", "4325"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
55
a_test.go
55
a_test.go
@ -1,55 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
|
||||||
"golang.org/x/text/transform"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 尝试使用不同编码进行解码
|
|
||||||
func tryDecodeWithEncoding(data []byte, decoder transform.Transformer) (string, error) {
|
|
||||||
reader := transform.NewReader(bytes.NewReader(data), decoder)
|
|
||||||
decoded, err := io.ReadAll(reader)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(decoded), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测可能的编码
|
|
||||||
func detectEncoding(data []byte) {
|
|
||||||
// 尝试 GBK 解码
|
|
||||||
if result, err := tryDecodeWithEncoding(data, simplifiedchinese.GBK.NewDecoder()); err == nil {
|
|
||||||
fmt.Printf("可能是 GBK 编码: %s\n", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 尝试 GB18030 解码
|
|
||||||
if result, err := tryDecodeWithEncoding(data, simplifiedchinese.GB18030.NewDecoder()); err == nil {
|
|
||||||
fmt.Printf("可能是 GB18030 编码: %s\n", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 尝试 UTF-8 解码(直接输出)
|
|
||||||
fmt.Printf("原始 UTF-8 输出: %s\n", string(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestA(t *testing.T) {
|
|
||||||
chaos := "凳蹦戎昆储。"
|
|
||||||
body := []byte(chaos)
|
|
||||||
|
|
||||||
fmt.Println("尝试检测编码...")
|
|
||||||
detectEncoding(body)
|
|
||||||
|
|
||||||
// 使用 GBK 解码
|
|
||||||
reader := transform.NewReader(bytes.NewReader(body), simplifiedchinese.GBK.NewDecoder())
|
|
||||||
decoded, err := io.ReadAll(reader)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("解码失败: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("GBK 解码结果:", string(decoded))
|
|
||||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||||||
"bilinovel-downloader/utils"
|
"bilinovel-downloader/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -412,7 +413,9 @@ func downloadChapterByPage(page, chapterIdx int, chapter *model.Chapter, outputP
|
|||||||
content.Find(".cgo").Remove()
|
content.Find(".cgo").Remove()
|
||||||
content.Find("center").Remove()
|
content.Find("center").Remove()
|
||||||
content.Find(".google-auto-placed").Remove()
|
content.Find(".google-auto-placed").Remove()
|
||||||
content.Find("p").Last().AddClass("read-font")
|
if strings.Contains(resp.String(), `font-family: "read"`) {
|
||||||
|
content.Find("p").Last().AddClass("read-font")
|
||||||
|
}
|
||||||
|
|
||||||
content.Find("img").Each(func(i int, s *goquery.Selection) {
|
content.Find("img").Each(func(i int, s *goquery.Selection) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -426,15 +429,12 @@ func downloadChapterByPage(page, chapterIdx int, chapter *model.Chapter, outputP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := filepath.Join(imgSavePath, fmt.Sprintf("%03v%s", i+1, path.Ext(imgUrl)))
|
fileName := filepath.Join(imgSavePath, fmt.Sprintf("%03v%s", len(chapter.ImageFullPaths)+1, path.Ext(imgUrl)))
|
||||||
err = DownloadImg(imgUrl, filepath.Join(outputPath, fileName))
|
err = DownloadImg(imgUrl, filepath.Join(outputPath, fileName))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
s.SetAttr("src", "../"+strings.TrimPrefix(fileName, "OEBPS/"))
|
s.SetAttr("src", "../"+strings.TrimPrefix(fileName, "OEBPS/"))
|
||||||
s.RemoveAttr("class")
|
s.RemoveAttr("class")
|
||||||
s.RemoveAttr("data-src")
|
s.RemoveAttr("data-src")
|
||||||
if s.AttrOr("alt", "") == "" {
|
|
||||||
s.SetAttr("alt", fmt.Sprintf("image-%03d", i+1))
|
|
||||||
}
|
|
||||||
chapter.ImageFullPaths = append(chapter.ImageFullPaths, filepath.Join(outputPath, fileName))
|
chapter.ImageFullPaths = append(chapter.ImageFullPaths, filepath.Join(outputPath, fileName))
|
||||||
chapter.ImageOEBPSPaths = append(chapter.ImageOEBPSPaths, strings.TrimPrefix(fileName, "OEBPS/"))
|
chapter.ImageOEBPSPaths = append(chapter.ImageOEBPSPaths, strings.TrimPrefix(fileName, "OEBPS/"))
|
||||||
}
|
}
|
||||||
@ -530,7 +530,7 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
Metas: []model.DublinCoreMeta{
|
Metas: []model.DublinCoreMeta{
|
||||||
{
|
{
|
||||||
Name: "cover",
|
Name: "cover",
|
||||||
Content: fmt.Sprintf("Images/cover%s", path.Ext(volume.Cover)),
|
Content: "images-cover" + path.Ext(volume.Cover),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Property: "dcterms:modified",
|
Property: "dcterms:modified",
|
||||||
@ -571,9 +571,9 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
Media: fmt.Sprintf("image/%s", strings.ReplaceAll(strings.TrimPrefix(path.Ext(volume.Cover), "."), "jpg", "jpeg")),
|
Media: fmt.Sprintf("image/%s", strings.ReplaceAll(strings.TrimPrefix(path.Ext(volume.Cover), "."), "jpg", "jpeg")),
|
||||||
})
|
})
|
||||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||||
ID: "read.woff2",
|
ID: "read.ttf",
|
||||||
Link: "Fonts/read.woff2",
|
Link: "Fonts/read.ttf",
|
||||||
Media: "font/woff2",
|
Media: "application/vnd.ms-opentype",
|
||||||
})
|
})
|
||||||
for _, chapter := range volume.Chapters {
|
for _, chapter := range volume.Chapters {
|
||||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||||
@ -667,20 +667,19 @@ func CreateTocNCX(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFont(outputPath string) error {
|
//go:embed read.ttf
|
||||||
log.Printf("Downloading Font: read.woff2")
|
var readTTF []byte
|
||||||
|
|
||||||
fontPath := filepath.Join(outputPath, "read.woff2")
|
func DownloadFont(outputPath string) error {
|
||||||
|
log.Printf("Writing Font: %s", outputPath)
|
||||||
|
|
||||||
|
fontPath := filepath.Join(outputPath, "read.ttf")
|
||||||
err := os.MkdirAll(path.Dir(fontPath), 0755)
|
err := os.MkdirAll(path.Dir(fontPath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create font directory: %v", err)
|
return fmt.Errorf("failed to create font directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := utils.Request().Get("https://www.bilinovel.com/public/font/read.woff2")
|
err = os.WriteFile(fontPath, readTTF, 0644)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to download font: %v", err)
|
|
||||||
}
|
|
||||||
err = os.WriteFile(fontPath, resp.Body(), 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write font: %v", err)
|
return fmt.Errorf("failed to write font: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,9 @@ func addStringToZip(zipWriter *zip.Writer, relPath, content string, method uint1
|
|||||||
|
|
||||||
func addDirContentToZip(zipWriter *zip.Writer, dirPath string, method uint16) error {
|
func addDirContentToZip(zipWriter *zip.Writer, dirPath string, method uint16) error {
|
||||||
return filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error {
|
return filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error {
|
||||||
|
if filepath.Base(filePath) == "volume.json" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
BIN
downloader/bilinovel/read.ttf
Normal file
BIN
downloader/bilinovel/read.ttf
Normal file
Binary file not shown.
@ -1,13 +1,13 @@
|
|||||||
package bilinovel
|
package bilinovel
|
||||||
|
|
||||||
const StyleCSS = `
|
const StyleCSS = `
|
||||||
@font-face{
|
@font-face {
|
||||||
font-family: "read";
|
font-family: "MI LANTING";
|
||||||
src: url(../Fonts/read.woff2);
|
src: url(../Fonts/read.ttf);
|
||||||
}
|
}
|
||||||
|
|
||||||
.read-font{
|
.read-font {
|
||||||
font-family: "read" !important;
|
font-family: "MI LANTING", serif !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
body > div {
|
body > div {
|
||||||
|
1
go.mod
1
go.mod
@ -8,7 +8,6 @@ require (
|
|||||||
github.com/go-resty/resty/v2 v2.16.5
|
github.com/go-resty/resty/v2 v2.16.5
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
golang.org/x/text v0.24.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
2
go.sum
2
go.sum
@ -77,8 +77,6 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
|
||||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
|
||||||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user