Skip to content

Commit

Permalink
更新版本到v1.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sndnvaps committed Mar 1, 2020
1 parent 29ba013 commit b7aa791
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

2020.03.01 go版本
1. cli版本:添加检查最新版本功能 update_check功能
2. cli版本:添加生成epub功能
3. gui版本:添加生成epub功能
4. http-server版本:添加生成epub功能
5. gui版本:把字体嵌入到程序当中
6. 更新版本到 1.7.3

2020.02.29 go版本
1. 对代码函数命名进行规范
Expand Down
59 changes: 54 additions & 5 deletions cli/ebookdl_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func EbookDownloader(c *cli.Context) error {
isTxt := c.Bool("txt")
isMobi := c.Bool("mobi")
isAzw3 := c.Bool("azw3")
isEpub := c.Bool("epub")
isJSON := c.Bool("json") //把下载到的小说信息保存到json数据当中
isPV := c.Bool("printvolume") //打印分卷信息,只用做调试时使用
isMeta := c.Bool("meta") //保存meta信息到 小说目录当中
Expand All @@ -45,9 +46,14 @@ func EbookDownloader(c *cli.Context) error {
txtfilepath := "" //定义 txt下载后,获取得到的 地址
mobifilepath := "" //定义 mobi下载后,获取得到的 地址
coverURLPath := "" //定义下载小说后,封面的url地址
epubfilepath := "" //定义 epub下载后,获取得到的 地址

//isTxt 或者 isMobi必须一个为真,或者两个都为真
if (isTxt || isMobi || isAzw3) || (isTxt && isMobi) || (isTxt && isAzw3) || isPV || isJSON {
if (isTxt || isMobi || isAzw3 || isEpub) ||
(isTxt && isMobi) ||
(isTxt && isAzw3) ||
(isTxt && isEpub) ||
isPV || isJSON {

if ebhost == "xsbiquge.com" {
xsbiquge := edl.NewXSBiquge()
Expand Down Expand Up @@ -114,6 +120,17 @@ func EbookDownloader(c *cli.Context) error {
coverURLPath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + "cover.jpg"
}
}

//生成epub格式电子书
if isEpub {
fmt.Printf("\n正在生成EPUB版本的电子书,请耐心等待!\n")
bookinfo.GenerateEPUB()
if isMeta { //配置meta信息
epubfilepath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + bookinfo.Name + "-" + bookinfo.Author + ".epub"
coverURLPath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + "cover.jpg"
}
}

if isMeta {
metainfo = edl.Meta{
Ebhost: ebhost,
Expand All @@ -124,6 +141,7 @@ func EbookDownloader(c *cli.Context) error {
Description: bookinfo.Description,
TxtURLPath: txtfilepath,
MobiURLPath: mobifilepath,
EPUBURLPath: epubfilepath,
}

metainfo.WriteFile("./outputs/" + bookinfo.Name + "-" + bookinfo.Author + "/meta.json")
Expand All @@ -150,18 +168,29 @@ func ConvJSON2Ebook(c *cli.Context) error {
isTxt := c.Bool("txt")
isMobi := c.Bool("mobi")
isAzw3 := c.Bool("azw3")
isEpub := c.Bool("epub")
isMeta := c.Bool("meta") //保存meta信息到 小说目录当中

var metainfo edl.Meta //用于保存小说的meta信息
txtfilepath := "" //定义 txt下载后,获取得到的 地址
mobifilepath := "" //定义 mobi下载后,获取得到的 地址
epubfilepath := "" //定义 epub下载后,获取得到的 地址
coverURLPath := "" //定义下载小说后,封面的url地址

//isTxt 或者 isMobi必须一个为真,或者两个都为真
if (isTxt || isMobi || isAzw3) || (isTxt && isMobi) || (isTxt && isAzw3) {
if (isTxt || isMobi || isAzw3 || isEpub) ||
(isTxt && isMobi) ||
(isTxt && isAzw3) ||
(isTxt && isEpub) {

// isMobi && isAzw3 当同时为真的时候,退出进程
if isMobi && isAzw3 {
// isMobi && isEpub 当同时为真的时候,退出进程
// isAzw3 && isEpub 当同时为真的时候,退出进程
// isMobi && isAzw3 && isEpub 当同时为真的时候,退出进程
if (isMobi && isAzw3) ||
(isMobi && isEpub) ||
(isAzw3 && isMobi && isEpub) ||
(isAzw3 && isEpub) {
cli.ShowAppHelpAndExit(c, 0)
return nil
}
Expand Down Expand Up @@ -199,6 +228,16 @@ func ConvJSON2Ebook(c *cli.Context) error {
coverURLPath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + "cover.jpg"
}
}

//生成epub格式电子书
if isEpub {
fmt.Printf("\n正在生成EPUB版本的电子书,请耐心等待!\n")
bookinfo.GenerateEPUB()
if isMeta { //配置meta信息
epubfilepath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + bookinfo.Name + "-" + bookinfo.Author + ".epub"
coverURLPath = "public/" + bookinfo.Name + "-" + bookinfo.Author + "/" + "cover.jpg"
}
}
if isMeta {
metainfo = edl.Meta{
Ebhost: bookinfo.EBHost,
Expand All @@ -209,6 +248,7 @@ func ConvJSON2Ebook(c *cli.Context) error {
Description: bookinfo.Description,
TxtURLPath: txtfilepath,
MobiURLPath: mobifilepath,
EPUBURLPath: epubfilepath,
}

metainfo.WriteFile("./outputs/" + bookinfo.Name + "-" + bookinfo.Author + "/meta.json")
Expand All @@ -225,9 +265,10 @@ func ConvJSON2Ebook(c *cli.Context) error {

//UpdateCheck 检查更新
func UpdateCheck(c *cli.Context) error {
result, err := edl.UpdateCheck(Version)
result, err := edl.UpdateCheck()
if err == nil {
fmt.Printf(result)
CompareResult := result.Compare(Version)
fmt.Printf("版本检测结果[%s]\n", CompareResult)
return nil
}
return err
Expand Down Expand Up @@ -273,6 +314,10 @@ func main() {
Name: "azw3",
Usage: "当使用的时候,生成azw3文件(不可与--mobi同时使用)",
},
cli.BoolFlag{
Name: "epub",
Usage: "当使用的时候,生成epub文件(不可与--mobi同时使用)",
},
cli.BoolFlag{
Name: "json",
Usage: "当使用的时候,把下载得到的小说内容写入到json文件当中",
Expand Down Expand Up @@ -307,6 +352,10 @@ func main() {
Name: "azw3",
Usage: "生成azw3文件",
},
cli.BoolFlag{
Name: "epub",
Usage: "当使用的时候,生成epub文件",
},
cli.BoolFlag{
Name: "meta",
Usage: "生成meta文件",
Expand Down
64 changes: 64 additions & 0 deletions ebookdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/Chain-Zhang/pinyin"
"github.com/bmaupin/go-epub"
"github.com/unknwon/com"
)

Expand Down Expand Up @@ -216,6 +217,69 @@ func (this BookInfo) GenerateTxt() {
//WriteFile(outfname, []byte(content))
}

//GenerateEPUB 生成ebpub小说
func (this BookInfo) GenerateEPUB() error {
//将文件名转换成拼音
strPinyin, _ := pinyin.New(this.Name).Split("-").Mode(pinyin.WithoutTone).Convert()
savepath := "./tmp/" + strPinyin
savepath, _ = filepath.Abs(savepath) //使用绝对路径
if com.IsExist(savepath) {
os.RemoveAll(savepath)
}
os.MkdirAll(path.Dir(savepath)+string(os.PathSeparator), os.ModePerm)

//设置生成mobi的输出目录
outputpath := "./outputs/" + this.Name + "-" + this.Author + "/"
outputpath, _ = filepath.Abs(outputpath)
outputpath = outputpath + string(os.PathSeparator) //使用绝对路径
//fmt.Println(outputpath)
if !com.IsExist(outputpath) {
os.MkdirAll(outputpath, os.ModePerm)
}
// 生成封面
GenerateCover(this)
//把封面复制到 tmp 目录当中
coverPath, _ := filepath.Abs("./cover.jpg")

//把封面复制到 outputs/小说名-作者/cover.jpg
err := com.Copy(coverPath, outputpath+"cover.jpg")
if err != nil {
fmt.Println(err.Error())
}
//删除当前目前的cover.jpg文件
os.RemoveAll(coverPath)

//创建epub小说信息
e := epub.NewEpub(this.Name)
e.SetAuthor(this.Author)
epubCover, _ := e.AddImage("./outputs/"+this.Name+"-"+this.Author+"/"+"cover.jpg", "cover.jpg")
epubCoverCSS, _ := e.AddCSS("./tpls/epub_cover.css", "cover.css")
e.SetCover(epubCover, epubCoverCSS)
e.SetDescription(this.Description)

//设置章节信息
chapters := this.Chapters
for _, chapter := range chapters {
sectionBody := "<h1>" + chapter.Title + "</h1>\n<p></p>\n"
contentTmp := chapter.Content
contentLines := strings.Split(contentTmp, "\r")
for _, line := range contentLines {
line = strings.Replace(line, " ", " ", -1) //将每行前面4个空格都换成二个空格
sectionBody += "<p>" + line + "</p>\n"
}
if _, err := e.AddSection(sectionBody, chapter.Title, "", ""); err != nil {
return err
}

}

if err = e.Write(outputpath + this.Name + "-" + this.Author + ".epub"); err != nil {
return err
}

return nil
}

//GenerateJSON 生成json格式的数据
func (this BookInfo) GenerateJSON() error {
outfpath := "./outputs/" + this.Name + "-" + this.Author + "/"
Expand Down
5 changes: 5 additions & 0 deletions ebookdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func TestGenerateAwz3(t *testing.T) {
assert.True(t, true, isExist(savename))
//os.RemoveAll(savename)
}
func TestGenerateEPUB(t *testing.T) {
testbi.GenerateEPUB()
savename := "./outputs/" + testbi.Name + "-" + testbi.Author + "/" + testbi.Name + "-" + testbi.Author + ".epub"
assert.True(t, true, isExist(savename))
}

// IsExist checks whether a file or directory exists.
// It returns false when the file or directory does not exist.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/antchfx/xpath v1.1.4 // indirect
github.com/appleboy/gin-jwt v2.5.0+incompatible
github.com/appleboy/gin-jwt/v2 v2.6.3
github.com/bmaupin/go-epub v0.5.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.5.0
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/appleboy/gin-jwt v2.5.0+incompatible/go.mod h1:pG7tv32IEe5wEh1NSQzcyD
github.com/appleboy/gin-jwt/v2 v2.6.3 h1:aK4E3DjihWEBUTjEeRnGkA5nUkmwJPL1CPonMa2usRs=
github.com/appleboy/gin-jwt/v2 v2.6.3/go.mod h1:MfPYA4ogzvOcVkRwAxT7quHOtQmVKDpTwxyUrC2DNw0=
github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw=
github.com/bmaupin/go-epub v0.5.3 h1:HBOJS2KqsRGGcEzM470/9l5q2l9JwAUxQabEgPMrW90=
github.com/bmaupin/go-epub v0.5.3/go.mod h1:4RBr0Zo03mRGOyGAcc25eLOqIPCkMbfz+tINVmH6clQ=
github.com/boltdb/bolt v1.3.1-0.20170131192018-e9cf4fae01b5/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/codegangsta/cli v1.8.1-0.20150711215404-bca61c476e3c/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA=
github.com/codegangsta/negroni v0.1.1-0.20150319171304-c7477ad8e330 h1:M/anPvoT8sd0FHMD2LFr4PA8/pbwCtD+G1CO9tjkWeE=
Expand Down Expand Up @@ -52,6 +54,8 @@ github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEK
github.com/go-resty/resty/v2 v2.1.0/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/gofrs/uuid v3.1.0+incompatible h1:q2rtkjaKT4YEr6E1kamy0Ha4RtepWlQBedyHx0uzKwA=
github.com/gofrs/uuid v3.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
269 changes: 269 additions & 0 deletions gui/bindata.go

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions gui/ebookdl_gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ var (
itemSelected int32 //0 -> xsbiquge.com ; 1 -> 999xs.com; 2 -> 23us.la
checked bool //生成txt
checked2 bool //生成mobi
checked3 bool //生成epub
multiline string //小说简介
author string //小说作者

compareResult string //版本对比信息

bookinfo edl.BookInfo //初始化bookinfo变量
ebdlInterface edl.EBookDLInterface //初始化接口
)
Expand All @@ -30,7 +33,7 @@ var (

var (
//Version 版本信息
Version string = "1.7.2"
Version string = "dev"
//Commit git commit信息
Commit string = "b40f73c79"
//BuildTime 编译时间
Expand All @@ -53,13 +56,22 @@ func btnPopupCLicked1() {
imgui.OpenPopup("Confirm1")
}

func btnPopupCLicked2() {
obj, err := edl.UpdateCheck()
if err == nil {
compareResult = obj.Compare(Version)
}
imgui.OpenPopup("Comfirm2")
}

//EbookDownloaderRun 下载小说功能
func EbookDownloaderRun() {
multiline = items[itemSelected]
id := bookid
ebhost := items[itemSelected]
isTxt := checked
isMobi := checked2
isEpub := checked3
p := proxy

var cmdArgs []string //定义命令用到的参数
Expand Down Expand Up @@ -94,6 +106,9 @@ func EbookDownloaderRun() {
if isMobi {
cmdArgs = append(cmdArgs, "--mobi")
}
if isEpub {
cmdArgs = append(cmdArgs, "--epub")
}
//添加生成meta.json参数
cmdArgs = append(cmdArgs, "--meta")

Expand All @@ -115,7 +130,6 @@ func loop() {
g.Label("github: https://github.com/sndnvaps"),
g.Line(
g.Button("Yes", func() { imgui.CloseCurrentPopup() }),
g.Button("No", nil),
),
}),

Expand All @@ -128,7 +142,16 @@ func loop() {
g.Label("编译时间:" + BuildTime),
g.Line(
g.Button("Yes", func() { imgui.CloseCurrentPopup() }),
g.Button("No", nil),
),
}),
g.Button("检查更新", btnPopupCLicked2),
g.Popup("Confirm2", g.Layout{
g.Label("检查软件是否需要更新"),
g.Label("项目地址: https://github.com/sndnvaps/ebookdownloader"),
g.Label("当前版本号:" + Version),
g.Label("检测结果:" + compareResult),
g.Line(
g.Button("Yes", func() { imgui.CloseCurrentPopup() }),
),
}),
},
Expand Down Expand Up @@ -158,6 +181,9 @@ func loop() {
g.Checkbox("生成mobi", &checked2, func() {
fmt.Println(checked2)
}),
g.Checkbox("生成epub", &checked3, func() {
fmt.Println(checked3)
}),
),

g.Combo("选择要用到的默认下载网站", items[itemSelected], items, &itemSelected, 0, comboChanged),
Expand Down Expand Up @@ -194,8 +220,8 @@ func loadFont() {
builder.AddRanges(fonts.GlyphRangesChineseFull())
builder.BuildRanges(ranges)

fontPath := "./fonts/WenQuanYiMicroHei.ttf"
fonts.AddFontFromFileTTFV(fontPath, 14, imgui.DefaultFontConfig, ranges.Data())
fontBytes, _ := Asset("fonts/WenQuanYiMicroHei.ttf")
fonts.AddFontFromMemoryTTFV(fontBytes, 14, imgui.DefaultFontConfig, ranges.Data())
}
func main() {

Expand Down
Loading

0 comments on commit b7aa791

Please sign in to comment.