|
@@ -230,6 +230,37 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
s.LastThreeTimes = append(s.LastThreeTimes, end)
|
|
|
return 3
|
|
|
}))
|
|
|
+ s.L.SetGlobal("downloadAdvNew", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ cookie := S.ToString(-1)
|
|
|
+ head := S.ToTable(-2)
|
|
|
+ param := S.ToTable(-3)
|
|
|
+ method := S.ToString(-4)
|
|
|
+ url := S.ToString(-5)
|
|
|
+ ishttps := S.ToBool(-6)
|
|
|
+ charset := S.ToString(-7)
|
|
|
+ if charset == "" {
|
|
|
+ charset = s.Encoding
|
|
|
+ }
|
|
|
+ var mycookie []*http.Cookie
|
|
|
+ json.Unmarshal([]byte(cookie), &mycookie)
|
|
|
+ var ret string
|
|
|
+ var retcookie []*http.Cookie
|
|
|
+ var headers = map[string]interface{}{}
|
|
|
+ if param == nil {
|
|
|
+ ptext := map[string]interface{}{"text": S.ToString(-3)}
|
|
|
+ ret, retcookie, headers = DownloadAdvNew(s.Downloader, url, method, ptext, util.GetTable(head), mycookie, charset, s.Userproxy, ishttps, s.SCode, s.Timeout)
|
|
|
+ } else {
|
|
|
+ ret, retcookie, headers = DownloadAdvNew(s.Downloader, url, method, util.GetTable(param), util.GetTable(head), mycookie, charset, s.Userproxy, ishttps, s.SCode, s.Timeout)
|
|
|
+ }
|
|
|
+ S.Push(lua.LString(ret))
|
|
|
+ scookie, _ := json.Marshal(retcookie)
|
|
|
+ S.Push(lua.LString(scookie))
|
|
|
+ hTable := util.MapToLuaTable(S, headers)
|
|
|
+ S.Push(hTable)
|
|
|
+ atomic.AddInt32(&s.ToDayRequestNum, 1)
|
|
|
+ atomic.AddInt32(&s.TotalRequestNum, 1)
|
|
|
+ return 3
|
|
|
+ }))
|
|
|
//下载附件downloadFile(url,method,param,head,cookie,fileName)
|
|
|
//s.L.SetGlobal("downloadFile", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
// if s.FileLastThreeTimes == nil {
|
|
@@ -830,10 +861,14 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
}))
|
|
|
//支持替换
|
|
|
s.L.SetGlobal("replace", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ n := S.ToInt(-4)
|
|
|
+ if n <= 0 {
|
|
|
+ n = -1
|
|
|
+ }
|
|
|
text := S.ToString(-3)
|
|
|
old := S.ToString(-2)
|
|
|
repl := S.ToString(-1)
|
|
|
- text = strings.Replace(text, old, repl, -1)
|
|
|
+ text = strings.Replace(text, old, repl, n)
|
|
|
S.Push(lua.LString(text))
|
|
|
return 1
|
|
|
}))
|
|
@@ -1202,14 +1237,23 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
s.L.SetGlobal("downloadByChrome", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
timeout := S.ToInt64(-2)
|
|
|
taskStr := S.ToString(-1)
|
|
|
- chromeActions := []util.ChromeActions{}
|
|
|
- if json.Unmarshal([]byte(taskStr), &chromeActions) == nil {
|
|
|
- chromeTask := util.ChromeTask{
|
|
|
- TimeOut: timeout,
|
|
|
- Actions: chromeActions,
|
|
|
+ cam := util.ChromeActionMap{}
|
|
|
+ if json.Unmarshal([]byte(taskStr), &cam) == nil {
|
|
|
+ if len(cam.BaseActions) > 0 {
|
|
|
+ if len(cam.RangeActions) > 0 && cam.RangeTimes > 0 {
|
|
|
+ for times := 1; times <= cam.RangeTimes; times++ {
|
|
|
+ cam.BaseActions = append(cam.BaseActions, cam.RangeActions...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ chromeTask := util.ChromeTask{
|
|
|
+ TimeOut: timeout,
|
|
|
+ Actions: cam.BaseActions,
|
|
|
+ }
|
|
|
+ ret := DownloadByChrome(s.SCode, s.Downloader, chromeTask, s.Timeout)
|
|
|
+ S.Push(util.MapToTable(S, ret))
|
|
|
+ } else {
|
|
|
+ S.Push(S.NewTable())
|
|
|
}
|
|
|
- ret := DownloadByChrome(s.SCode, s.Downloader, chromeTask, s.Timeout)
|
|
|
- S.Push(util.MapToTable(S, ret))
|
|
|
} else {
|
|
|
S.Push(S.NewTable())
|
|
|
}
|