mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2025-10-26 17:14:24 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 75745b9431 | |||
| ca3fdf8980 | |||
| 042b383988 | |||
| c9a7853cef | |||
| b2130f60d5 | |||
| d80c6053ab | |||
| 0c746c984b | |||
| 9d1d3f0f17 | |||
| 6028e7d8c2 | |||
| 6076069338 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
novels/
|
novels/
|
||||||
|
dist/
|
||||||
|
|||||||
31
.goreleaser.yaml
Normal file
31
.goreleaser.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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
|
||||||
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
@@ -2,12 +2,20 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Debug download volume",
|
"name": "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", "2025", "-v", "72693"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "novel",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"args": ["download", "novel", "-n", "4325"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -1,24 +1,24 @@
|
|||||||
# BiliNovel Downloader
|
# Bilinovel Downloader
|
||||||
|
|
||||||
这是一个用于下载和生成轻小说 EPUB 电子书的工具。
|
这是一个用于从 Bilinovel 下载和生成轻小说 EPUB 电子书的工具。
|
||||||
|
生成的 EPUB 文件完全符合 EPUB 标准,可以在 Calibre 检查中无错误通过。
|
||||||
|
|
||||||
## 功能特点
|
## 使用示例
|
||||||
|
|
||||||
- 支持下载轻小说并转换为标准 EPUB 格式
|
1. 下载整本 `https://www.bilinovel.com/novel/2388.html`
|
||||||
- 自动处理图片和文本内容
|
|
||||||
- 生成符合 EPUB 3.0 规范的电子书文件
|
|
||||||
- 支持多章节内容的组织和管理
|
|
||||||
- 保留原有插图和排版格式
|
|
||||||
|
|
||||||
## 使用说明
|
```bash
|
||||||
|
bilinovel-downloader download novel -n 2388
|
||||||
|
```
|
||||||
|
|
||||||
1. 确保系统环境满足要求
|
2. 下载单卷 `https://www.bilinovel.com/novel/2388/vol_84522.html`
|
||||||
2. 运行下载器获取小说内容
|
|
||||||
3. 程序会自动处理并生成标准格式的 EPUB 文件
|
|
||||||
4. 生成的电子书文件可以在任何支持 EPUB 3.0 的阅读器中打开
|
|
||||||
|
|
||||||
## 注意事项
|
```bash
|
||||||
|
bilinovel-downloader download volume -n 2388 -v 84522
|
||||||
|
```
|
||||||
|
|
||||||
- 生成的 EPUB 文件严格遵循 EPUB 3.0 规范
|
3. 对自动生成的 epub 格式不满意可以自行修改后使用命令打包
|
||||||
- 建议使用支持 EPUB 3.0 的阅读器以获得最佳阅读体验
|
|
||||||
- 请遵守相关法律法规,合理使用下载的内容
|
```bash
|
||||||
|
bilinovel-downloader pack -d <目录路径>
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bilinovel-downloader/downloader"
|
"bilinovel-downloader/downloader/bilinovel"
|
||||||
"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{
|
||||||
@@ -58,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)
|
||||||
}
|
}
|
||||||
@@ -73,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)
|
||||||
}
|
}
|
||||||
|
|||||||
22
cmd/version.go
Normal file
22
cmd/version.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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 downloader
|
package bilinovel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bilinovel-downloader/model"
|
"bilinovel-downloader/model"
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"bilinovel-downloader/utils"
|
"bilinovel-downloader/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -41,6 +42,7 @@ 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()))
|
||||||
@@ -49,7 +51,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)
|
||||||
}
|
}
|
||||||
@@ -59,7 +61,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/vol_%v.html", novelId, volumeId)
|
novelUrl := fmt.Sprintf("https://www.bilinovel.com/novel/%v/catalog", novelId)
|
||||||
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)
|
||||||
@@ -73,11 +75,42 @@ 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 = novelUrl
|
volume.Url = volumeUrl
|
||||||
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) {
|
||||||
@@ -97,7 +130,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 {
|
||||||
@@ -124,7 +157,7 @@ func GetNovelVolumes(novelId int) ([]*model.Volume, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
volumes := make([]*model.Volume, 0)
|
volumes := make([]*model.Volume, 0)
|
||||||
for _, volumeIdStr := range volumeIds {
|
for i, 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)
|
||||||
@@ -133,6 +166,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +260,7 @@ func downloadVolume(volume *model.Volume, outputPath string) error {
|
|||||||
return fmt.Errorf("failed to write volume: %v", err)
|
return fmt.Errorf("failed to write volume: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
coverPath := filepath.Join(outputPath, "OEBPS/Images/cover.jpg")
|
coverPath := filepath.Join(outputPath, "cover.jpeg")
|
||||||
err = os.MkdirAll(path.Dir(coverPath), 0755)
|
err = os.MkdirAll(path.Dir(coverPath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create cover directory: %v", err)
|
return fmt.Errorf("failed to create cover directory: %v", err)
|
||||||
@@ -245,14 +279,16 @@ func downloadVolume(volume *model.Volume, outputPath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create cover file: %v", err)
|
return fmt.Errorf("failed to create cover file: %v", err)
|
||||||
}
|
}
|
||||||
err = template.ContentXHTML(&model.Chapter{
|
err = template.CoverXHTML(fmt.Sprintf(`../../cover%s`, strings.ReplaceAll(path.Ext(volume.Cover), "jpg", "jpeg"))).Render(context.Background(), file)
|
||||||
Title: "封面",
|
|
||||||
Content: fmt.Sprintf(`<img src="../Images/cover%s" />`, path.Ext(volume.Cover)),
|
|
||||||
}).Render(context.Background(), file)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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 {
|
||||||
@@ -293,12 +329,7 @@ func downloadVolume(volume *model.Volume, outputPath string) error {
|
|||||||
return fmt.Errorf("failed to create content opf: %v", err)
|
return fmt.Errorf("failed to create content opf: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CreateTocNCX(outputPath, u.String(), volume)
|
err = CreateEpub(outputPath)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create toc ncx: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
@@ -374,6 +405,9 @@ 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 {
|
||||||
@@ -387,15 +421,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/"))
|
||||||
}
|
}
|
||||||
@@ -479,7 +510,7 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
},
|
},
|
||||||
Languages: []model.DCLanguage{
|
Languages: []model.DCLanguage{
|
||||||
{
|
{
|
||||||
Value: "zh-TW",
|
Value: "zh-CN",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Descriptions: []model.DCDescription{
|
Descriptions: []model.DCDescription{
|
||||||
@@ -491,48 +522,57 @@ 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: "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{
|
||||||
Items: make([]model.ManifestItem, 0),
|
Items: make([]model.ManifestItem, 0),
|
||||||
}
|
}
|
||||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||||
ID: "ncx",
|
ID: "cover.xhtml",
|
||||||
Link: "toc.ncx",
|
Link: "OEBPS/Text/cover.xhtml",
|
||||||
Media: "application/x-dtbncx+xml",
|
|
||||||
})
|
|
||||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
|
||||||
ID: "cover",
|
|
||||||
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: "OEBPS/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: "cover",
|
||||||
Link: fmt.Sprintf("Images/cover%s", path.Ext(volume.Cover)),
|
Link: fmt.Sprintf("cover%s", strings.ReplaceAll(path.Ext(volume.Cover), "jpg", "jpeg")),
|
||||||
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")),
|
||||||
|
Properties: "cover-image",
|
||||||
|
})
|
||||||
|
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||||
|
ID: "read.ttf",
|
||||||
|
Link: "OEBPS/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),
|
||||||
Link: chapter.TextOEBPSPath,
|
Link: "OEBPS/" + chapter.TextOEBPSPath,
|
||||||
Media: "application/xhtml+xml",
|
Media: "application/xhtml+xml",
|
||||||
})
|
})
|
||||||
for _, image := range chapter.ImageOEBPSPaths {
|
for _, image := range chapter.ImageOEBPSPaths {
|
||||||
item := model.ManifestItem{
|
item := model.ManifestItem{
|
||||||
ID: strings.Join(strings.Split(strings.ToLower(image), string(filepath.Separator)), "-"),
|
ID: strings.Join(strings.Split(strings.ToLower(image), string(filepath.Separator)), "-"),
|
||||||
Link: image,
|
Link: "OEBPS/" + image,
|
||||||
}
|
}
|
||||||
item.Media = fmt.Sprintf("image/%s", strings.ReplaceAll(strings.TrimPrefix(path.Ext(volume.Cover), "."), "jpg", "jpeg"))
|
item.Media = fmt.Sprintf("image/%s", strings.ReplaceAll(strings.TrimPrefix(path.Ext(volume.Cover), "."), "jpg", "jpeg"))
|
||||||
manifest.Items = append(manifest.Items, item)
|
manifest.Items = append(manifest.Items, item)
|
||||||
@@ -540,7 +580,7 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
}
|
}
|
||||||
manifest.Items = append(manifest.Items, model.ManifestItem{
|
manifest.Items = append(manifest.Items, model.ManifestItem{
|
||||||
ID: "style",
|
ID: "style",
|
||||||
Link: "Styles/style.css",
|
Link: "style.css",
|
||||||
Media: "text/css",
|
Media: "text/css",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -554,7 +594,7 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
contentOPFPath := filepath.Join(dirPath, "OEBPS/content.opf")
|
contentOPFPath := filepath.Join(dirPath, "content.opf")
|
||||||
err := os.MkdirAll(path.Dir(contentOPFPath), 0755)
|
err := os.MkdirAll(path.Dir(contentOPFPath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create content directory: %v", err)
|
return fmt.Errorf("failed to create content directory: %v", err)
|
||||||
@@ -570,47 +610,22 @@ func CreateContentOPF(dirPath string, uuid string, volume *model.Volume) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTocNCX(dirPath string, uuid string, volume *model.Volume) error {
|
//go:embed read.ttf
|
||||||
navMap := &model.NavMap{Points: make([]*model.NavPoint, 0)}
|
var readTTF []byte
|
||||||
navMap.Points = append(navMap.Points, &model.NavPoint{
|
|
||||||
Id: "cover",
|
func DownloadFont(outputPath string) error {
|
||||||
PlayOrder: 1,
|
log.Printf("Writing Font: %s", outputPath)
|
||||||
Label: "封面",
|
|
||||||
Content: model.NavPointContent{Src: "Text/cover.xhtml"},
|
fontPath := filepath.Join(outputPath, "read.ttf")
|
||||||
})
|
err := os.MkdirAll(path.Dir(fontPath), 0755)
|
||||||
navMap.Points = append(navMap.Points, &model.NavPoint{
|
if err != nil {
|
||||||
Id: "contents",
|
return fmt.Errorf("failed to create font directory: %v", err)
|
||||||
PlayOrder: 2,
|
|
||||||
Label: "目录",
|
|
||||||
Content: model.NavPointContent{Src: "Text/contents.xhtml"},
|
|
||||||
})
|
|
||||||
for idx, chapter := range volume.Chapters {
|
|
||||||
navMap.Points = append(navMap.Points, &model.NavPoint{
|
|
||||||
Id: fmt.Sprintf("chapter-%03v", idx+1),
|
|
||||||
PlayOrder: len(navMap.Points) + 1,
|
|
||||||
Label: chapter.Title,
|
|
||||||
Content: model.NavPointContent{Src: chapter.TextOEBPSPath},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
head := &model.TocNCXHead{
|
err = os.WriteFile(fontPath, readTTF, 0644)
|
||||||
Meta: []model.TocNCXHeadMeta{
|
if err != nil {
|
||||||
{Name: "dtb:uid", Content: fmt.Sprintf("urn:uuid:%s", uuid)},
|
return fmt.Errorf("failed to write font: %v", err)
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ncxPath := filepath.Join(dirPath, "OEBPS/toc.ncx")
|
|
||||||
err := os.MkdirAll(path.Dir(ncxPath), 0755)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create toc directory: %v", err)
|
|
||||||
}
|
|
||||||
file, err := os.Create(ncxPath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create toc file: %v", err)
|
|
||||||
}
|
|
||||||
err = template.TocNCX(volume.Title, head, navMap).Render(context.Background(), file)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to render toc: %v", err)
|
|
||||||
}
|
|
||||||
return nil
|
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, "style.css", StyleCSS, zip.Deflate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -81,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
|
||||||
}
|
}
|
||||||
BIN
downloader/bilinovel/read.ttf
Normal file
BIN
downloader/bilinovel/read.ttf
Normal file
Binary file not shown.
@@ -1,6 +1,19 @@
|
|||||||
package template
|
package bilinovel
|
||||||
|
|
||||||
const StyleCSS = `
|
const StyleCSS = `
|
||||||
|
@font-face {
|
||||||
|
font-family: "MI LANTING";
|
||||||
|
src: url(OEBPS/Fonts/read.ttf);
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-font {
|
||||||
|
display: block;
|
||||||
|
font-family: "MI LANTING", serif;
|
||||||
|
font-size: 1.33333em;
|
||||||
|
text-indent: 2em;
|
||||||
|
margin: 0.8em 0;
|
||||||
|
}
|
||||||
|
|
||||||
body > div {
|
body > div {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.24.2
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/PuerkitoBio/goquery v1.10.3
|
github.com/PuerkitoBio/goquery v1.10.3
|
||||||
github.com/a-h/templ v0.3.857
|
github.com/a-h/templ v0.3.906
|
||||||
github.com/go-resty/resty/v2 v2.16.5
|
github.com/go-resty/resty/v2 v2.16.5
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -2,6 +2,8 @@ github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiU
|
|||||||
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
|
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
|
||||||
github.com/a-h/templ v0.3.857 h1:6EqcJuGZW4OL+2iZ3MD+NnIcG7nGkaQeF2Zq5kf9ZGg=
|
github.com/a-h/templ v0.3.857 h1:6EqcJuGZW4OL+2iZ3MD+NnIcG7nGkaQeF2Zq5kf9ZGg=
|
||||||
github.com/a-h/templ v0.3.857/go.mod h1:qhrhAkRFubE7khxLZHsBFHfX+gWwVNKbzKeF9GlPV4M=
|
github.com/a-h/templ v0.3.857/go.mod h1:qhrhAkRFubE7khxLZHsBFHfX+gWwVNKbzKeF9GlPV4M=
|
||||||
|
github.com/a-h/templ v0.3.906 h1:ZUThc8Q9n04UATaCwaG60pB1AqbulLmYEAMnWV63svg=
|
||||||
|
github.com/a-h/templ v0.3.906/go.mod h1:FFAu4dI//ESmEN7PQkJ7E7QfnSEMdcnu7QrAY8Dn334=
|
||||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
||||||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -2,11 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bilinovel-downloader/cmd"
|
"bilinovel-downloader/cmd"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := cmd.RootCmd.Execute(); err != nil {
|
_ = cmd.RootCmd.Execute()
|
||||||
log.Fatalf("Error executing command: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ type Spine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Spine) Marshal() (string, error) {
|
func (s *Spine) Marshal() (string, error) {
|
||||||
s.Toc = "ncx"
|
|
||||||
xmlBytes, err := xml.Marshal(s)
|
xmlBytes, err := xml.Marshal(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -11,15 +11,20 @@ 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,47 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "encoding/xml"
|
|
||||||
|
|
||||||
type TocNCXHead struct {
|
|
||||||
XMLName xml.Name `xml:"head"`
|
|
||||||
Meta []TocNCXHeadMeta `xml:"meta"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TocNCXHeadMeta struct {
|
|
||||||
XMLName xml.Name `xml:"meta"`
|
|
||||||
Content string `xml:"content,attr"`
|
|
||||||
Name string `xml:"name,attr"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *TocNCXHead) Marshal() (string, error) {
|
|
||||||
xmlBytes, err := xml.Marshal(h)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(xmlBytes), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type NavPoint struct {
|
|
||||||
Id string `xml:"id,attr"`
|
|
||||||
PlayOrder int `xml:"playOrder,attr"`
|
|
||||||
Label string `xml:"navLabel>text"`
|
|
||||||
Content NavPointContent `xml:"content"`
|
|
||||||
NavPoints []*NavPoint `xml:"navPoint"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NavPointContent struct {
|
|
||||||
Src string `xml:"src,attr"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NavMap struct {
|
|
||||||
XMLName xml.Name `xml:"navMap"`
|
|
||||||
Points []*NavPoint `xml:"navPoint"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *NavMap) Marshal() (string, error) {
|
|
||||||
xmlBytes, err := xml.Marshal(n)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(xmlBytes), nil
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package template
|
package template
|
||||||
|
|
||||||
templ ContainerXML() {
|
templ ContainerXML() {
|
||||||
@templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`)
|
@templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`)
|
||||||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
|
||||||
<rootfiles>
|
<rootfiles>
|
||||||
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"></rootfile>
|
<rootfile full-path="content.opf" media-type="application/oebps-package+xml"></rootfile>
|
||||||
</rootfiles>
|
</rootfiles>
|
||||||
</container>
|
</container>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.857
|
// templ: version: v0.3.906
|
||||||
package template
|
package template
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
@@ -29,11 +29,11 @@ func ContainerXML() templ.Component {
|
|||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<container version=\"1.0\" xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\"><rootfiles><rootfile full-path=\"OEBPS/content.opf\" media-type=\"application/oebps-package+xml\"></rootfile></rootfiles></container>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<container xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\" version=\"1.0\"><rootfiles><rootfile full-path=\"content.opf\" media-type=\"application/oebps-package+xml\"></rootfile></rootfiles></container>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package template
|
|||||||
import "bilinovel-downloader/model"
|
import "bilinovel-downloader/model"
|
||||||
|
|
||||||
templ ContentOPF(uniqueIdentifier string, dc *model.DublinCoreMetadata, manifest *model.Manifest, spine *model.Spine, guide *model.Guide) {
|
templ ContentOPF(uniqueIdentifier string, dc *model.DublinCoreMetadata, manifest *model.Manifest, spine *model.Spine, guide *model.Guide) {
|
||||||
@templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`)
|
@templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`)
|
||||||
<package version="3.0" xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" unique-identifier={ uniqueIdentifier }>
|
<package version="3.0" xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" unique-identifier={ uniqueIdentifier }>
|
||||||
if dc != nil {
|
if dc != nil {
|
||||||
{{ metadata, err := dc.Marshal() }}
|
{{ metadata, err := dc.Marshal() }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.857
|
// templ: version: v0.3.906
|
||||||
package template
|
package template
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
@@ -31,7 +31,7 @@ func ContentOPF(uniqueIdentifier string, dc *model.DublinCoreMetadata, manifest
|
|||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package template
|
|||||||
import "bilinovel-downloader/model"
|
import "bilinovel-downloader/model"
|
||||||
|
|
||||||
templ ContentXHTML(content *model.Chapter) {
|
templ ContentXHTML(content *model.Chapter) {
|
||||||
@templ.Raw(`<?xml version="1.0" encoding="utf-8" standalone="no"?>`)
|
@templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`)
|
||||||
@templ.Raw(`<!DOCTYPE html>`)
|
// @templ.Raw(`<!DOCTYPE html>`)
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:xml="http://www.w3.org/XML/1998/namespace">
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<title>{ content.Title }</title>
|
<title>{ content.Title }</title>
|
||||||
@templ.Raw(`<link href="../Styles/style.css" rel="stylesheet" type="text/css"/>`)
|
@templ.Raw(`<link href="../../style.css" rel="stylesheet" type="text/css"/>`)
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="chapter">
|
<div class="chapter">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.857
|
// templ: version: v0.3.906
|
||||||
package template
|
package template
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
@@ -31,15 +31,11 @@ func ContentXHTML(content *model.Chapter) templ.Component {
|
|||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templ.Raw(`<?xml version="1.0" encoding="utf-8" standalone="no"?>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templ.Raw(`<?xml version='1.0' encoding='utf-8'?>`).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templ.Raw(`<!DOCTYPE html>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"zh-CN\"><head><title>")
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"zh-CN\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"><head><title>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -56,7 +52,7 @@ func ContentXHTML(content *model.Chapter) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templ.Raw(`<link href="../Styles/style.css" rel="stylesheet" type="text/css"/>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templ.Raw(`<link href="../../style.css" rel="stylesheet" type="text/css"/>`).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
37
template/cover.xhtml.templ
Normal file
37
template/cover.xhtml.templ
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package template
|
||||||
|
|
||||||
|
templ CoverXHTML(coverPath string) {
|
||||||
|
@templ.Raw(`
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>`)
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<title>Cover</title>
|
||||||
|
</head>
|
||||||
|
<style type="text/css">
|
||||||
|
@page {
|
||||||
|
padding: 0pt;
|
||||||
|
margin: 0pt
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0pt;
|
||||||
|
margin: 0pt;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
version="1.1"
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
viewBox="0 0 400 581"
|
||||||
|
preserveAspectRatio="none"
|
||||||
|
>
|
||||||
|
<image width="400" height="581" xlink:href={ coverPath }></image>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// Code generated by templ - DO NOT EDIT.
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
// templ: version: v0.3.857
|
// templ: version: v0.3.906
|
||||||
package template
|
package template
|
||||||
|
|
||||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
@@ -8,9 +8,7 @@ package template
|
|||||||
import "github.com/a-h/templ"
|
import "github.com/a-h/templ"
|
||||||
import templruntime "github.com/a-h/templ/runtime"
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
import "bilinovel-downloader/model"
|
func CoverXHTML(coverPath string) templ.Component {
|
||||||
|
|
||||||
func TocNCX(title string, head *model.TocNCXHead, navMap *model.NavMap) templ.Component {
|
|
||||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
@@ -31,54 +29,25 @@ func TocNCX(title string, head *model.TocNCXHead, navMap *model.NavMap) templ.Co
|
|||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templ.Raw(`
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>`).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templ.Raw(`<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">`).Render(ctx, templ_7745c5c3_Buffer)
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"zh-CN\"><head><title>Cover</title></head><style type=\"text/css\">\n\t\t@page {\n\t\t\tpadding: 0pt;\n\t\t\tmargin: 0pt\n\t\t}\n\t\tbody {\n\t\t\ttext-align: center;\n\t\t\tpadding: 0pt;\n\t\t\tmargin: 0pt;\n\t\t}\n\t\t</style><body><div><svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" width=\"100%\" height=\"100%\" viewBox=\"0 0 400 581\" preserveAspectRatio=\"none\"><image width=\"400\" height=\"581\" xlink:href=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<ncx xmlns=\"http://www.daisy.org/z3986/2005/ncx/\" version=\"2005-1\">")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
if head != nil {
|
|
||||||
head, err := head.Marshal()
|
|
||||||
if err == nil {
|
|
||||||
templ_7745c5c3_Err = templ.Raw(head).Render(ctx, templ_7745c5c3_Buffer)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<docTitle><text>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var2 string
|
var templ_7745c5c3_Var2 string
|
||||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(coverPath)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `template/toc.ncx.templ`, Line: 16, Col: 16}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `template/cover.xhtml.templ`, Line: 32, Col: 59}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</text></docTitle> ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\"></image></svg></div></body></html>")
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
if navMap != nil {
|
|
||||||
navMap, err := navMap.Marshal()
|
|
||||||
if err == nil {
|
|
||||||
templ_7745c5c3_Err = templ.Raw(navMap).Render(ctx, templ_7745c5c3_Buffer)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</ncx>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package template
|
|
||||||
|
|
||||||
import "bilinovel-downloader/model"
|
|
||||||
|
|
||||||
templ TocNCX(title string, head *model.TocNCXHead, navMap *model.NavMap) {
|
|
||||||
@templ.Raw(`<?xml version="1.0" encoding="UTF-8"?>`)
|
|
||||||
@templ.Raw(`<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">`)
|
|
||||||
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
|
||||||
if head != nil {
|
|
||||||
{{ head, err := head.Marshal() }}
|
|
||||||
if err == nil {
|
|
||||||
@templ.Raw(head)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<docTitle>
|
|
||||||
<text>{ title }</text>
|
|
||||||
</docTitle>
|
|
||||||
if navMap != nil {
|
|
||||||
{{ navMap, err := navMap.Marshal() }}
|
|
||||||
if err == nil {
|
|
||||||
@templ.Raw(navMap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</ncx>
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user