Skip to content

Commit

Permalink
[Captcha] fix #4450
Browse files Browse the repository at this point in the history
  • Loading branch information
GammaC0de committed Apr 20, 2024
1 parent 1da386c commit 08a759a
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/pyload/plugins/base/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class BaseCaptcha(BasePlugin):
__name__ = "BaseCaptcha"
__type__ = "anticaptcha"
__version__ = "0.60"
__version__ = "0.61"
__status__ = "stable"

__description__ = """Base anti-captcha plugin"""
Expand Down Expand Up @@ -83,16 +83,14 @@ def decrypt_image(
result = None
time_ref = "{:.2f}".format(time.time())[-6:].replace(".", "")

with open(
os.path.join(
self.pyload.tempdir,
"captcha_image_{}_{}.{}".format(
self.pyfile.plugin.__name__, time_ref, input_type
),
img_path = os.path.join(
self.pyload.tempdir,
"captcha_image_{}_{}.{}".format(
self.pyfile.plugin.__name__, time_ref, input_type
),
"wb",
) as img_f:
img_f.write(img)
)
with open(img_path, "wb") as img_fp:
img_fp.write(img)

if ocr:
self.log_info(self._("Using OCR to decrypt captcha..."))
Expand All @@ -101,9 +99,9 @@ def decrypt_image(
_OCR = self.pyload.plugin_manager.load_class(
"anticaptcha", ocr
) #: Rename `captcha` to `ocr` in 0.6.x
result = _OCR(self.pyfile).recognize(img_f.name)
result = _OCR(self.pyfile).recognize(img_fp.name)
else:
result = self.recognize(img_f.name)
result = self.recognize(img_fp.name)

if not result:
self.log_warning(self._("No OCR result"))
Expand All @@ -117,7 +115,7 @@ def decrypt_image(
"src": "data:image/{};base64,{}".format(
input_type, to_str(base64.standard_b64encode(img))
),
"file": img_f.name,
"file": img_fp.name,
"captcha_plugin": self.__name__,
"plugin": self.pyfile.plugin.__name__,
"url": self.pyfile.url,
Expand All @@ -132,6 +130,7 @@ def decrypt_image(

finally:
captcha_manager.remove_task(self.task)
os.remove(img_path)

result = self.task.result

Expand All @@ -155,7 +154,7 @@ def decrypt_image(
)

if not self.pyload.debug:
self.remove(img_f.name, try_trash=False)
self.remove(img_fp.name, try_trash=False)

return result

Expand Down

0 comments on commit 08a759a

Please sign in to comment.