Skip to content

Commit

Permalink
Added translations for reCAPTCHA objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Xewdy444 committed Mar 3, 2024
1 parent 191986b commit 85bcb71
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
39 changes: 20 additions & 19 deletions playwright_recaptcha/recaptchav2/async_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
RecaptchaSolveError,
)
from .recaptcha_box import AsyncRecaptchaBox
from .translations import TRANSLATIONS


class AsyncAudioFile(speech_recognition.AudioFile):
Expand Down Expand Up @@ -115,29 +116,29 @@ async def _get_task_object(recaptcha_box: AsyncRecaptchaBox) -> Optional[str]:
The object ID. Returns None if the task object is not recognized.
"""
object_dict = {
"taxis": "/m/0pg52",
"bus": "/m/01bjv",
"school bus": "/m/02yvhj",
"motorcycles": "/m/04_sv",
"tractors": "/m/013xlm",
"chimneys": "/m/01jk_4",
"crosswalks": "/m/014xcs",
"traffic lights": "/m/015qff",
"bicycles": "/m/0199g",
"parking meters": "/m/015qbp",
"cars": "/m/0k4j",
"bridges": "/m/015kr",
"boats": "/m/019jd",
"palm trees": "/m/0cdl1",
"mountains or hills": "/m/09d_r",
"fire hydrant": "/m/01pns0",
"stairs": "/m/01lynh",
"/m/0pg52": TRANSLATIONS["taxis"],
"/m/01bjv": TRANSLATIONS["bus"],
"/m/02yvhj": TRANSLATIONS["school_bus"],
"/m/04_sv": TRANSLATIONS["motorcycles"],
"/m/013xlm": TRANSLATIONS["tractors"],
"/m/01jk_4": TRANSLATIONS["chimneys"],
"/m/014xcs": TRANSLATIONS["crosswalks"],
"/m/015qff": TRANSLATIONS["traffic_lights"],
"/m/0199g": TRANSLATIONS["bicycles"],
"/m/015qbp": TRANSLATIONS["parking_meters"],
"/m/0k4j": TRANSLATIONS["cars"],
"/m/015kr": TRANSLATIONS["bridges"],
"/m/019jd": TRANSLATIONS["boats"],
"/m/0cdl1": TRANSLATIONS["palm_trees"],
"/m/09d_r": TRANSLATIONS["mountains_or_hills"],
"/m/01pns0": TRANSLATIONS["fire_hydrant"],
"/m/01lynh": TRANSLATIONS["stairs"],
}

task = await recaptcha_box.bframe_frame.locator("div").all_inner_texts()

for object_name, object_id in object_dict.items():
if object_name in task[0]:
for object_id, translations in object_dict.items():
if any(translation in task[0] for translation in translations):
return object_id

return None
Expand Down
39 changes: 20 additions & 19 deletions playwright_recaptcha/recaptchav2/sync_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RecaptchaSolveError,
)
from .recaptcha_box import SyncRecaptchaBox
from .translations import TRANSLATIONS


class SyncSolver:
Expand Down Expand Up @@ -77,29 +78,29 @@ def _get_task_object(recaptcha_box: SyncRecaptchaBox) -> Optional[str]:
The object ID. Returns None if the task object is not recognized.
"""
object_dict = {
"taxis": "/m/0pg52",
"bus": "/m/01bjv",
"school bus": "/m/02yvhj",
"motorcycles": "/m/04_sv",
"tractors": "/m/013xlm",
"chimneys": "/m/01jk_4",
"crosswalks": "/m/014xcs",
"traffic lights": "/m/015qff",
"bicycles": "/m/0199g",
"parking meters": "/m/015qbp",
"cars": "/m/0k4j",
"bridges": "/m/015kr",
"boats": "/m/019jd",
"palm trees": "/m/0cdl1",
"mountains or hills": "/m/09d_r",
"fire hydrant": "/m/01pns0",
"stairs": "/m/01lynh",
"/m/0pg52": TRANSLATIONS["taxis"],
"/m/01bjv": TRANSLATIONS["bus"],
"/m/02yvhj": TRANSLATIONS["school_bus"],
"/m/04_sv": TRANSLATIONS["motorcycles"],
"/m/013xlm": TRANSLATIONS["tractors"],
"/m/01jk_4": TRANSLATIONS["chimneys"],
"/m/014xcs": TRANSLATIONS["crosswalks"],
"/m/015qff": TRANSLATIONS["traffic_lights"],
"/m/0199g": TRANSLATIONS["bicycles"],
"/m/015qbp": TRANSLATIONS["parking_meters"],
"/m/0k4j": TRANSLATIONS["cars"],
"/m/015kr": TRANSLATIONS["bridges"],
"/m/019jd": TRANSLATIONS["boats"],
"/m/0cdl1": TRANSLATIONS["palm_trees"],
"/m/09d_r": TRANSLATIONS["mountains_or_hills"],
"/m/01pns0": TRANSLATIONS["fire_hydrant"],
"/m/01lynh": TRANSLATIONS["stairs"],
}

task = recaptcha_box.bframe_frame.locator("div").all_inner_texts()

for object_name, object_id in object_dict.items():
if object_name in task[0]:
for object_id, translations in object_dict.items():
if any(translation in task[0] for translation in translations):
return object_id

return None
Expand Down
17 changes: 17 additions & 0 deletions playwright_recaptcha/recaptchav2/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@
"Please select all matching images",
"Выберите все совпадающие изображения",
),
"taxis": ("taxis", "такси"),
"bus": ("bus", "автобус"),
"school_bus": ("school bus", "школьный автобус"),
"motorcycles": ("motorcycles", "мотоциклы"),
"tractors": ("tractors", "тракторы"),
"chimneys": ("chimneys", "дымоходы"),
"crosswalks": ("crosswalks", "пешеходные переходы"),
"traffic_lights": ("traffic lights", "светофоры"),
"bicycles": ("bicycles", "велосипеды"),
"parking_meters": ("parking meters", "парковочные автоматы"),
"cars": ("cars", "машины"),
"bridges": ("bridges", "мосты"),
"boats": ("boats", "лодки"),
"palm_trees": ("palm trees", "пальмы"),
"mountains_or_hills": ("mountains or hills", "горы или холмы"),
"fire_hydrant": ("fire hydrant", "пожарный гидрант"),
"stairs": ("stairs", "лестницы"),
}

0 comments on commit 85bcb71

Please sign in to comment.