162 lines
2.9 KiB
Go
162 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
"github.com/headzoo/surf"
|
|
"github.com/headzoo/surf/browser"
|
|
"github.com/mmcdole/gofeed/rss"
|
|
"rogchap.com/v8go"
|
|
)
|
|
|
|
type App struct {
|
|
vm *v8go.Isolate
|
|
browser *browser.Browser
|
|
fp rss.Parser
|
|
http *http.Client
|
|
js [][]byte
|
|
}
|
|
|
|
type MangaSeeChapter struct {
|
|
Chapter string
|
|
Type string
|
|
Page string
|
|
Date string
|
|
ChapterName string
|
|
Directory string
|
|
}
|
|
|
|
func ChapterImage(chstr string) string {
|
|
ch := chstr[1 : len(chstr)-1]
|
|
odd := chstr[len(chstr)-1:]
|
|
if odd == "0" {
|
|
return ch
|
|
} else {
|
|
return fmt.Sprintf("%s.%s", ch, odd)
|
|
}
|
|
}
|
|
|
|
func (app *App) GetFeed(uri string) (feed *rss.Feed, err error) {
|
|
resp, err := app.http.Get(uri)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
feed, err = app.fp.Parse(resp.Body)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (app *App) GetChapterImages(uri string) (err error) {
|
|
vm, err := v8go.NewContext(app.vm)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = app.browser.Open(uri)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, f := range app.js {
|
|
_, err = vm.RunScript(string(f), "app.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
app.browser.Dom().Find("script").Each(func(_ int, s *goquery.Selection) {
|
|
if strings.Contains(s.Text(), "function MainFunction($http, $timeout){") {
|
|
_, err := vm.RunScript(s.Text(), "main.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
})
|
|
|
|
_, err = vm.RunScript("MainFunction()", "main.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
curpathname, err := vm.RunScript("CurPathName", "main.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
chidx, err := vm.RunScript("IndexName", "main.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
chjson, err := vm.RunScript("JSON.stringify(CurChapter)", "main.js")
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var ch MangaSeeChapter
|
|
|
|
err = json.Unmarshal([]byte(chjson.String()), &ch)
|
|
|
|
// src="https://{{vm.CurPathName}}/manga/To-You-The-Immortal/{{vm.CurChapter.Directory == '' ? '' : vm.CurChapter.Directory+'/'}}{{vm.ChapterImage(vm.CurChapter.Chapter)}}-{{vm.PageImage(Page)}}.png"
|
|
|
|
//fmt.Println(ch)
|
|
|
|
page, err := strconv.Atoi(ch.Page)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for i := 1; i <= page; i++ {
|
|
fmt.Printf("(%s) https://%s/manga/%s/%s-%.3d.png\n", ch.Chapter, curpathname.String(), chidx.String(), ChapterImage(ch.Chapter), i)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func main() {
|
|
var err error
|
|
|
|
app := &App{}
|
|
|
|
underscore, err := ioutil.ReadFile("./underscore-min.js")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fq, err := ioutil.ReadFile("./fakequery.js")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
app.js = append(app.js, underscore)
|
|
app.js = append(app.js, fq)
|
|
|
|
app.http = &http.Client{}
|
|
app.vm, err = v8go.NewIsolate()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
app.browser = surf.NewBrowser()
|
|
app.fp = rss.Parser{}
|
|
|
|
feed, err := app.GetFeed("https://mangasee123.com/rss/Rurouni-Kenshin-Hokkaido-Arc.xml")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for _, item := range feed.Items {
|
|
app.GetChapterImages(item.Link)
|
|
}
|
|
}
|