Skip to content

Commit

Permalink
update version to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sndnvaps committed Jan 3, 2020
1 parent 4e2944c commit 0cd40b2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
.\ebookdownloader.exe --bookid=0_642 --txt #只生成txt文本
.\ebookdownloader.exe --bookid=0_642 --mobi #只生成mobi电子书
.\ebookdownloader.exe --bookid=0_642 --txt --mobi #生成txt 和 mobi
.\ebookdownloader.exe --bookid=0_642 --txt --awz3 #生成txt 和 awz3
.\ebookdownloader.exe --proxy="http://proxyip:proxyport" --bookid=0_642 --mobi #生成mobi电子书,在下载章节的过程中使用 Proxy
.\ebookdownloader.exe --ebhost=xsbiquge.com --bookid=0_642 --txt --mobi #使用xsbiquge.com做为下载源,生成txt 和 mobi
.\ebookdownloader.exe --ebhost=999xs.com --bookid=0_642 --txt --mobi #使用999xs.com做为下载源,生成txt 和 mobi
Expand All @@ -31,6 +32,11 @@

## 更新日志

2020.01.03 go版本 更新
1. 修改生成电子书的压缩比为-c2,使生成的文件更小
2. 添加生成awz3格式支持(注意,--mobi,--awz3只能使用一个,不能同时使用)
3. 修改封面的引用方法

2019.12.29 go版本 完成实现 999xs.com平台的小说下载接口

2019.12.27 go版本 实现不同小说平台的interface{}接口,方便加入新的小说网站
Expand Down
50 changes: 42 additions & 8 deletions ebookdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type BookInfo struct {
Name string
Author string
Description string
IsMobi bool //当为true的时候生成mobi
IsAwz3 bool //当为true的时候生成awz3,
Chapters []Chapter
}

Expand Down Expand Up @@ -50,6 +52,13 @@ func WriteFile(filename string, data []byte) error {
return ioutil.WriteFile(filename, data, 0655)
}

//设置生成mobi格式,或者生成awz3格式
//现在设置,mobi和awz3格式不能同时设置为true
func (this *BookInfo) SetKindleEbookType(isMobi bool, isAwz3 bool) {
this.IsMobi = isMobi
this.IsAwz3 = isAwz3
}

