mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-04-28 11:15:54 +08:00
Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
novels/
|
novels/
|
||||||
dist/
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
project_name: bilinovel-downloader
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- templ generate
|
|
||||||
builds:
|
|
||||||
- env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
goos:
|
|
||||||
- windows
|
|
||||||
- linux
|
|
||||||
- darwin
|
|
||||||
goarch:
|
|
||||||
- amd64
|
|
||||||
- arm64
|
|
||||||
- arm
|
|
||||||
- "386"
|
|
||||||
ldflags:
|
|
||||||
- -s -w -X bilinovel-downloader/cmd.Version={{ .Version }}
|
|
||||||
flags:
|
|
||||||
- -trimpath
|
|
||||||
archives:
|
|
||||||
- format: tar.gz
|
|
||||||
format_overrides:
|
|
||||||
- format: zip
|
|
||||||
goos: windows
|
|
||||||
wrap_in_directory: true
|
|
||||||
release:
|
|
||||||
draft: true
|
|
||||||
upx:
|
|
||||||
- enabled: true
|
|
||||||
compress: best
|
|
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -2,20 +2,12 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "volume",
|
"name": "Debug download 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"]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bilinovel-downloader/downloader/bilinovel"
|
"bilinovel-downloader/downloader"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var downloadCmd = &cobra.Command{
|
var downloadCmd = &cobra.Command{
|
||||||
Use: "download",
|
Use: "download",
|
||||||
Short: "Download a novel or volume",
|
|
||||||
Long: "Download a novel or volume",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadNovelCmd = &cobra.Command{
|
var downloadNovelCmd = &cobra.Command{
|
||||||
@ -60,7 +58,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 := bilinovel.DownloadNovel(novelArgs.NovelId, novelArgs.outputPath)
|
err := downloader.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 +73,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 := bilinovel.DownloadVolume(volumeArgs.NovelId, volumeArgs.VolumeId, volumeArgs.outputPath)
|
err := downloader.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/downloader/bilinovel"
|
"bilinovel-downloader/utils"
|
||||||
"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 := bilinovel.CreateEpub(pArgs.DirPath)
|
err := utils.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,22 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
Version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
|
||||||
Use: "version",
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("version: ", Version)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RootCmd.AddCommand(versionCmd)
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package bilinovel
|
package downloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bilinovel-downloader/model"
|
"bilinovel-downloader/model"
|
||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"bilinovel-downloader/utils"
|
"bilinovel-downloader/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -42,7 +41,6 @@ func GetNovel(novelId int) (*model.Novel, error) {
|
|||||||
|
|
||||||
novel.Title = strings.TrimSpace(doc.Find(".book-title").First().Text())
|
novel.Title = strings.TrimSpace(doc.Find(".book-title").First().Text())
|
||||||
novel.Description = strings.TrimSpace(doc.Find(".book-summary>content").First().Text())
|
novel.Description = strings.TrimSpace(doc.Find(".book-summary>content").First().Text())
|
||||||
novel.Id = novelId
|
|
||||||
|
|
||||||
doc.Find(".authorname>a").Each(func(i int, s *goquery.Selection) {
|
doc.Find(".authorname>a").Each(func(i int, s *goquery.Selection) {
|
||||||
novel.Authors = append(novel.Authors, strings.TrimSpace(s.Text()))
|
novel.Authors = append(novel.Authors, strings.TrimSpace(s.Text()))
|
||||||
@ -51,7 +49,7 @@ func GetNovel(novelId int) (*model.Novel, error) {
|
|||||||
novel.Authors = append(novel.Authors, strings.TrimSpace(s.Text()))
|
novel.Authors = append(novel.Authors, strings.TrimSpace(s.Text()))
|
||||||
})
|
})
|
||||||
|
|
||||||
volumes, err := getNovelVolumes(novelId)
|
volumes, err := GetNovelVolumes(novelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get novel volumes: %v", err)
|
return nil, fmt.Errorf("failed to get novel volumes: %v", err)
|
||||||
}
|
}
|
||||||
@ -61,7 +59,7 @@ func GetNovel(novelId int) (*model.Novel, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetVolume(novelId int, volumeId int) (*model.Volume, error) {
|
func GetVolume(novelId int, volumeId int) (*model.Volume, error) {
|
||||||
novelUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/catalog", novelId)
|
novelUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/vol_%v.html", novelId, volumeId)
|
||||||
resp, err := utils.Request().Get(novelUrl)
|
resp, err := utils.Request().Get(novelUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get novel info: %v", err)
|
return nil, fmt.Errorf("failed to get novel info: %v", err)
|
||||||
@ -75,42 +73,11 @@ func GetVolume(novelId int, volumeId int) (*model.Volume, error) {
|
|||||||
return nil, fmt.Errorf("failed to parse html: %v", err)
|
return nil, fmt.Errorf("failed to parse html: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
seriesIdx := 0
|
|
||||||
doc.Find("a.volume-cover-img").Each(func(i int, s *goquery.Selection) {
|
|
||||||
if s.AttrOr("href", "") == fmt.Sprintf("/novel/%v/vol_%v.html", novelId, volumeId) {
|
|
||||||
seriesIdx = i + 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
novelTitle := strings.TrimSpace(doc.Find(".book-title").First().Text())
|
|
||||||
|
|
||||||
if seriesIdx == 0 {
|
|
||||||
return nil, fmt.Errorf("volume not found: %v", volumeId)
|
|
||||||
}
|
|
||||||
|
|
||||||
volumeUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/vol_%v.html", novelId, volumeId)
|
|
||||||
resp, err = utils.Request().Get(volumeUrl)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get novel info: %v", err)
|
|
||||||
}
|
|
||||||
if resp.StatusCode() != http.StatusOK {
|
|
||||||
return nil, fmt.Errorf("failed to get novel info: %v", resp.Status())
|
|
||||||
}
|
|
||||||
|
|
||||||
doc, err = goquery.NewDocumentFromReader(bytes.NewReader(resp.Body()))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse html: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
volume := &model.Volume{}
|
volume := &model.Volume{}
|
||||||
volume.NovelId = novelId
|
|
||||||
volume.NovelTitle = novelTitle
|
|
||||||
volume.Id = volumeId
|
|
||||||
volume.SeriesIdx = seriesIdx
|
|
||||||
volume.Title = strings.TrimSpace(doc.Find(".book-title").First().Text())
|
volume.Title = strings.TrimSpace(doc.Find(".book-title").First().Text())
|
||||||
volume.Description = strings.TrimSpace(doc.Find(".book-summary>content").First().Text())
|
volume.Description = strings.TrimSpace(doc.Find(".book-summary>content").First().Text())
|
||||||
volume.Cover = doc.Find(".book-cover").First().AttrOr("src", "")
|
volume.Cover = doc.Find(".book-cover").First().AttrOr("src", "")
|
||||||
volume.Url = volumeUrl
|
volume.Url = novelUrl
|
||||||
volume.Chapters = make([]*model.Chapter, 0)
|
volume.Chapters = make([]*model.Chapter, 0)
|
||||||
|
|
||||||
doc.Find(".authorname>a").Each(func(i int, s *goquery.Selection) {
|
doc.Find(".authorname>a").Each(func(i int, s *goquery.Selection) {
|
||||||
@ -130,7 +97,7 @@ func GetVolume(novelId int, volumeId int) (*model.Volume, error) {
|
|||||||
return volume, nil
|
return volume, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNovelVolumes(novelId int) ([]*model.Volume, error) {
|
func GetNovelVolumes(novelId int) ([]*model.Volume, error) {
|
||||||
catelogUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/catalog", novelId)
|
catelogUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/catalog", novelId)
|
||||||
resp, err := utils.Request().Get(catelogUrl)
|
resp, err := utils.Request().Get(catelogUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -157,7 +124,7 @@ func getNovelVolumes(novelId int) ([]*model.Volume, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
volumes := make([]*model.Volume, 0)
|
volumes := make([]*model.Volume, 0)
|
||||||
for i, volumeIdStr := range volumeIds {
|
for _, volumeIdStr := range volumeIds {
|
||||||
volumeId, err := strconv.Atoi(volumeIdStr)
|
volumeId, err := strconv.Atoi(volumeIdStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to convert volume id: %v", err)
|
return nil, fmt.Errorf("failed to convert volume id: %v", err)
|
||||||
@ -166,7 +133,6 @@ func getNovelVolumes(novelId int) ([]*model.Volume, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get volume info: %v", err)
|
return nil, fmt.Errorf("failed to get volume info: %v", err)
|
||||||
}
|
}
|
||||||
volume.SeriesIdx = i
|
|
||||||
volumes = append(volumes, volume)
|
volumes = append(volumes, volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,11 +253,6 @@ 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 {
|
||||||
@ -337,7 +298,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 = CreateEpub(outputPath)
|
err = utils.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)
|
||||||
}
|
}
|
||||||
@ -413,9 +374,6 @@ 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()
|
||||||
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 {
|
||||||
@ -429,12 +387,15 @@ func downloadChapterByPage(page, chapterIdx int, chapter *model.Chapter, outputP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := filepath.Join(imgSavePath, fmt.Sprintf("%03v%s", len(chapter.ImageFullPaths)+1, path.Ext(imgUrl)))
|
fileName := filepath.Join(imgSavePath, fmt.Sprintf("%03v%s", i+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,20 +491,12 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
Metas: []model.DublinCoreMeta{
|
Metas: []model.DublinCoreMeta{
|
||||||
{
|
{
|
||||||
Name: "cover",
|
Name: "cover",
|
||||||
Content: "images-cover" + path.Ext(volume.Cover),
|
Content: fmt.Sprintf("Images/cover%s", path.Ext(volume.Cover)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Property: "dcterms:modified",
|
Property: "dcterms:modified",
|
||||||
Value: time.Now().UTC().Format("2006-01-02T15:04:05Z"),
|
Value: time.Now().UTC().Format("2006-01-02T15:04:05Z"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "calibre:series",
|
|
||||||
Content: volume.NovelTitle,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "calibre:series_index",
|
|
||||||
Content: strconv.Itoa(volume.SeriesIdx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
manifest := &model.Manifest{
|
manifest := &model.Manifest{
|
||||||
@ -555,26 +508,21 @@ 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.xhtml",
|
ID: "cover",
|
||||||
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.xhtml",
|
ID: "contents",
|
||||||
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" + path.Ext(volume.Cover),
|
ID: "images-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.ttf",
|
|
||||||
Link: "Fonts/read.ttf",
|
|
||||||
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{
|
||||||
ID: path.Base(chapter.TextOEBPSPath),
|
ID: path.Base(chapter.TextOEBPSPath),
|
||||||
@ -666,23 +614,3 @@ func CreateTocNCX(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed read.ttf
|
|
||||||
var readTTF []byte
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.WriteFile(fontPath, readTTF, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to write font: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
Binary file not shown.
@ -11,20 +11,15 @@ type Chapter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Volume struct {
|
type Volume struct {
|
||||||
Id int
|
|
||||||
SeriesIdx int
|
|
||||||
Title string
|
Title string
|
||||||
Url string
|
Url string
|
||||||
Cover string
|
Cover string
|
||||||
Description string
|
Description string
|
||||||
Authors []string
|
Authors []string
|
||||||
Chapters []*Chapter
|
Chapters []*Chapter
|
||||||
NovelId int
|
|
||||||
NovelTitle string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Novel struct {
|
type Novel struct {
|
||||||
Id int
|
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
Authors []string
|
Authors []string
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
package bilinovel
|
package template
|
||||||
|
|
||||||
const StyleCSS = `
|
const StyleCSS = `
|
||||||
@font-face {
|
|
||||||
font-family: "MI LANTING";
|
|
||||||
src: url(../Fonts/read.ttf);
|
|
||||||
}
|
|
||||||
|
|
||||||
.read-font {
|
|
||||||
font-family: "MI LANTING", serif !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
body > div {
|
body > div {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 20px;
|
padding: 20px;
|
@ -1,16 +1,14 @@
|
|||||||
package bilinovel
|
package utils
|
||||||
|
|
||||||
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 {
|
||||||
@ -31,7 +29,7 @@ func CreateEpub(path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addStringToZip(zipWriter, "OEBPS/Styles/style.css", StyleCSS, zip.Deflate)
|
err = addStringToZip(zipWriter, "OEBPS/Styles/style.css", template.StyleCSS, zip.Deflate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -83,9 +81,6 @@ 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
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user