summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-08-17 01:00:41 +0200
committerGravatar zoidberg10 <zoidberg@mujmail.cz> 2012-08-17 01:00:41 +0200
commit09731ea0da4753992de70d36d3fc87b5756e5271 (patch)
treeb9f0eb844c312814d6dc572a8dba9a88eb729475 /module
parent2shared - closed #656, 4shared - closed #651 (dl with free account only) (diff)
downloadpyload-09731ea0da4753992de70d36d3fc87b5756e5271.tar.xz
fix multipart post encoding, add workaround for captcha hooks
Diffstat (limited to 'module')
-rw-r--r--module/network/HTTPRequest.py2
-rw-r--r--module/plugins/hooks/DeathByCaptcha.py24
-rw-r--r--module/plugins/hooks/ImageTyperz.py38
3 files changed, 51 insertions, 13 deletions
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py
index d4c33bbff..4747d937f 100644
--- a/module/network/HTTPRequest.py
+++ b/module/network/HTTPRequest.py
@@ -167,7 +167,7 @@ class HTTPRequest():
self.c.setopt(pycurl.POSTFIELDS, post)
else:
- post = [(x, str(quote(y)) if type(y) in (str, unicode) else y ) for x, y in post.iteritems()]
+ post = [(x, y.encode('utf8') if type(y) == unicode else y ) for x, y in post.iteritems()]
self.c.setopt(pycurl.HTTPPOST, post)
else:
self.c.setopt(pycurl.POST, 0)
diff --git a/module/plugins/hooks/DeathByCaptcha.py b/module/plugins/hooks/DeathByCaptcha.py
index ab64299dd..59ff40ded 100644
--- a/module/plugins/hooks/DeathByCaptcha.py
+++ b/module/plugins/hooks/DeathByCaptcha.py
@@ -15,10 +15,13 @@
@author: mkaay, RaNaN, zoidberg
"""
+from __future__ import with_statement
from thread import start_new_thread
from pycurl import FORM_FILE, HTTPHEADER, RESPONSE_CODE
from time import sleep
+from base64 import b64encode
+import re
from module.network.RequestFactory import getURL, getRequest
from module.network.HTTPRequest import BadHeader
@@ -55,7 +58,7 @@ class DeathByCaptchaException(Exception):
class DeathByCaptcha(Hook):
__name__ = "DeathByCaptcha"
- __version__ = "0.02"
+ __version__ = "0.03"
__description__ = """send captchas to DeathByCaptcha.com"""
__config__ = [("activated", "bool", "Activated", False),
("username", "str", "Username", ""),
@@ -119,9 +122,25 @@ class DeathByCaptcha(Hook):
self.info.update(response)
else:
raise DeathByCaptchaException(response)
+
+ def getStatus(self):
+ response = self.call_api("status", False)
+
+ if 'is_service_overloaded' in response and response['is_service_overloaded']:
+ raise DeathByCaptchaException('service-overload')
def submit(self, captcha, captchaType="file", match=None):
- response = self.call_api("captcha", {"captchafile": (FORM_FILE, captcha)}, True)
+ #workaround multipart-post bug in HTTPRequest.py
+ if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")):
+ multipart = True
+ data = (FORM_FILE, captcha)
+ else:
+ multipart = False
+ with open(captcha, 'rb') as f:
+ data = f.read()
+ data = "base64:" + b64encode(data)
+
+ response = self.call_api("captcha", {"captchafile": data}, multipart)
if "captcha" not in response:
raise DeathByCaptchaException(response)
@@ -154,6 +173,7 @@ class DeathByCaptcha(Hook):
return False
try:
+ self.getStatus()
self.getCredits()
except DeathByCaptchaException, e:
self.logError(e.getDesc())
diff --git a/module/plugins/hooks/ImageTyperz.py b/module/plugins/hooks/ImageTyperz.py
index f27eccf26..59b6334a7 100644
--- a/module/plugins/hooks/ImageTyperz.py
+++ b/module/plugins/hooks/ImageTyperz.py
@@ -15,6 +15,7 @@
@author: mkaay, RaNaN, zoidberg
"""
+from __future__ import with_statement
from thread import start_new_thread
from pycurl import FORM_FILE, LOW_SPEED_TIME
@@ -23,6 +24,8 @@ from module.network.RequestFactory import getURL, getRequest
from module.network.HTTPRequest import BadHeader
from module.plugins.Hook import Hook
+import re
+from base64 import b64encode
class ImageTyperzException(Exception):
def __init__(self, err):
@@ -39,7 +42,7 @@ class ImageTyperzException(Exception):
class ImageTyperz(Hook):
__name__ = "ImageTyperz"
- __version__ = "0.02"
+ __version__ = "0.03"
__description__ = """send captchas to ImageTyperz.com"""
__config__ = [("activated", "bool", "Activated", True),
("username", "str", "Username", ""),
@@ -66,9 +69,12 @@ class ImageTyperz(Hook):
raise ImageTyperzException(response)
try:
- return float(response)
+ balance = float(response)
except:
raise ImageTyperzException("invalid response")
+
+ self.logInfo("Account balance: $%s left" % response)
+ return balance
def submit(self, captcha, captchaType="file", match=None):
req = getRequest()
@@ -76,12 +82,22 @@ class ImageTyperz(Hook):
req.c.setopt(LOW_SPEED_TIME, 80)
try:
- response = req.load(self.SUBMIT_URL,
- post={ "action": "UPLOADCAPTCHA",
- "username": self.getConfig("username"),
- "password": self.getConfig("passkey"),
- "file": (FORM_FILE, captcha)},
- multipart=True)
+ #workaround multipart-post bug in HTTPRequest.py
+ if re.match("^[A-Za-z0-9]*$", self.getConfig("passkey")):
+ multipart = True
+ data = (FORM_FILE, captcha)
+ else:
+ multipart = False
+ with open(captcha, 'rb') as f:
+ data = f.read()
+ data = b64encode(data)
+
+ response = req.load(self.SUBMIT_URL,
+ post={ "action": "UPLOADCAPTCHA",
+ "username": self.getConfig("username"),
+ "password": self.getConfig("passkey"),
+ "file": data},
+ multipart = multipart)
finally:
req.close()
@@ -127,8 +143,10 @@ class ImageTyperz(Hook):
"imageid": task.data["ticket"]}
)
- if not response == "SUCCESS":
- self.logError(("Refund request failed"), response)
+ if response == "SUCCESS":
+ self.logInfo("Bad captcha solution received, requested refund")
+ else:
+ self.logError("Bad captcha solution received, refund request failed", response)
def processCaptcha(self, task):
c = task.captchaFile