1
0
mirror of https://github.com/bestnite/bilinovel-downloader.git synced 2025-12-13 09:50:15 +00:00

2 Commits

Author SHA1 Message Date
b2130f60d5 fix missing images 2025-04-20 21:44:28 +10:00
d80c6053ab fix font error 2025-04-20 21:34:52 +10:00
4 changed files with 21 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import (
"bilinovel-downloader/utils" "bilinovel-downloader/utils"
"bytes" "bytes"
"context" "context"
_ "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
@@ -426,15 +427,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 +528,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 +569,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 +665,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)
} }

View File

@@ -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
} }

Binary file not shown.

View File

@@ -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 {