mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-06-04 09:35:00 +08:00
Compare commits
2 Commits
6028e7d8c2
...
0c746c984b
Author | SHA1 | Date | |
---|---|---|---|
0c746c984b | |||
9d1d3f0f17 |
@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bilinovel-downloader/downloader"
|
||||
"bilinovel-downloader/downloader/bilinovel"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -60,7 +60,7 @@ func runDownloadNovel(cmd *cobra.Command, args []string) error {
|
||||
if novelArgs.NovelId == 0 {
|
||||
return fmt.Errorf("novel id is required")
|
||||
}
|
||||
err := downloader.DownloadNovel(novelArgs.NovelId, novelArgs.outputPath)
|
||||
err := bilinovel.DownloadNovel(novelArgs.NovelId, novelArgs.outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download novel: %v", err)
|
||||
}
|
||||
@ -75,7 +75,7 @@ func runDownloadVolume(cmd *cobra.Command, args []string) error {
|
||||
if volumeArgs.VolumeId == 0 {
|
||||
return fmt.Errorf("volume id is required")
|
||||
}
|
||||
err := downloader.DownloadVolume(volumeArgs.NovelId, volumeArgs.VolumeId, volumeArgs.outputPath)
|
||||
err := bilinovel.DownloadVolume(volumeArgs.NovelId, volumeArgs.VolumeId, volumeArgs.outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download volume: %v", err)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bilinovel-downloader/utils"
|
||||
"bilinovel-downloader/downloader/bilinovel"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -28,7 +28,7 @@ func init() {
|
||||
}
|
||||
|
||||
func runPackage(cmd *cobra.Command, args []string) error {
|
||||
err := utils.CreateEpub(pArgs.DirPath)
|
||||
err := bilinovel.CreateEpub(pArgs.DirPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create epub: %v", err)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package downloader
|
||||
package bilinovel
|
||||
|
||||
import (
|
||||
"bilinovel-downloader/model"
|
||||
@ -286,6 +286,11 @@ func downloadVolume(volume *model.Volume, outputPath string) error {
|
||||
return fmt.Errorf("failed to render cover: %v", err)
|
||||
}
|
||||
|
||||
err = DownloadFont(filepath.Join(outputPath, "OEBPS/Fonts"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download font: %v", err)
|
||||
}
|
||||
|
||||
contentsXHTMLPath := filepath.Join(outputPath, "OEBPS/Text/contents.xhtml")
|
||||
err = os.MkdirAll(path.Dir(contentsXHTMLPath), 0755)
|
||||
if err != nil {
|
||||
@ -331,7 +336,7 @@ func downloadVolume(volume *model.Volume, outputPath string) error {
|
||||
return fmt.Errorf("failed to create toc ncx: %v", err)
|
||||
}
|
||||
|
||||
err = utils.CreateEpub(outputPath)
|
||||
err = CreateEpub(outputPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create epub: %v", err)
|
||||
}
|
||||
@ -407,6 +412,7 @@ 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")
|
||||
|
||||
content.Find("img").Each(func(i int, s *goquery.Selection) {
|
||||
if err != nil {
|
||||
@ -549,21 +555,26 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
||||
Media: "application/x-dtbncx+xml",
|
||||
})
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
ID: "cover",
|
||||
ID: "cover.xhtml",
|
||||
Link: "Text/cover.xhtml",
|
||||
Media: "application/xhtml+xml",
|
||||
})
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
ID: "contents",
|
||||
ID: "contents.xhtml",
|
||||
Link: "Text/contents.xhtml",
|
||||
Media: "application/xhtml+xml",
|
||||
Properties: "nav",
|
||||
})
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
ID: "images-cover",
|
||||
ID: "images-cover" + path.Ext(volume.Cover),
|
||||
Link: fmt.Sprintf("Images/cover%s", path.Ext(volume.Cover)),
|
||||
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",
|
||||
})
|
||||
for _, chapter := range volume.Chapters {
|
||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||
ID: path.Base(chapter.TextOEBPSPath),
|
||||
@ -655,3 +666,24 @@ func CreateTocNCX(dirPath string, uuid string, volume *model.Volume) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DownloadFont(outputPath string) error {
|
||||
log.Printf("Downloading Font: read.woff2")
|
||||
|
||||
fontPath := filepath.Join(outputPath, "read.woff2")
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write font: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
package utils
|
||||
package bilinovel
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bilinovel-downloader/template"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func CreateEpub(path string) error {
|
||||
log.Printf("Creating epub for %s", path)
|
||||
|
||||
savePath := path + ".epub"
|
||||
zipFile, err := os.Create(savePath)
|
||||
if err != nil {
|
||||
@ -29,7 +31,7 @@ func CreateEpub(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = addStringToZip(zipWriter, "OEBPS/Styles/style.css", template.StyleCSS, zip.Deflate)
|
||||
err = addStringToZip(zipWriter, "OEBPS/Styles/style.css", StyleCSS, zip.Deflate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
@ -1,6 +1,15 @@
|
||||
package template
|
||||
package bilinovel
|
||||
|
||||
const StyleCSS = `
|
||||
@font-face{
|
||||
font-family: "read";
|
||||
src: url(../Fonts/read.woff2);
|
||||
}
|
||||
|
||||
.read-font{
|
||||
font-family: "read" !important;
|
||||
}
|
||||
|
||||
body > div {
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
Loading…
x
Reference in New Issue
Block a user