//生成txt电子书
func (this BookInfo) GenerateTxt() {
chapters := this.Chapters
Expand Down Expand Up @@ -160,6 +169,7 @@ func (this BookInfo) GenerateMobi() {
opf_content = strings.Replace(opf_content, "___DESCRIPTION___", this.Description, -1)
//写入发布者信息
opf_content = strings.Replace(opf_content, "___PUBLISHER___", "sndnvaps", -1)
//把修改内容写入到content.opf文件中
WriteFile(savepath+"/content.opf", []byte(opf_content))

if !com.IsExist("./outputs") {
Expand All @@ -175,10 +185,16 @@ func (this BookInfo) GenerateMobi() {
os.RemoveAll("cover.jpg")

// 生成
outfname := this.Name + "-" + this.Author + ".mobi"
outfname := this.Name + "-" + this.Author
if this.IsMobi {
outfname += ".mobi"
}
if this.IsAwz3 {
outfname += ".awz3"
}
//-dont_append_source ,禁止mobi 文件中附加源文件
//cmd := exec.Command("./tools/kindlegen.exe", "-dont_append_source", savepath+"/content.opf", "-c1", "-o", outfname)
cmd := KindlegenCmd("-dont_append_source", savepath+"/content.opf", "-c1", "-o", outfname)
//cmd := exec.Command("./tools/kindlegen.exe", "-dont_append_source", savepath+"/content.opf", "-c2", "-o", outfname)
cmd := KindlegenCmd("-dont_append_source", savepath+"/content.opf", "-c2", "-o", outfname)
cmd.Run()

// 把生成的mobi文件复制到 outputs/目录下面
Expand All @@ -199,11 +215,12 @@ func EbookDownloader(c *cli.Context) error {

isTxt := c.Bool("txt")
isMobi := c.Bool("mobi")
isAwz3 := c.Bool("awz3")

var bookinfo BookInfo //初始化变量
var EBDLInterface EBookDLInterface //初始化接口
//isTxt 或者 isMobi必须一个为真,或者两个都为真
if (isTxt || isMobi) || (isTxt && isMobi) {
if (isTxt || isMobi || isAwz3) || (isTxt && isMobi) || (isTxt && isAwz3) {

if ebhost == "xsbiquge.com" {
xsbiquge := NewXSBiquge()
Expand All @@ -215,6 +232,11 @@ func EbookDownloader(c *cli.Context) error {
cli.ShowAppHelpAndExit(c, 0)
return nil
}
// isMobi && isAwz3 当同时为真的时候,退出进程
if isMobi && isAwz3 {
cli.ShowAppHelpAndExit(c, 0)
return nil
}
bookinfo = EBDLInterface.GetBookInfo(bookid, proxy)

//下载章节内容
Expand All @@ -228,8 +250,16 @@ func EbookDownloader(c *cli.Context) error {
//生成mobi格式电子书
if isMobi {
fmt.Printf("\n正在生成mobi版本的电子书,请耐心等待!\n")
bookinfo.SetKindleEbookType(true /* isMobi */, false /* isAwz3 */)
bookinfo.GenerateMobi()
}
//生成awz3格式电子书
if isAwz3 {
fmt.Printf("\n正在生成Awz3版本的电子书,请耐心等待!\n")
bookinfo.SetKindleEbookType(false /* isMobi */, true /* isAwz3 */)
bookinfo.GenerateMobi()
}

} else {
cli.ShowAppHelpAndExit(c, 0)
return nil
Expand All @@ -244,15 +274,15 @@ func main() {
app := cli.NewApp()
app.Name = "golang EBookDownloader"
app.Compiled = time.Now()
app.Version = "1.4.0"
app.Version = "1.5.0"
app.Authors = []cli.Author{
cli.Author{
Name: "Jimes Yang",
Email: "[email protected]",
},
}
app.Copyright = "(c) 2019 Jimes Yang<[email protected]>"
app.Usage = "用于下载 笔趣阁(https://www.xsbiquge.com),999小说网(https://www.999xs.com/) 上面的电子书,并保存为txt格式或者mobi格式的电子书"
app.Copyright = "(c) 2019 - 2020 Jimes Yang<[email protected]>"
app.Usage = "用于下载 笔趣阁(https://www.xsbiquge.com),999小说网(https://www.999xs.com/) 上面的电子书,并保存为txt格式或者(mobi格式,awz3格式)的电子书"
app.Action = EbookDownloader
app.Flags = []cli.Flag{
cli.StringFlag{
Expand All @@ -274,7 +304,11 @@ func main() {
},
cli.BoolFlag{
Name: "mobi",
Usage: "当使用的时候,生成mobi文件",
Usage: "当使用的时候,生成mobi文件(不可与--awz3同时使用)",
},
cli.BoolFlag{
Name: "awz3",
Usage: "当使用的时候,生成awz3文件(不可与--mobi同时使用)",
},
}

Expand Down
12 changes: 11 additions & 1 deletion ebookdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ func TestGenerateTxt(t *testing.T) {
savename := "./outputs/" + testbi.Name + "-" + testbi.Author + ".txt"

assert.True(t, true, isExist(savename))
os.RemoveAll(savename)
//os.RemoveAll(savename)

}

func TestGenerateMobi(t *testing.T) {
testbi.SetKindleEbookType(true /* isMobi */, false /* isAwz3 */)
testbi.GenerateMobi()
savename := "./outputs/" + testbi.Name + "-" + testbi.Author + ".mobi"

assert.True(t, true, isExist(savename))
//os.RemoveAll(savename)
}

func TestGenerateAwz3(t *testing.T) {
testbi.SetKindleEbookType(false /* isMobi */, true /* isAwz3 */)
testbi.GenerateMobi()
savename := "./outputs/" + testbi.Name + "-" + testbi.Author + ".awz3"

assert.True(t, true, isExist(savename))
//os.RemoveAll(savename)
}

// IsExist checks whether a file or directory exists.
// It returns false when the file or directory does not exist.
func isExist(path string) bool {
Expand Down
5 changes: 3 additions & 2 deletions tpls/tpl_content.opf
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
<dc:date>___CREATE_TIME___</dc:date>
<dc:description>___DESCRIPTION___</dc:description>
<dc:publisher>___PUBLISHER___</dc:publisher>
<dc:rights>Created with Ebookdownloader v1.3.0</dc:rights>
<dc:rights>Created with Ebookdownloader v1.5.0</dc:rights>
<dc:language>zh-CN</dc:language>
</dc-metadata>
<meta name="cover" content="Cover" />
<x-metadata>
<output encoding="utf-8"></output>
<EmbeddedCover>cover.jpg</EmbeddedCover>
</x-metadata>
</metadata>
<manifest>
<item id="ncxtoc" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
<item id="htmltoc" href="book-toc.html" media-type="application/xhtml+xml"/>
<item id="css" href="style.css" media-type="text/css"/>
___MANIFEST___
<item id="Cover" media-type="image/jpeg" href="cover.jpg"/>
</manifest>
<spine toc="ncxtoc">
<itemref idref="htmltoc" linear="yes"/>
Expand Down

0 comments on commit 0cd40b2

Please sign in to comment.