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