diff --git a/23us.la.go b/23us.la.go index aceeed4..cbf1f9f 100644 --- a/23us.la.go +++ b/23us.la.go @@ -1,4 +1,4 @@ -package main +package ebookdownloader import ( "fmt" @@ -6,7 +6,7 @@ import ( "sync" "github.com/Aiicy/htmlquery" - "gopkg.in/schollz/progressbar.v2" + "github.com/schollz/progressbar/v2" ) //参考地址,创建规则 @@ -15,63 +15,6 @@ import ( //https://www.23us.la/html/113/113444/ -> 不朽凡人 //需要参考 https://segmentfault.com/a/1190000018475209 解决 返回的content与title不对应问题 -/* -package main - -import ( - "fmt" - "sync" - "time" -) - -func main() { - resultCh := make(chan chan string, 5000) - wg := sync.WaitGroup{} - go replay(resultCh) - startTime := time.Now() - operation2(resultCh, "aaa", &wg) - operation2(resultCh, "bbb", &wg) - operation1(resultCh, "ccc", &wg) - operation1(resultCh, "ddd", &wg) - operation2(resultCh, "eee", &wg) - wg.Wait() - endTime := time.Now() - fmt.Printf("Process time %s", endTime.Sub(startTime)) -} - -func replay(resultCh chan chan string)(){ - for{ - //拿到一个chan 读取值 这个时候拿到的是先进先出 因为所有方法是按顺序加入chan的 - c := <- resultCh - //读取嵌套chan中的值,这个时候等待3秒 因为是operation2中执行了3秒 在这3绵中 其实其余的4个方法也已经执行完毕。之后的方法则不需要等待sleep的时间 - r := <-c - fmt.Println(r) - } -} - -func operation1(ch chan chan string, str string, wg *sync.WaitGroup)(){ - //先创建一个chan 兵给到嵌套chan 占据一个通道 这个通道是阻塞的 - c := make(chan string) - ch <- c - wg.Add(1) - go func(str string){ - time.Sleep(time.Second*1) - c <- "operation1:"+str - wg.Done() - }(str) -} - -func operation2(ch chan chan string, str string, wg *sync.WaitGroup)(){ - c := make(chan string) - ch <- c - wg.Add(1) - go func(str string){ - time.Sleep(time.Second*2) - c <- "operation2:"+str - wg.Done() - }(str) -} -*/ //顶点小说网 23us.la type Ebook23US struct { diff --git a/999xs.go b/999xs.go index faa7586..3666295 100644 --- a/999xs.go +++ b/999xs.go @@ -1,4 +1,4 @@ -package main +package ebookdownloader import ( "fmt" @@ -6,7 +6,7 @@ import ( "sync" "github.com/Aiicy/htmlquery" - "gopkg.in/schollz/progressbar.v2" + "github.com/schollz/progressbar/v2" ) // https://www.999xs.com/ diff --git a/Kindlegen_darwin.go b/Kindlegen_darwin.go index ded1041..1a3a2c9 100644 --- a/Kindlegen_darwin.go +++ b/Kindlegen_darwin.go @@ -1,6 +1,6 @@ // +build darwin -package main +package ebookdownloader import ( "os/exec" diff --git a/Kindlegen_linux.go b/Kindlegen_linux.go index 70713a7..18e7919 100644 --- a/Kindlegen_linux.go +++ b/Kindlegen_linux.go @@ -1,6 +1,6 @@ // +build linux -package main +package ebookdownloader import ( "os/exec" diff --git a/Kindlegen_windows.go b/Kindlegen_windows.go index 3219c98..7994e3a 100644 --- a/Kindlegen_windows.go +++ b/Kindlegen_windows.go @@ -1,6 +1,6 @@ // +build windows -package main +package ebookdownloader import ( "os/exec" diff --git a/README.md b/README.md index d116628..f44fb06 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## 安装方法 ```bash - go get github.com/sndnvaps/ebookdownloader + go get github.com/sndnvaps/ebookdownloader/cli ``` ## 使用方法 ```bash @@ -33,6 +33,11 @@ ## 更新日志 + 2020.01.22 go版本 更新 + 1. 分离出命令行版本cli,编译命令 cd cli;build.[cmd|sh] + 2. 界面版本gui,立项目 + 3. 添加go mod支持 + 2020.01.13 go版本 更新 1. 修复潜在问题,无法生成 ./outputs目录 2. 修复azw3后序出错问题,已经可以在 calibre中阅读 @@ -87,3 +92,4 @@ [√] 1.添加生成封面功能 [√] 2. 添加不同平台的接口实现 [√] 3. 添加生成二级目录的方法(已经添加相应的实例) + [ ] 4. 添加界面版本gui diff --git a/cli/build.cmd b/cli/build.cmd new file mode 100644 index 0000000..1cc3349 --- /dev/null +++ b/cli/build.cmd @@ -0,0 +1,9 @@ +for /F %%i in ('git rev-parse --short HEAD') do ( set commitid=%%i) +echo commitid=%commitid% + +set CURRENT_DATE=%date:~0,4%-%date:~5,2%-%date:~8,2% +set CURRENT_TIME=%time:~0,2%:%time:~3,2%:%time:~6,2% +echo %CURRENT_DATE% %CURRENT_TIME% +set buildtime=%CURRENT_DATE%-%CURRENT_TIME% +go build -ldflags "-X main.Commit=%commitid% -X main.BuildTime=%buildtime%" -o ebookdownloader_cli.exe +copy ebookdownloader_cli.exe ..\ diff --git a/cli/build.sh b/cli/build.sh new file mode 100644 index 0000000..aedf2dc --- /dev/null +++ b/cli/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +CommitID=$(git rev-parse HEAD) +BuildTime=$(date +%Y-%m-%d\ %H:%M) +LDFlags="-X main.Commit=${CommitID} -X 'main.BuildTime=${BuildTime}'" + + go build -ldflags "${LDFlags}" -o ebookdownloader_cli + cp ebookdownloader_cli ../ \ No newline at end of file diff --git a/cli/ebookdl_cli.go b/cli/ebookdl_cli.go new file mode 100644 index 0000000..0e6159c --- /dev/null +++ b/cli/ebookdl_cli.go @@ -0,0 +1,149 @@ +package main + +import ( + "fmt" + "log" + "os" + "time" + + edl "github.com/sndnvaps/ebookdownloader" + "gopkg.in/urfave/cli.v1" +) + +var ( + Version string = "1.6.2" + Commit string = "" + BuildTime string = "" +) + +func EbookDownloader(c *cli.Context) error { + //bookid := "91_91345" //91_91345, 0_642 + bookid := c.String("bookid") + if bookid == "" { + cli.ShowAppHelpAndExit(c, 0) + return nil + } + //对应下载小说的网站,默认值为xsbiquge.com + ebhost := c.String("ebhost") + + proxy := c.String("proxy") + + isTxt := c.Bool("txt") + isMobi := c.Bool("mobi") + isAzw3 := c.Bool("azw3") + isPV := c.Bool("printvolume") //打印分卷信息,只用做调试时使用 + + var bookinfo edl.BookInfo //初始化变量 + var EBDLInterface edl.EBookDLInterface //初始化接口 + //isTxt 或者 isMobi必须一个为真,或者两个都为真 + if (isTxt || isMobi || isAzw3) || (isTxt && isMobi) || (isTxt && isAzw3) || isPV { + + if ebhost == "xsbiquge.com" { + xsbiquge := edl.NewXSBiquge() + EBDLInterface = xsbiquge //实例化接口 + } else if ebhost == "999xs.com" { + xs999 := edl.New999XS() + EBDLInterface = xs999 //实例化接口 + } else if ebhost == "23us.la" { + xs23 := edl.New23US() + EBDLInterface = xs23 //实例化接口 + } else { + cli.ShowAppHelpAndExit(c, 0) + return nil + } + // isMobi && isAzw3 当同时为真的时候,退出进程 + if isMobi && isAzw3 { + cli.ShowAppHelpAndExit(c, 0) + return nil + } + bookinfo = EBDLInterface.GetBookInfo(bookid, proxy) + + //打印分卷信息,只用于调试 + if isPV { + bookinfo.PrintVolumeInfo() + return nil + } else { + //下载章节内容 + fmt.Printf("正在下载电子书的相应章节,请耐心等待!\n") + bookinfo = EBDLInterface.DownloadChapters(bookinfo, proxy) + } + //生成txt文件 + if isTxt { + fmt.Printf("\n正在生成txt版本的电子书,请耐心等待!\n") + bookinfo.GenerateTxt() + } + //生成mobi格式电子书 + if isMobi { + fmt.Printf("\n正在生成mobi版本的电子书,请耐心等待!\n") + bookinfo.SetKindleEbookType(true /* isMobi */, false /* isAzw3 */) + bookinfo.GenerateMobi() + } + //生成awz3格式电子书 + if isAzw3 { + fmt.Printf("\n正在生成Azw3版本的电子书,请耐心等待!\n") + bookinfo.SetKindleEbookType(false /* isMobi */, true /* isAzw3 */) + bookinfo.GenerateMobi() + } + + } else { + cli.ShowAppHelpAndExit(c, 0) + return nil + } + fmt.Printf("已经完成生成电子书!\n") + + return nil +} + +func main() { + + app := cli.NewApp() + app.Name = "golang EBookDownloader" + app.Compiled = time.Now() + app.Version = Version + "-" + Commit + "-" + BuildTime + app.Authors = []cli.Author{ + cli.Author{ + Name: "Jimes Yang", + Email: "sndnvaps@gmail.com", + }, + } + app.Copyright = "(c) 2019 - 2020 Jimes Yang" + app.Usage = "用于下载 笔趣阁(https://www.xsbiquge.com),999小说网(https://www.999xs.com/) ,顶点小说网(https://www.23us.la) 上面的电子书,并保存为txt格式或者(mobi格式,awz3格式)的电子书" + app.Action = EbookDownloader + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "ebhost", + Value: "xsbiquge.com", + Usage: "定义下载ebook的网站地址(可选择xsbiquge.com,999xs.com,23us.la)", + }, + cli.StringFlag{ + Name: "bookid,id", + Usage: "对应笔趣阁id(https://www.xsbiquge.com/0_642/),其中0_642就是book_id;\n对应999小说网id(https://www.999xs.com/files/article/html/0/591/),其中591为book_id;\n对应顶点小说网id(https://www.23us.la/html/113/113444/),其中113444为bookid", + }, + cli.StringFlag{ + Name: "proxy,p", + Usage: "ip代理(http://ip:ipport),减少本机ip被小说网站封的可能性", + }, + cli.BoolFlag{ + Name: "txt", + Usage: "当使用的时候,生成txt文件", + }, + cli.BoolFlag{ + Name: "mobi", + Usage: "当使用的时候,生成mobi文件(不可与--azw3同时使用)", + }, + cli.BoolFlag{ + Name: "azw3", + Usage: "当使用的时候,生成azw3文件(不可与--mobi同时使用)", + }, + cli.BoolFlag{ + Name: "printvolume,pv", + Usage: "打印分卷信息,只于调试时使用!(使用此功能的时候,不会下载章节内容)", + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } + +} diff --git a/ebookCover.go b/ebookCover.go index 9f8c892..abdf12c 100644 --- a/ebookCover.go +++ b/ebookCover.go @@ -1,4 +1,4 @@ -package main +package ebookdownloader import ( "fmt" diff --git a/ebookdl.go b/ebookdl.go index e55ba8d..1bcd50b 100644 --- a/ebookdl.go +++ b/ebookdl.go @@ -1,18 +1,16 @@ -package main +package ebookdownloader import ( "fmt" "io/ioutil" - "log" "os" "path" "strings" "sync" "time" - "github.com/Unknwon/com" - "github.com/chain-zhang/pinyin" - "gopkg.in/urfave/cli.v1" + "github.com/Chain-Zhang/pinyin" + "github.com/unknwon/com" ) type BookInfo struct { @@ -299,84 +297,6 @@ func (this BookInfo) GenerateMobi() { com.Copy(savepath+"/"+outfname, "./outputs/"+outfname) } -func EbookDownloader(c *cli.Context) error { - //bookid := "91_91345" //91_91345, 0_642 - bookid := c.String("bookid") - if bookid == "" { - cli.ShowAppHelpAndExit(c, 0) - return nil - } - //对应下载小说的网站,默认值为xsbiquge.com - ebhost := c.String("ebhost") - - proxy := c.String("proxy") - - isTxt := c.Bool("txt") - isMobi := c.Bool("mobi") - isAzw3 := c.Bool("azw3") - isPV := c.Bool("printvolume") //打印分卷信息,只用做调试时使用 - - var bookinfo BookInfo //初始化变量 - var EBDLInterface EBookDLInterface //初始化接口 - //isTxt 或者 isMobi必须一个为真,或者两个都为真 - if (isTxt || isMobi || isAzw3) || (isTxt && isMobi) || (isTxt && isAzw3) || isPV { - - if ebhost == "xsbiquge.com" { - xsbiquge := NewXSBiquge() - EBDLInterface = xsbiquge //实例化接口 - } else if ebhost == "999xs.com" { - xs999 := New999XS() - EBDLInterface = xs999 //实例化接口 - } else if ebhost == "23us.la" { - xs23 := New23US() - EBDLInterface = xs23 //实例化接口 - } else { - cli.ShowAppHelpAndExit(c, 0) - return nil - } - // isMobi && isAzw3 当同时为真的时候,退出进程 - if isMobi && isAzw3 { - cli.ShowAppHelpAndExit(c, 0) - return nil - } - bookinfo = EBDLInterface.GetBookInfo(bookid, proxy) - - //打印分卷信息,只用于调试 - if isPV { - bookinfo.PrintVolumeInfo() - return nil - } else { - //下载章节内容 - fmt.Printf("正在下载电子书的相应章节,请耐心等待!\n") - bookinfo = EBDLInterface.DownloadChapters(bookinfo, proxy) - } - //生成txt文件 - if isTxt { - fmt.Printf("\n正在生成txt版本的电子书,请耐心等待!\n") - bookinfo.GenerateTxt() - } - //生成mobi格式电子书 - if isMobi { - fmt.Printf("\n正在生成mobi版本的电子书,请耐心等待!\n") - bookinfo.SetKindleEbookType(true /* isMobi */, false /* isAzw3 */) - bookinfo.GenerateMobi() - } - //生成awz3格式电子书 - if isAzw3 { - fmt.Printf("\n正在生成Azw3版本的电子书,请耐心等待!\n") - bookinfo.SetKindleEbookType(false /* isMobi */, true /* isAzw3 */) - bookinfo.GenerateMobi() - } - - } else { - cli.ShowAppHelpAndExit(c, 0) - return nil - } - fmt.Printf("已经完成生成电子书!\n") - - return nil -} - //AsycChapter func AsycChapter(ResultChan chan chan Chapter, chapter chan Chapter) { for { @@ -386,57 +306,3 @@ func AsycChapter(ResultChan chan chan Chapter, chapter chan Chapter) { } } - -func main() { - - app := cli.NewApp() - app.Name = "golang EBookDownloader" - app.Compiled = time.Now() - app.Version = "1.6.1" - app.Authors = []cli.Author{ - cli.Author{ - Name: "Jimes Yang", - Email: "sndnvaps@gmail.com", - }, - } - app.Copyright = "(c) 2019 - 2020 Jimes Yang" - app.Usage = "用于下载 笔趣阁(https://www.xsbiquge.com),999小说网(https://www.999xs.com/) ,顶点小说网(https://www.23us.la) 上面的电子书,并保存为txt格式或者(mobi格式,awz3格式)的电子书" - app.Action = EbookDownloader - app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "ebhost", - Value: "xsbiquge.com", - Usage: "定义下载ebook的网站地址(可选择xsbiquge.com,999xs.com,23us.la)", - }, - cli.StringFlag{ - Name: "bookid,id", - Usage: "对应笔趣阁id(https://www.xsbiquge.com/0_642/),其中0_642就是book_id;\n对应999小说网id(https://www.999xs.com/files/article/html/0/591/),其中591为book_id;\n对应顶点小说网id(https://www.23us.la/html/113/113444/),其中113444为bookid", - }, - cli.StringFlag{ - Name: "proxy,p", - Usage: "ip代理(http://ip:ipport),减少本机ip被小说网站封的可能性", - }, - cli.BoolFlag{ - Name: "txt", - Usage: "当使用的时候,生成txt文件", - }, - cli.BoolFlag{ - Name: "mobi", - Usage: "当使用的时候,生成mobi文件(不可与--azw3同时使用)", - }, - cli.BoolFlag{ - Name: "azw3", - Usage: "当使用的时候,生成azw3文件(不可与--mobi同时使用)", - }, - cli.BoolFlag{ - Name: "printvolume,pv", - Usage: "打印分卷信息,只于调试时使用!(使用此功能的时候,不会下载章节内容)", - }, - } - - err := app.Run(os.Args) - if err != nil { - log.Fatal(err) - } - -} diff --git a/ebookdl_test.go b/ebookdl_test.go index 2321e72..395af7e 100644 --- a/ebookdl_test.go +++ b/ebookdl_test.go @@ -1,4 +1,4 @@ -package main +package ebookdownloader import ( "os" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e5e14a3 --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module github.com/sndnvaps/ebookdownloader + +go 1.13 + +require ( + github.com/Aiicy/htmlquery v0.0.0-20191217151354-e656ce3100dc + github.com/Chain-Zhang/pinyin v0.1.3 + github.com/antchfx/xpath v1.1.4 // indirect + github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff + github.com/schollz/progressbar/v2 v2.15.0 + github.com/stretchr/testify v1.4.0 + github.com/unknwon/com v1.0.1 + golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect + golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect + gopkg.in/urfave/cli.v1 v1.20.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0059ccd --- /dev/null +++ b/go.sum @@ -0,0 +1,42 @@ +github.com/Aiicy/htmlquery v0.0.0-20191217151354-e656ce3100dc h1:I3xXOKWNqNFnI1aPIVW/ST08UQ9gVl0v2u2eqm73Pb8= +github.com/Aiicy/htmlquery v0.0.0-20191217151354-e656ce3100dc/go.mod h1:I9AP7gqzg8mzt9hrBptwroZe+dgUU5efNNhIhcdXFKA= +github.com/Chain-Zhang/pinyin v0.1.3 h1:RzErNyNwVa8z2sOLCuXSOtVdY/AsARb8mBzI2p2qtnE= +github.com/Chain-Zhang/pinyin v0.1.3/go.mod h1:5iHpt9p4znrnaP59/hfPMnAojajkDxQaP9io+tRMPho= +github.com/antchfx/xpath v1.1.4 h1:naPIpjBGeT3eX0Vw7E8iyHsY8FGt6EbGdkcd8EZCo+g= +github.com/antchfx/xpath v1.1.4/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM= +github.com/schollz/progressbar/v2 v2.15.0 h1:dVzHQ8fHRmtPjD3K10jT3Qgn/+H+92jhPrhmxIJfDz8= +github.com/schollz/progressbar/v2 v2.15.0/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI= +github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/unknwon/com v1.0.1 h1:3d1LTxD+Lnf3soQiD4Cp/0BRB+Rsa/+RTvz8GMMzIXs= +github.com/unknwon/com v1.0.1/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg= +golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= +gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gui/ebookdl_gui.go b/gui/ebookdl_gui.go new file mode 100644 index 0000000..e134dbd --- /dev/null +++ b/gui/ebookdl_gui.go @@ -0,0 +1,185 @@ +// +build gui + +package main + +import ( + "runtime" + + "github.com/AllenDang/gimu" + "github.com/AllenDang/gimu/nk" +) + +var ( + textedit = gimu.NewTextEdit() + selected int + comboLabel string + num1 uint = 11 + num2 uint = 33 + propertyInt int32 + propertyFloat float32 + checked bool + option int = 1 + selected1 bool + selected2 bool + showPopup bool + showAboutPopup bool + picture *gimu.Texture + slider int32 = 33 + customFont *nk.Font +) + +func msgbox(w *gimu.Window) { + gimu.SetFont(w.MasterWindow().GetContext(), customFont) + + opened := w.Popup("完成状态", nk.PopupStatic, nk.WindowTitle|nk.WindowNoScrollbar|nk.WindowClosable, nk.NkRect(30, 10, 300, 100), func(w *gimu.Window) { + w.Row(25).Dynamic(1) + // Custom font + + w.Label("弹出窗口", "LC") + buttonState := w.Button("关闭") + if buttonState { + showPopup = false + w.ClosePopup() + } + gimu.SetFont(w.MasterWindow().GetContext(), w.MasterWindow().GetDefaultFont()) + + }) + if !opened { + showPopup = false + } +} + +func AboutMsgBox(w *gimu.Window) { + gimu.SetFont(w.MasterWindow().GetContext(), customFont) + + opened := w.Popup("关于本程序", nk.PopupStatic, nk.WindowTitle|nk.WindowNoScrollbar|nk.WindowClosable, nk.NkRect(30, 10, 300, 100), func(w *gimu.Window) { + w.Row(25).Dynamic(1) + // Custom font + + w.Label("本程序由 sndnvaps开发", "LC") + buttonState := w.Button("关闭") + if buttonState { + showAboutPopup = false + w.ClosePopup() + } + gimu.SetFont(w.MasterWindow().GetContext(), w.MasterWindow().GetDefaultFont()) + + }) + if !opened { + showAboutPopup = false + } +} + +func inputwidgets(w *gimu.Window) { + gimu.SetFont(w.MasterWindow().GetContext(), customFont) + // Menu + w.Menubar(func(w *gimu.Window) { + w.Row(25).Static(60, 60, 60) + // Menu 1 + w.Menu("Menu1", "CC", 200, 100, func(w *gimu.Window) { + w.Row(25).Dynamic(1) + w.MenuItemLabel("Menu item 1", "LC") + w.MenuItemLabel("Menu item 2", "LC") + w.Button("Button inside menu") + }) + // Menu 2 + w.Menu("Menu2", "CC", 100, 100, func(w *gimu.Window) { + w.Row(25).Dynamic(1) + w.MenuItemLabel("Menu item 1", "LC") + w.SliderInt(0, &slider, 100, 1) + w.MenuItemLabel("Menu item 2", "LC") + }) + + // Menu 3 + w.Menu("Help", "CC", 100, 100, func(w *gimu.Window) { + w.Row(25).Dynamic(1) + state := w.Button("关于") + if state { + showAboutPopup = true + } + /* + if showAboutPopup { + AboutMsgBox(w) + } + */ + }) + + }) + // 弹出窗口 + /* + w.Row(25).Dynamic(1) + w.LabelColored("Colored label", color.RGBA{200, 100, 100, 255}, "LC") + state := w.Button("Click me to show a popup window") + if state { + showPopup = true + } + + if showPopup { + msgbox(w) + } + */ + + w.Row(25).Dynamic(1) + w.Label("Radio", "LC") + w.Row(25).Dynamic(3) + if op1 := w.Radio("Option 1", option == 1); op1 { + option = 1 + } + if op2 := w.Radio("Option 2", option == 2); op2 { + option = 2 + } + if op3 := w.Radio("Option 3", option == 3); op3 { + option = 3 + } + + w.Row(25).Static(100, 150) + w.Label("小说的BookId", "LC") + textedit.Edit(w, nk.EditField, gimu.EditFilterDefault) //inputbot ,输入框 + + //fmt.Println(textedit.GetString()) + + w.Row(25).Static(100, 100) + w.Label("作者", "LC") + textedit.Edit(w, nk.EditField, gimu.EditFilterDefault) //inputbot ,输入框 + + w.Row(25).Static(100) + w.Label("简介", "LC") + w.Row(300).Static(600) + textedit.Edit(w, nk.EditBox, gimu.EditFilterDefault) //inputbot ,输入框 + + w.Row(25).Static(100) + w.Tooltip("点击并进行小说内容的下载") + w.Button("下载并生成文件") + + gimu.SetFont(w.MasterWindow().GetContext(), w.MasterWindow().GetDefaultFont()) +} + +func updatefn(w *gimu.Window) { + width, height := w.MasterWindow().GetSize() + bounds := nk.NkRect(0, 0, float32(width), float32(height)) + + w.Window("小说下载器@sndnvaps", bounds, nk.WindowNoScrollbar, func(w *gimu.Window) { + _, h := w.MasterWindow().GetSize() + w.Row(int(float32(h-10)) - 9).Dynamic(1) //只有一个group-1 + w.Group("Group1", nk.WindowBorder|nk.WindowTitle, func(w *gimu.Window) { + inputwidgets(w) + + }) + + }) +} + +func main() { + runtime.LockOSThread() + + // Create master window + wnd := gimu.NewMasterWindow("小说下载器@sndnvaps", 1000, 800, gimu.MasterWindowFlagDefault) + //Load font + config := nk.NkFontConfig(14) + config.SetOversample(1, 1) + config.SetRange(nk.NkFontChineseGlyphRanges()) + // + customFont = gimu.LoadFontFromFile("./fonts/FZYTK.TTF", 14, &config) + + wnd.Main(updatefn) +} diff --git a/xsbiquge.go b/xsbiquge.go index 4010696..4e57c5b 100644 --- a/xsbiquge.go +++ b/xsbiquge.go @@ -1,4 +1,4 @@ -package main +package ebookdownloader import ( "fmt" @@ -7,8 +7,7 @@ import ( "strings" "github.com/Aiicy/htmlquery" - pool "github.com/dgrr/goslaves" - "gopkg.in/schollz/progressbar.v2" + "github.com/schollz/progressbar/v2" ) //新笔趣阁 xsbiquge.com @@ -153,16 +152,6 @@ func (this EbookXSBiquge) GetChapterContent(pc ProxyChapter) Chapter { return result } -func excuteServe(p *pool.Pool, chapters []Chapter, proxy string) { - for i := 0; i < len(chapters); i++ { - tmp := ProxyChapter{ - Proxy: proxy, - C: chapters[i], - } - p.Serve(tmp) - } -} - //根据每个章节的 url连接,下载每章对应的内容Content当中 func (this EbookXSBiquge) DownloadChapters(Bi BookInfo, proxy string) BookInfo { chapters := Bi.Chapters