mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-12-13 09:50:15 +00:00
Compare commits
3 Commits
0c746c984b
...
v0.0.7
| Author | SHA1 | Date | |
|---|---|---|---|
| c9a7853cef | |||
| b2130f60d5 | |||
| d80c6053ab |
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@@ -2,12 +2,20 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug download volume",
|
||||
"name": "volume",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}",
|
||||
"args": ["download", "volume", "-n", "2013", "-v", "165880"]
|
||||
},
|
||||
{
|
||||
"name": "novel",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}",
|
||||
"args": ["download", "novel", "-n", "4325"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"bilinovel-downloader/utils"
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -412,7 +413,9 @@ func downloadChapterByPage(page, chapterIdx int, chapter *model.Chapter, outputP
|
||||
content.Find(".cgo").Remove()
|
||||
content.Find("center").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) {
|
||||
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))
|
||||
if err == nil {
|
||||
s.SetAttr("src", "../"+strings.TrimPrefix(fileName, "OEBPS/"))
|
||||
s.RemoveAttr("class")
|
||||
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.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{
|
||||
{
|
||||
Name: "cover",
|
||||
Content: fmt.Sprintf("Images/cover%s", path.Ext(volume.Cover)),
|
||||
Content: "images-cover" + path.Ext(volume.Cover),
|
||||
},
|
||||
{
|
||||
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")),
|
||||
})
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
ID: "read.woff2",
|
||||
Link: "Fonts/read.woff2",
|
||||
Media: "font/woff2",
|
||||
ID: "read.ttf",
|
||||
Link: "Fonts/read.ttf",
|
||||
Media: "application/vnd.ms-opentype",
|
||||
})
|
||||
for _, chapter := range volume.Chapters {
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
@@ -667,20 +667,19 @@ func CreateTocNCX(dirPath string, uuid string, volume *model.Volume) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownloadFont(outputPath string) error {
|
||||
log.Printf("Downloading Font: read.woff2")
|
||||
//go:embed read.ttf
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create font directory: %v", err)
|
||||
}
|
||||
|
||||
resp, err := utils.Request().Get("https://www.bilinovel.com/public/font/read.woff2")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download font: %v", err)
|
||||
}
|
||||
err = os.WriteFile(fontPath, resp.Body(), 0644)
|
||||
err = os.WriteFile(fontPath, readTTF, 0644)
|
||||
if err != nil {
|
||||
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 {
|
||||
return filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error {
|
||||
if filepath.Base(filePath) == "volume.json" {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
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
|
||||
|
||||
const StyleCSS = `
|
||||
@font-face{
|
||||
font-family: "read";
|
||||
src: url(../Fonts/read.woff2);
|
||||
@font-face {
|
||||
font-family: "MI LANTING";
|
||||
src: url(../Fonts/read.ttf);
|
||||
}
|
||||
|
||||
.read-font{
|
||||
font-family: "read" !important;
|
||||
.read-font {
|
||||
font-family: "MI LANTING", serif !important;
|
||||
}
|
||||
|
||||
body > div {
|
||||
|
||||
Reference in New Issue
Block a user