Skip to content

Commit

Permalink
improved code and added another example
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaph committed Feb 5, 2023
1 parent 83ba51b commit 1debda9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CaptchaGO
Easily integrate and support many different captcha APIs in your Go project.
Easily integrate and support many captcha services in your Go project.

[View usage examples](examples)

Expand All @@ -10,7 +10,7 @@ go get github.com/median/captchago

## Supported Services
- [x] [2captcha (ruCaptcha)](https://2captcha.com)
- [x] [AntiCaptcha](https://anti-captcha.com)
- [x] [AntiCaptcha](http://getcaptchasolution.com/ielxn7dpk3)
- [x] [CapMonster](https://capmonster.cloud)
- [x] [AnyCaptcha](https://anycaptcha.com)
- [x] [CapSolver](https://capsolver.com)
Expand All @@ -21,3 +21,4 @@ go get github.com/median/captchago
- [x] Recaptcha V3
- [x] HCaptcha
- [x] FunCaptcha
- [x] Get Balance
18 changes: 8 additions & 10 deletions acmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
r = solver.ForcedDomain
}

// detects if it's an ip or a domain
if strings.Contains(r, ":") || strings.Count(r, ".") == 4 {
r = "http://" + r
} else {
r = "https://" + r
if !strings.Contains(r, "://") {
// detects if it's an ip or a domain
if strings.Contains(r, ":") || strings.Count(r, ".") == 4 {
r = "http://" + r
} else {
r = "https://" + r
}
}

return r
Expand All @@ -33,13 +35,9 @@ func antiCaptchaMethods(solver *Solver, preferredDomain string) *solveMethods {
}

if strings.Contains(d, "anti-captcha.com") {
payload["softId"] = 1029
payload["softId"] = 1080
} else if strings.Contains(d, "capmonster.cloud") {
payload["softId"] = 59
} else if strings.Contains(d, "api.capsolver.com") {
payload["softId"] = 1029 // TODO: get softId for capsolver
} else if strings.Contains(d, "api.anycaptcha.com") {
payload["softId"] = 1029 // TODO: get softId for anycaptcha
}

body, err := postJSON(d+"/createTask", payload)
Expand Down
29 changes: 29 additions & 0 deletions examples/custom_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"github.com/median/captchago"
)

func main() {
// when setting captchago.AntiCaptcha as service, it will use the same API format as anti-captcha.com
// but after setting a forced domain it will just replace anti-captcha.com with the domain you set
solver, err := captchago.New(captchago.AntiCaptcha, "YOUR_API_KEY")
if err != nil {
panic(err)
}

solver.ForcedDomain = "http://custom-service.com"

sol, err := solver.HCaptcha(captchago.HCaptchaOptions{
PageURL: "https://www.hcaptcha.com/demo",
SiteKey: "10000000-ffff-ffff-ffff-000000000001",
})

if err != nil {
panic(err)
}

fmt.Println(sol.Text)
fmt.Println(fmt.Sprintf("Solved in %v ms", sol.Speed))
}
16 changes: 16 additions & 0 deletions solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,29 @@ func (s *Solver) SetService(service SolveService) error {
return nil
}

func (s *Solver) IsValidService(service SolveService) bool {
service = formatService(service)

switch service {
case AntiCaptcha, AnyCaptcha, CapMonster, CapSolver, TwoCaptcha:
return true
}

return false
}

func (s *Solver) GetService() SolveService {
return s.service
}

// formatService formats the service name to reduce the chance of human errors
func formatService(s SolveService) SolveService {
// remove spaces, dashes, and tlds
s = strings.ReplaceAll(strings.ReplaceAll(strings.ToLower(s), " ", ""), "-", "")
s = strings.Split(s, ".")[0]
if strings.Contains(s, "://") {
s = strings.Split(s, "://")[1]
}

// rucaptcha uses same api as 2captcha, its just different name
if s == "rucaptcha" {
Expand Down

0 comments on commit 1debda9

Please sign in to comment.