Update captcha job

This commit is contained in:
Omar Roth 2020-05-25 12:52:15 -05:00
parent 750ef296c6
commit ceb252986e
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2
3 changed files with 16 additions and 9 deletions

View File

@ -26,7 +26,7 @@ dependencies:
version: ~> 0.1.2 version: ~> 0.1.2
lsquic: lsquic:
github: omarroth/lsquic.cr github: omarroth/lsquic.cr
version: ~> 0.1.9 branch: dev
crystal: 0.34.0 crystal: 0.34.0

View File

@ -295,7 +295,9 @@ def bypass_captcha(captcha_key, logger)
inputs[node["name"]] = node["value"] inputs[node["name"]] = node["value"]
end end
response = JSON.parse(HTTP::Client.post("https://api.anti-captcha.com/createTask", body: { captcha_client = HTTPClient.new(URI.parse("https://api.anti-captcha.com"))
captcha_client.family = CONFIG.force_resolve || Socket::Family::INET
response = JSON.parse(captcha_client.post("/createTask", body: {
"clientKey" => CONFIG.captcha_key, "clientKey" => CONFIG.captcha_key,
"task" => { "task" => {
"type" => "NoCaptchaTaskProxyless", "type" => "NoCaptchaTaskProxyless",
@ -310,7 +312,7 @@ def bypass_captcha(captcha_key, logger)
loop do loop do
sleep 10.seconds sleep 10.seconds
response = JSON.parse(HTTP::Client.post("https://api.anti-captcha.com/getTaskResult", body: { response = JSON.parse(captcha_client.post("/getTaskResult", body: {
"clientKey" => CONFIG.captcha_key, "clientKey" => CONFIG.captcha_key,
"taskId" => task_id, "taskId" => task_id,
}.to_json).body) }.to_json).body)
@ -323,9 +325,11 @@ def bypass_captcha(captcha_key, logger)
end end
inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s
client = HTTPClient.new(location) headers["content-type"] = "application/x-www-form-urlencoded"
client.family = CONFIG.force_resolve || Socket::Family::INET headers["origin"] = "https://www.google.com"
response = client.post(location.full_path, form: inputs) headers["user-agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
response = YT_POOL.client &.post("/sorry/index", headers: headers, form: inputs)
headers = HTTP::Headers{ headers = HTTP::Headers{
"Cookie" => URI.parse(response.headers["location"]).query_params["google_abuse"].split(";")[0], "Cookie" => URI.parse(response.headers["location"]).query_params["google_abuse"].split(";")[0],
} }

View File

@ -2,13 +2,16 @@ require "lsquic"
require "pool/connection" require "pool/connection"
def add_yt_headers(request) def add_yt_headers(request)
request.headers["x-youtube-client-name"] ||= "1"
request.headers["x-youtube-client-version"] ||= "1.20180719"
request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36" request.headers["user-agent"] ||= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
request.headers["accept-charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7" request.headers["accept-charset"] ||= "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
request.headers["accept"] ||= "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" request.headers["accept"] ||= "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
request.headers["accept-language"] ||= "en-us,en;q=0.5" request.headers["accept-language"] ||= "en-us,en;q=0.5"
return if request.resource.starts_with? "/sorry/index"
request.headers["x-youtube-client-name"] ||= "1"
request.headers["x-youtube-client-version"] ||= "1.20180719"
if !CONFIG.cookies.empty?
request.headers["cookie"] = "#{(CONFIG.cookies.map { |c| "#{c.name}=#{c.value}" }).join("; ")}; #{request.headers["cookie"]?}" request.headers["cookie"] = "#{(CONFIG.cookies.map { |c| "#{c.name}=#{c.value}" }).join("; ")}; #{request.headers["cookie"]?}"
end
end end
struct QUICPool struct QUICPool