Skip to content

Commit

Permalink
[新增]臺灣華文電子書庫
Browse files Browse the repository at this point in the history
  • Loading branch information
zhudw committed Oct 14, 2023
1 parent 0c9fd30 commit 723f3b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/huawen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Huawen struct {
}

func (r *Huawen) Init(iTask int, sUrl string) (msg string, err error) {
if !strings.Contains(sUrl, "/reader") && strings.Contains(sUrl, "/zh-tw/book/") {
sUrl += "/reader"
}
r.dt = new(DownloadTask)
r.dt.UrlParsed, err = url.Parse(sUrl)
r.dt.Url = sUrl
Expand Down Expand Up @@ -90,12 +93,15 @@ func (r *Huawen) getVolumes(sUrl string, jar *cookiejar.Jar) (volumes []string,
if err != nil {
return
}
matches := regexp.MustCompile(`viewer.html\?file=([^"]+)"`).FindAllSubmatch(bs, -1)
matches := regexp.MustCompile(`(?i)viewer.html\?file=([^"]+)"`).FindAllSubmatch(bs, -1)
if matches == nil {
return
}
for _, match := range matches {
sPath := strings.TrimSpace(string(match[1]))
if pos := strings.Index(sPath, "&"); pos > 0 {
sPath = sPath[:pos]
}
pdfUrl := "https://" + r.dt.UrlParsed.Host + sPath
volumes = append(volumes, pdfUrl)
}
Expand Down

0 comments on commit 723f3b5

Please sign in to comment.