Skip to content

Commit

Permalink
update verison to v1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sndnvaps committed Jan 22, 2020
1 parent 4627b15 commit 7cc2db2
Show file tree
Hide file tree
Showing 16 changed files with 430 additions and 217 deletions.
61 changes: 2 additions & 59 deletions 23us.la.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main
package ebookdownloader

import (
"fmt"
"strings"
"sync"

"github.com/Aiicy/htmlquery"
"gopkg.in/schollz/progressbar.v2"
"github.com/schollz/progressbar/v2"
)

//参考地址,创建规则
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions 999xs.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main
package ebookdownloader

import (
"fmt"
"strings"
"sync"

"github.com/Aiicy/htmlquery"
"gopkg.in/schollz/progressbar.v2"
"github.com/schollz/progressbar/v2"
)

// https://www.999xs.com/
Expand Down
2 changes: 1 addition & 1 deletion Kindlegen_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build darwin

package main
package ebookdownloader

import (
"os/exec"
Expand Down
2 changes: 1 addition & 1 deletion Kindlegen_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build linux

package main
package ebookdownloader

import (
"os/exec"
Expand Down
2 changes: 1 addition & 1 deletion Kindlegen_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build windows

package main
package ebookdownloader

import (
"os/exec"
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## 安装方法
```bash
go get github.com/sndnvaps/ebookdownloader
go get github.com/sndnvaps/ebookdownloader/cli
```
## 使用方法
```bash
Expand All @@ -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中阅读
Expand Down Expand Up @@ -87,3 +92,4 @@
[√] 1.添加生成封面功能
[√] 2. 添加不同平台的接口实现
[√] 3. 添加生成二级目录的方法(已经添加相应的实例)
[ ] 4. 添加界面版本gui
9 changes: 9 additions & 0 deletions cli/build.cmd
Original file line number Diff line number Diff line change
@@ -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 ..\
8 changes: 8 additions & 0 deletions cli/build.sh
Original file line number Diff line number Diff line change
@@ -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 ../
149 changes: 149 additions & 0 deletions cli/ebookdl_cli.go
Original file line number Diff line number Diff line change
@@ -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: "[email protected]",
},
}
app.Copyright = "(c) 2019 - 2020 Jimes Yang<[email protected]>"
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)
}

}
2 changes: 1 addition & 1 deletion ebookCover.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package ebookdownloader

import (
"fmt"
Expand Down
Loading

0 comments on commit 7cc2db2

Please sign in to comment.