From 5840d9343ac93353106e122d94682e1d63a8db91 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Tue, 26 Dec 2017 16:32:23 +0800 Subject: [PATCH] (*)support generating pdf for kindle DXG --- 168xs.go | 11 +++++------ aszw.go | 11 +++++------ biquge.go | 10 ++++------ luoxia.go | 11 +++++------ main.go | 31 +++++++++++++++++++++---------- piaotian.go | 10 ++++------ shumilou.go | 10 ++++------ uukanshu.go | 10 ++++------ wutuxs.go | 10 ++++------ yssm.go | 10 ++++------ 10 files changed, 60 insertions(+), 64 deletions(-) diff --git a/168xs.go b/168xs.go index 62d7fc0..4f9ea56 100644 --- a/168xs.go +++ b/168xs.go @@ -7,7 +7,6 @@ import ( "regexp" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -81,8 +80,8 @@ func init() { b = ic.Convert("gbk", "utf-8", b) b = bytes.Replace(b, []byte("
\n
([^<]+)
$`) @@ -96,7 +95,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[1] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -105,11 +104,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", tocURL, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) } diff --git a/aszw.go b/aszw.go index 50336d9..70a8f63 100644 --- a/aszw.go +++ b/aszw.go @@ -7,7 +7,6 @@ import ( "regexp" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -67,8 +66,8 @@ func init() { b = ic.Convert("gbk", "utf-8", b) b = bytes.Replace(b, []byte(""), []byte("\n"), -1) b = bytes.Replace(b, []byte(""), []byte("\n"), -1) - mobi := &ebook.Mobi{} - mobi.Begin() + + gen.Begin() var title string // 1、我会对你负责的 @@ -83,7 +82,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[1] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -92,11 +91,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", tocURL, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) } diff --git a/biquge.go b/biquge.go index 40b93d0..29a1416 100644 --- a/biquge.go +++ b/biquge.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -77,8 +76,7 @@ func init() { b = ic.Convert("gbk", "utf-8", b) } - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string var lines []string @@ -101,7 +99,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[p.bookTitlePos] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -125,10 +123,10 @@ func init() { finalURL = articleURL } c := dlPage(finalURL) - mobi.AppendContent(s[p.articleTitlePos], finalURL, string(c)) + gen.AppendContent(s[p.articleTitlePos], finalURL, string(c)) fmt.Println(s[p.articleTitlePos], finalURL, len(c), "bytes") } - mobi.End() + gen.End() } registerNovelSiteHandler(&novelSiteHandler{ diff --git a/luoxia.go b/luoxia.go index 995c394..0220826 100644 --- a/luoxia.go +++ b/luoxia.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" ) @@ -93,8 +92,8 @@ func init() { } b = bytes.Replace(b, []byte("
  • "), []byte("
  • \n
  • "), -1) - mobi := &ebook.Mobi{} - mobi.Begin() + + gen.Begin() var title string //
  • 第二章 破釜沉舟
  • @@ -110,7 +109,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[1] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -121,12 +120,12 @@ func init() { c := dlPage(finalURL) if len(c) > 0 { title := strings.Replace(s[2], ` `, ` `, -1) - mobi.AppendContent(title, finalURL, string(c)) + gen.AppendContent(title, finalURL, string(c)) fmt.Println(title, finalURL, len(c), "bytes") } } } - mobi.End() + gen.End() }, }) } diff --git a/main.go b/main.go index df4804e..1c93f71 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/dfordsoft/golib/ebook" "net/url" "os" "regexp" @@ -32,6 +33,7 @@ type novelSiteHandler struct { var ( novelSiteHandlers []*novelSiteHandler + gen ebook.IBook ) func registerNovelSiteHandler(h *novelSiteHandler) { @@ -64,23 +66,32 @@ func main() { return } - if os.Args[1] == "list" { - listCommandHandler() - return + var novelURL string + for i := 1; i < len(os.Args); i++ { + switch os.Args[i] { + case "list": + listCommandHandler() + return + case "dxg": + gen = &ebook.Pdf{} + default: + _, e := url.Parse(os.Args[i]) + if e == nil { + novelURL = os.Args[i] + } + } } - _, e := url.Parse(os.Args[1]) - if e != nil { - fmt.Println("不支持的输入参数") - listCommandHandler() - return + if gen == nil { + gen = &ebook.Mobi{} } for _, h := range novelSiteHandlers { for _, pattern := range h.MatchPatterns { r, _ := regexp.Compile(pattern) - if r.MatchString(os.Args[1]) { - h.Download(os.Args[1]) + if r.MatchString(novelURL) { + gen.Info() + h.Download(novelURL) return } } diff --git a/piaotian.go b/piaotian.go index eb96ac7..7ffc559 100644 --- a/piaotian.go +++ b/piaotian.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -71,8 +70,7 @@ func init() { return } - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string r, _ = regexp.Compile(`^
  • ([^<]+)
  • $`) @@ -92,7 +90,7 @@ func init() { if idx > 0 { title = title[:idx] } - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -101,11 +99,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", tocURL, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) } diff --git a/shumilou.go b/shumilou.go index 7b70aa9..8fcb54c 100644 --- a/shumilou.go +++ b/shumilou.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -65,8 +64,7 @@ func init() { b = bytes.Replace(b, []byte("
  • "), []byte("
  • \n
  • "), -1) - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string //
  • 阅读指南(重要,必读)
  • @@ -88,7 +86,7 @@ func init() { if idx > 0 { title = title[:idx] } - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -97,11 +95,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", u, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) } diff --git a/uukanshu.go b/uukanshu.go index 9676d04..5a6e440 100644 --- a/uukanshu.go +++ b/uukanshu.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -73,8 +72,7 @@ func init() { return } - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string var lines []string @@ -97,7 +95,7 @@ func init() { if idx > 0 { title = title[:idx] } - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -111,10 +109,10 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", u, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } - mobi.End() + gen.End() }, }) } diff --git a/wutuxs.go b/wutuxs.go index 1a22c80..ab51fc0 100644 --- a/wutuxs.go +++ b/wutuxs.go @@ -7,7 +7,6 @@ import ( "regexp" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" "github.com/dfordsoft/golib/ic" ) @@ -63,8 +62,7 @@ func init() { return } - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string // 第一章.超级网吧系统 @@ -82,7 +80,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[1] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -91,11 +89,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("http://www.wutuxs.com%s", s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) } diff --git a/yssm.go b/yssm.go index 05294a2..4f0c386 100644 --- a/yssm.go +++ b/yssm.go @@ -7,7 +7,6 @@ import ( "regexp" "time" - "github.com/dfordsoft/golib/ebook" "github.com/dfordsoft/golib/httputil" ) @@ -60,8 +59,7 @@ func init() { return } - mobi := &ebook.Mobi{} - mobi.Begin() + gen.Begin() var title string r, _ := regexp.Compile(`
    \s([^<]+)
    $`) @@ -75,7 +73,7 @@ func init() { if len(ss) > 0 && len(ss[0]) > 0 { s := ss[0] title = s[1] - mobi.SetTitle(title) + gen.SetTitle(title) continue } } @@ -84,11 +82,11 @@ func init() { s := ss[0] finalURL := fmt.Sprintf("%s%s", tocURL, s[1]) c := dlPage(finalURL) - mobi.AppendContent(s[2], finalURL, string(c)) + gen.AppendContent(s[2], finalURL, string(c)) fmt.Println(s[2], finalURL, len(c), "bytes") } } - mobi.End() + gen.End() }, }) }