Change into library

master
Stein Ivar Berghei 2022-06-30 13:53:35 +02:00
parent 8d0a42dc97
commit 3ead31eb01
4 changed files with 59 additions and 42 deletions

22
go.mod
View File

@ -1,14 +1,18 @@
module mangasee
go 1.16
go 1.17
require (
github.com/PuerkitoBio/goquery v1.6.1 // indirect
github.com/codegangsta/cli v1.20.0 // indirect
github.com/headzoo/surf v1.0.0 // indirect
github.com/mmcdole/gofeed v1.1.0 // indirect
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac // indirect
gopkg.in/headzoo/surf.v1 v1.0.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
rogchap.com/v8go v0.5.1 // indirect
github.com/PuerkitoBio/goquery v1.6.1
github.com/headzoo/surf v1.0.0
github.com/mmcdole/gofeed v1.1.0
rogchap.com/v8go v0.5.1
)
require (
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/headzoo/ut v0.0.0-20181013193318-a13b5a7a02ca // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
golang.org/x/text v0.3.2 // indirect
)

13
go.sum
View File

@ -4,13 +4,15 @@ github.com/PuerkitoBio/goquery v1.6.1 h1:FgjbQZKl5HTmcn4sKBgvx8vv63nhyhIpv7lJpFG
github.com/PuerkitoBio/goquery v1.6.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/headzoo/surf v1.0.0 h1:d2h9ftKeQYj7tKqAjQtAA0lJVkO8cTxvzdXLynmNnHM=
github.com/headzoo/surf v1.0.0/go.mod h1:/bct0m/iMNEqpn520y01yoaWxsAEigGFPnvyR1ewR5M=
github.com/headzoo/ut v0.0.0-20181013193318-a13b5a7a02ca h1:utFgFwgxaqx5OthzE3DSGrtOq7rox5r2sxZ2wbfTuK0=
github.com/headzoo/ut v0.0.0-20181013193318-a13b5a7a02ca/go.mod h1:8926sG02TCOX4RFRzIMFIzRw4xuc/TwO2gtN7teMJZ4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/mmcdole/gofeed v1.1.0 h1:T2WrGLVJRV04PY2qwhEJLHCt9JiCtBhb6SmC8ZvJH08=
@ -21,17 +23,16 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac h1:kYPjbEN6YPYWWHI6ky1J813KzIq/8+Wg4TO4xU7A/KU=
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@ -41,10 +42,6 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/headzoo/surf.v1 v1.0.0 h1:Ti4LagTvHxSdHYHf5DTqJRhY4+pQYZ0slBPlxo2IWGU=
gopkg.in/headzoo/surf.v1 v1.0.0/go.mod h1:T0BH8276y+OPL0E4tisxCFjBVIAKGbwdYU7AS7/EpQQ=
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
rogchap.com/v8go v0.5.1 h1:yx7uQC2ezAHthCHLHl4NuH3eprVLBtNl6Utm/ELjZ+w=
rogchap.com/v8go v0.5.1/go.mod h1:IitZnaOtWSJadY/7qinKHIEHpxsilMWyLQ+Efdo4n4I=

View File

@ -1,9 +1,9 @@
package main
package mangasee
import (
"embed"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
@ -15,6 +15,10 @@ import (
"rogchap.com/v8go"
)
//go:embed underscore-min.js
//go:embed fakequery.js
var jslib embed.FS
type App struct {
vm *v8go.Isolate
browser *browser.Browser
@ -56,11 +60,12 @@ func (app *App) GetFeed(uri string) (feed *rss.Feed, err error) {
return
}
func (app *App) GetChapterImages(uri string) (err error) {
func (app *App) GetChapterImages(uri string) (pages []string, err error) {
vm, err := v8go.NewContext(app.vm)
if err != nil {
return
}
defer vm.Close()
err = app.browser.Open(uri)
if err != nil {
@ -104,38 +109,31 @@ func (app *App) GetChapterImages(uri string) (err error) {
}
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)
pages = append(pages, fmt.Sprintf("https://%s/manga/%s/%s-%.3d.png", curpathname.String(), chidx.String(), ChapterImage(ch.Chapter), i))
}
return
}
func main() {
var err error
func New() (app *App, err error) {
app = new(App)
app := &App{}
underscore, err := ioutil.ReadFile("./underscore-min.js")
underscore, err := jslib.ReadFile("underscore-min.js")
if err != nil {
panic(err)
return
}
fq, err := ioutil.ReadFile("./fakequery.js")
fq, err := jslib.ReadFile("fakequery.js")
if err != nil {
panic(err)
return
}
app.js = append(app.js, underscore)
@ -150,12 +148,5 @@ func main() {
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)
}
return
}

25
mangasee_test.go Normal file
View File

@ -0,0 +1,25 @@
package mangasee
import (
"fmt"
"testing"
)
func TestManga(t *testing.T) {
app, err := New()
if err != nil {
t.Fatal(err)
}
feed, err := app.GetFeed("https://mangasee123.com/rss/Rurouni-Kenshin-Hokkaido-Arc.xml")
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", feed)
for _, item := range feed.Items {
pages, err := app.GetChapterImages(item.Link)
fmt.Println(pages, err)
}
}