Skip to content

Commit

Permalink
添加进度条功能支持
Browse files Browse the repository at this point in the history
  • Loading branch information
sndnvaps committed Dec 6, 2019
1 parent 344dd5b commit 47536cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
## 懒人模式,直接下载编译好的程序

到[这里](https://github.com/sndnvaps/ebookdownloader/releases)下载你需要的版本

## 更新日志

2019.12.6 go版本添加 进度条功能

2019.12.5 添加go语言版本支持

2019.8.22 python版本初始化
13 changes: 11 additions & 2 deletions ebookdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/chain-zhang/pinyin"
pool "github.com/dgrr/GoSlaves"
"github.com/urfave/cli"
"gopkg.in/schollz/progressbar.v2"
)

type BookInfo struct {
Expand Down Expand Up @@ -231,8 +232,10 @@ func excuteServe(p *pool.Pool, chapters []Chapter) {
//根据每个章节的 url连接,下载每章对应的内容Content当中
func (this BookInfo) DownloadChapters() BookInfo {
chapters := this.Chapters
NumChapter := len(chapters)
ch := make(chan Chapter, 1)
locker := sync.Mutex{}
var bar *progressbar.ProgressBar

sp := pool.NewPool(0, func(obj interface{}) {
locker.Lock()
Expand All @@ -245,12 +248,17 @@ func (this BookInfo) DownloadChapters() BookInfo {

go excuteServe(&sp, chapters)

//下载章节的时候显示进度条
bar = progressbar.New(NumChapter)
bar.RenderBlank()

for i := 0; i < len(chapters); {
select {
case c := <-ch:
chapters[i].Content = c.Content
i++
}
bar.Add(1)
}
sp.Close()

Expand Down Expand Up @@ -278,15 +286,16 @@ func EbookDownloader(c *cli.Context) error {

bookinfo := GetBookInfo(bookid)
//下载章节内容
fmt.Printf("正在下载电子书的相应章节,请耐心等待!\n")
bookinfo.DownloadChapters()
//生成txt文件
if isTxt {
fmt.Printf("正在生成txt版本的电子书,请耐心等待!\n")
fmt.Printf("\n正在生成txt版本的电子书,请耐心等待!\n")
bookinfo.GenerateTxt()
}
//生成mobi格式电子书
if isMobi {
fmt.Printf("正在生成mobi版本的电子书,请耐心等待!\n")
fmt.Printf("\n正在生成mobi版本的电子书,请耐心等待!\n")
bookinfo.GenerateMobi()
}
} else {
Expand Down

0 comments on commit 47536cd

Please sign in to comment.