summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/internal/BasePlugin.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-07 15:34:19 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-07 15:34:19 +0100
commitd8771b13f1c658ac726ac93195a48ad87169eccd (patch)
treea81899c2905d59ff20341ffcad35c949d880a0b4 /pyload/plugins/internal/BasePlugin.py
parentTiny code cosmetics (diff)
parent[SkipRev] Tiny fixup (diff)
downloadpyload-d8771b13f1c658ac726ac93195a48ad87169eccd.tar.xz
Merge branch 'stable' into 0.4.10
Conflicts: module/plugins/hoster/NowDownloadEu.py module/plugins/hoster/NowDownloadSx.py module/plugins/hoster/NowVideoAt.py module/plugins/hoster/NowVideoSx.py pyload/plugins/account/RapidshareCom.py pyload/plugins/addon/ExtractArchive.py pyload/plugins/addon/HotFolder.py pyload/plugins/addon/UpdateManager.py pyload/plugins/hook/Captcha9kw.py pyload/plugins/hook/DebridItaliaCom.py pyload/plugins/hoster/DebridItaliaCom.py pyload/plugins/hoster/Keep2shareCc.py pyload/plugins/hoster/NetloadIn.py pyload/plugins/hoster/NowDownloadEu.py pyload/plugins/hoster/NowVideoAt.py pyload/plugins/hoster/RapidshareCom.py pyload/plugins/hoster/ShareonlineBiz.py pyload/plugins/internal/MultiHoster.py pyload/plugins/internal/SimpleHoster.py
Diffstat (limited to 'pyload/plugins/internal/BasePlugin.py')
-rw-r--r--pyload/plugins/internal/BasePlugin.py98
1 files changed, 49 insertions, 49 deletions
diff --git a/pyload/plugins/internal/BasePlugin.py b/pyload/plugins/internal/BasePlugin.py
index f4abc1a15..a9d81d079 100644
--- a/pyload/plugins/internal/BasePlugin.py
+++ b/pyload/plugins/internal/BasePlugin.py
@@ -3,7 +3,7 @@
import re
from urllib import unquote
-from urlparse import urlparse
+from urlparse import urljoin, urlparse
from pyload.network.HTTPRequest import BadHeader
from pyload.plugins.internal.SimpleHoster import create_getInfo
@@ -13,7 +13,7 @@ from pyload.plugins.internal.Hoster import Hoster
class BasePlugin(Hoster):
__name__ = "BasePlugin"
__type__ = "hoster"
- __version__ = "0.23"
+ __version__ = "0.25"
__pattern__ = r'^unmatchable$'
@@ -25,7 +25,7 @@ class BasePlugin(Hoster):
@classmethod
def getInfo(cls, url="", html=""): #@TODO: Move to hoster class in 0.4.10
- return {'name': urlparse(url).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3, 'url': url or ""}
+ return {'name': urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3 if url else 1, 'url': unquote(url) or ""}
def setup(self):
@@ -38,69 +38,69 @@ class BasePlugin(Hoster):
pyfile.name = self.getInfo(pyfile.url)['name']
- if pyfile.url.startswith("http"):
- for _i in xrange(2):
- try:
- self.downloadFile(pyfile)
+ if not pyfile.url.startswith("http"):
+ self.fail(_("No plugin matched"))
+
+ for _i in xrange(5):
+ try:
+ self.downloadFile(pyfile)
- except BadHeader, e:
- if e.code is 404:
- self.offline()
+ except BadHeader, e:
+ if e.code is 404:
+ self.offline()
- elif e.code in (401, 403):
- self.logDebug("Auth required")
+ elif e.code in (401, 403):
+ self.logDebug("Auth required", "Received HTTP status code: %d" % e.code)
- account = self.core.accountManager.getAccountPlugin('Http')
- servers = [x['login'] for x in account.getAllAccounts()]
- server = urlparse(pyfile.url).netloc
+ account = self.core.accountManager.getAccountPlugin('Http')
+ servers = [x['login'] for x in account.getAllAccounts()]
+ server = urlparse(pyfile.url).netloc
- if server in servers:
- self.logDebug("Logging on to %s" % server)
- self.req.addAuth(account.accounts[server]['password'])
- else:
- for pwd in pyfile.package().password.splitlines():
- if ":" in pwd:
- self.req.addAuth(pwd.strip())
- break
- else:
- self.fail(_("Authorization required (username:password)"))
+ if server in servers:
+ self.logDebug("Logging on to %s" % server)
+ self.req.addAuth(account.accounts[server]['password'])
else:
- self.fail(e)
+ for pwd in self.getPassword().splitlines():
+ if ":" in pwd:
+ self.req.addAuth(pwd.strip())
+ break
+ else:
+ self.fail(_("Authorization required"))
else:
- break
+ self.fail(e)
else:
- self.fail(_("No file downloaded")) #@TODO: Move to hoster class (check if self.lastDownload) in 0.4.10
+ break
else:
- self.fail(_("No plugin matched"))
+ self.fail(_("No file downloaded")) #@TODO: Move to hoster class in 0.4.10
- # if self.checkDownload({'empty': re.compile(r"^$")}) is "empty":
- # self.fail(_("Empty file"))
+ if self.checkDownload({'empty': re.compile(r"^$")}) is "empty": #@TODO: Move to hoster in 0.4.10
+ self.fail(_("Empty file"))
def downloadFile(self, pyfile):
url = pyfile.url
- for _i in xrange(5):
- header = self.load(url, just_header=True)
-
- # self.load does not raise a BadHeader on 404 responses, do it here
- if 'code' in header and header['code'] == 404:
- raise BadHeader(404)
+ for i in xrange(1, 7): #@TODO: retrieve the pycurl.MAXREDIRS value set by req
+ header = self.load(url, ref=True, cookies=True, just_header=True, decode=True)
- if 'location' in header:
- self.logDebug("Location: " + header['location'])
-
- base = re.match(r'https?://[^/]+', url).group(0)
+ if 'location' not in header or not header['location']:
+ if 'code' in header and header['code'] not in (200, 201, 203, 206):
+ self.logDebug("Received HTTP status code: %d" % header['code'])
+ self.fail(_("File not found"))
+ else:
+ break
- if header['location'].startswith("http"):
- url = header['location']
+ location = header['location']
- elif header['location'].startswith("/"):
- url = base + unquote(header['location'])
+ self.logDebug("Redirect #%d to: %s" % (i, location))
- else:
- url = '%s/%s' % (base, unquote(header['location']))
+ if urlparse(location).scheme:
+ url = location
else:
- break
+ p = urlparse(url)
+ base = "%s://%s" % (p.scheme, p.netloc)
+ url = urljoin(base, location)
+ else:
+ self.fail(_("Too many redirects"))
- self.download(url, disposition=True)
+ self.download(unquote(url), disposition=True)