summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/BasePlugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/BasePlugin.py')
-rw-r--r--module/plugins/internal/BasePlugin.py71
1 files changed, 30 insertions, 41 deletions
diff --git a/module/plugins/internal/BasePlugin.py b/module/plugins/internal/BasePlugin.py
index 954fe4e22..792497449 100644
--- a/module/plugins/internal/BasePlugin.py
+++ b/module/plugins/internal/BasePlugin.py
@@ -5,15 +5,15 @@ import re
from urllib import unquote
from urlparse import urljoin, urlparse
-from pyload.network.HTTPRequest import BadHeader
-from pyload.plugin.internal.SimpleHoster import create_getInfo
-from pyload.plugin.Hoster import Hoster
+from module.network.HTTPRequest import BadHeader
+from module.plugins.internal.SimpleHoster import create_getInfo, fileUrl
+from module.plugins.Hoster import Hoster
class BasePlugin(Hoster):
__name__ = "BasePlugin"
__type__ = "hoster"
- __version__ = "0.25"
+ __version__ = "0.34"
__pattern__ = r'^unmatchable$'
@@ -25,11 +25,19 @@ class BasePlugin(Hoster):
@classmethod
def getInfo(cls, url="", html=""): #@TODO: Move to hoster class in 0.4.10
- return {'name': urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3 if url else 1, 'url': unquote(url) or ""}
+ url = unquote(url)
+ url_p = urlparse(url)
+ return {'name' : (url_p.path.split('/')[-1]
+ or url_p.query.split('=', 1)[::-1][0].split('&', 1)[0]
+ or url_p.netloc.split('.', 1)[0]),
+ 'size' : 0,
+ 'status': 3 if url else 8,
+ 'url' : url}
def setup(self):
- self.chunkLimit = -1
+ self.chunkLimit = -1
+ self.multiDL = True
self.resumeDownload = True
@@ -43,7 +51,12 @@ class BasePlugin(Hoster):
for _i in xrange(5):
try:
- self.downloadFile(pyfile)
+ link = fileUrl(self, unquote(pyfile.url))
+
+ if link:
+ self.download(link, ref=False, disposition=True)
+ else:
+ self.fail(_("File not found"))
except BadHeader, e:
if e.code is 404:
@@ -58,12 +71,11 @@ class BasePlugin(Hoster):
if server in servers:
self.logDebug("Logging on to %s" % server)
- self.req.addAuth(account.accounts[server]['password'])
+ self.req.addAuth(account.getAccountData(server)['password'])
else:
- for pwd in self.getPassword().splitlines():
- if ":" in pwd:
- self.req.addAuth(pwd.strip())
- break
+ pwd = self.getPassword()
+ if ':' in pwd:
+ self.req.addAuth(pwd)
else:
self.fail(_("Authorization required"))
else:
@@ -73,34 +85,11 @@ class BasePlugin(Hoster):
else:
self.fail(_("No file downloaded")) #@TODO: Move to hoster class in 0.4.10
- if self.checkDownload({'empty': re.compile(r"^$")}) is "empty": #@TODO: Move to hoster in 0.4.10
- self.fail(_("Empty file"))
-
+ check = self.checkDownload({'empty file': re.compile(r'\A\Z'),
+ 'html file' : re.compile(r'\A\s*<!DOCTYPE html'),
+ 'html error': re.compile(r'\A\s*(<.+>)?\d{3}(\Z|\s+)')})
+ if check:
+ self.fail(check.capitalize())
- def downloadFile(self, pyfile):
- url = pyfile.url
-
- 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' 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
-
- location = header['location']
-
- self.logDebug("Redirect #%d to: %s" % (i, location))
-
- if urlparse(location).scheme:
- url = location
- else:
- p = urlparse(url)
- base = "%s://%s" % (p.scheme, p.netloc)
- url = urljoin(base, location)
- else:
- self.fail(_("Too many redirects"))
- self.download(unquote(url), disposition=True)
+getInfo = create_getInfo(BasePlugin)