Compare commits

..

No commits in common. "master" and "v0.1.1" have entirely different histories.

3 changed files with 10 additions and 38 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
debug.test

View File

@ -9,7 +9,6 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"sync"
"time"
@ -56,35 +55,11 @@ type Label struct {
label string
conditionJS string
retry string
waitcapture string
configlock sync.Mutex
conditionlock sync.Mutex
cli *Client
}
// GetWaitime Get return waitime int
func (l *Label) GetWaitime() int {
r, _ := strconv.Atoi(l.waitcapture)
return r
}
// SetWaitime Set waitime int
func (l *Label) SetWaitime(waitime int) {
l.waitcapture = strconv.Itoa(waitime)
}
// GetRetry Get return retry int
func (l *Label) GetRetry() int {
r, _ := strconv.Atoi(l.retry)
return r
}
// SetRetry Set retry int
func (l *Label) SetRetry(retry int) {
l.retry = strconv.Itoa(retry)
}
// GetHash 根据label获取hash路径
func (l *Label) GetHash(label string) string {
if cb, ok := l.cli.register.Load(label); ok {
@ -108,8 +83,8 @@ func (l *Label) Open(urlstr string, carray interface{}) (bodyRes string, ok bool
// SetContentCondition 设置识别到的内容条件. js代码. 必须是一个函数. 命名可以随意. 返回bool
func (l *Label) SetContentCondition(jsScript string) {
l.configlock.Lock()
defer l.configlock.Unlock()
l.conditionlock.Lock()
defer l.conditionlock.Unlock()
l.conditionJS = jsScript
}
@ -123,8 +98,8 @@ func (l *Label) SetContentConditionFromFile(jsScriptFile string) {
if err != nil {
panic(err)
}
l.configlock.Lock()
defer l.configlock.Unlock()
l.conditionlock.Lock()
defer l.conditionlock.Unlock()
// log.Println(string(data))
l.conditionJS = string(data)
}
@ -157,7 +132,7 @@ func (cli *Client) Register(label string, callback func(cxt *CallbackContext)) *
}
cli.register.Store(label, cb)
cli.register.Store(cb.hash, cb)
l := &Label{label: label, cli: cli, waitcapture: "6000", retry: "1"}
l := &Label{label: label, cli: cli}
return l
}
@ -264,11 +239,9 @@ func (cli *Client) open(label *Label, urlstr string, carray interface{}) (bodyRe
}
func() {
label.configlock.Lock()
defer label.configlock.Unlock()
label.conditionlock.Lock()
defer label.conditionlock.Unlock()
data["content_condition"] = []string{label.conditionJS}
data["waitcapture"] = []string{label.waitcapture}
data["retry"] = []string{label.retry}
}()
resp, err := http.DefaultClient.PostForm(cli.chromeProxyAddr+"/task/put", data)

View File

@ -20,7 +20,7 @@ func TestPort(t *testing.T) {
ltest.SetContentConditionFromFile("example.js")
cli.Connect()
log.Println(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser", nil))
// log.Println(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser", nil))
// log.Println(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/yanngu?lang=en&deviceType=browser", "213"))
// log.Println(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"))
// log.Println(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/yanngu?lang=en&deviceType=browser"))