From 1fe525b92affd6d3829af219a9b1b5eeda136ca2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 12 Dec 2014 20:31:37 +0100 Subject: [SimpleHoster] Remove CONTENT_DISPOSITION + Rename parseInfo to parseInfos --- module/plugins/internal/SimpleHoster.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 530b67692..ddaea020a 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -104,9 +104,9 @@ def parseFileInfo(plugin, url="", html=""): #@TODO: Remove in 0.4.10 -#@NOTE: Every plugin must have own parseInfo classmethod to work with 0.4.10 +#@NOTE: Every plugin must have own parseInfos classmethod to work with 0.4.10 def create_getInfo(plugin): - return lambda urls: [(info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfo(urls)] + return lambda urls: [(info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)] def timestamp(): @@ -144,7 +144,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.71" + __version__ = "0.72" __pattern__ = r'^unmatchable$' @@ -206,11 +206,10 @@ class SimpleHoster(Hoster): FORCE_CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account CHECK_DIRECT_LINK = None #: Set to True to check for direct link, set to None to do it only if self.account is True MULTI_HOSTER = False #: Set to True to leech other hoster link (according its multihoster hook if available) - CONTENT_DISPOSITION = False #: Set to True to replace file name with content-disposition value from http header @classmethod - def parseInfo(cls, urls): + def parseInfos(cls, urls): for url in urls: url = replace_patterns(url, cls.FILE_URL_REPLACEMENTS if hasattr(cls, "FILE_URL_REPLACEMENTS") else cls.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 yield cls.getInfo(url) @@ -392,7 +391,7 @@ class SimpleHoster(Hoster): if not link: return - self.download(link, disposition=self.CONTENT_DISPOSITION) + self.download(link, disposition=True) def checkFile(self): -- cgit v1.2.3 From c9b4f3b9a78904d34d7e58593eacdc26b93c2562 Mon Sep 17 00:00:00 2001 From: philou75 Date: Fri, 12 Dec 2014 22:49:23 +0100 Subject: Make the waiting time work again on OneFichier.com --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index f391445fd..47b713173 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -144,7 +144,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.70" + __version__ = "0.71" __pattern__ = r'^unmatchable$' @@ -412,7 +412,7 @@ class SimpleHoster(Hoster): m = re.search(self.WAIT_PATTERN, self.html) if m: wait_time = sum([int(v) * {"hr": 3600, "hour": 3600, "min": 60, "sec": 1}[u.lower()] for v, u in - re.findall(r'(\d+)\s*(hr|hour|min|sec)', m, re.I)]) + re.findall(r'(\d+)\s*(hr|hour|min|sec)', m.group(0), re.I)]) self.wait(wait_time, False) return -- cgit v1.2.3 From a51d35534fc38650dd7714572f6874ab262bd119 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 16 Dec 2014 23:03:05 +0100 Subject: [SimpleHoster] Improve and fix --- module/plugins/internal/SimpleHoster.py | 58 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 24 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 992454451..86d9b4c9a 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -99,14 +99,24 @@ def parseHtmlForm(attr_str, html, input_names={}): #: Deprecated def parseFileInfo(plugin, url="", html=""): - info = plugin.getInfo(url, html) - return info['name'], info['size'], info['status'], info['url'] + if hasattr(plugin, "getInfo"): + info = plugin.getInfo(url, html) + res = info['name'], info['size'], info['status'], info['url'] + else: + res = urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 0, 3, url + + return res #@TODO: Remove in 0.4.10 #@NOTE: Every plugin must have own parseInfos classmethod to work with 0.4.10 def create_getInfo(plugin): - return lambda urls: [(info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)] + if hasattr(plugin, "parseInfos"): + fn = lambda urls: [(info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)] + else: + fn = lambda urls: [parseFileInfo(url) for url in urls] + + return fn def timestamp(): @@ -144,7 +154,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.73" + __version__ = "0.74" __pattern__ = r'^unmatchable$' @@ -260,18 +270,18 @@ class SimpleHoster(Hoster): try: info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here, please save api stuff to info['api'] except: - pass + info['pattern'] = {} for pattern in ("FILE_INFO_PATTERN", "INFO_PATTERN", "FILE_NAME_PATTERN", "NAME_PATTERN", "FILE_SIZE_PATTERN", "SIZE_PATTERN", "HASHSUM_PATTERN"): #@TODO: Remove old patterns starting with "FILE_" in 0.4.10 try: - attr = getattr(cls, pattern) - dict = re.search(attr, html).groupdict() + attr = getattr(cls, pattern) + pdict = re.search(attr, html).groupdict() - if all(True for k in dict if k not in info['pattern']): - info['pattern'].update(dict) + if all(True for k in pdict if k not in info['pattern']): + info['pattern'].update(pdict) except AttributeError: continue @@ -279,6 +289,9 @@ class SimpleHoster(Hoster): else: online = True + if not info['pattern']: + info.pop('pattern', None) + if online: info['status'] = 2 @@ -360,18 +373,21 @@ class SimpleHoster(Hoster): if self.html is None: self.fail(_("No html retrieved")) - self.checkErrors() - - premium_only = 'error' in self.info and self.info['error'] == "premium-only" - - self._updateInfo(self.getInfo(pyfile.url, self.html)) + self.updateInfo(self.getInfo(pyfile.url, self.html)) self.checkNameSize() + if hasattr(self, 'PREMIUM_ONLY_PATTERN'): + premium_only = re.search(self.PREMIUM_ONLY_PATTERN, self.html) + else: + premium_only = False + #: Usually premium only pages doesn't show any file information if not premium_only: self.checkStatus() + self.checkErrors() + if self.premium and (not self.FORCE_CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") self.handlePremium() @@ -406,18 +422,12 @@ class SimpleHoster(Hoster): errmsg = self.info['error'] = m.group(1) self.error(errmsg) - if hasattr(self, 'PREMIUM_ONLY_PATTERN'): - m = re.search(self.PREMIUM_ONLY_PATTERN, self.html) - if m: - self.info['error'] = "premium-only" - return - if hasattr(self, 'WAIT_PATTERN'): m = re.search(self.WAIT_PATTERN, self.html) if m: wait_time = sum([int(v) * {"hr": 3600, "hour": 3600, "min": 60, "sec": 1}[u.lower()] for v, u in re.findall(r'(\d+)\s*(hr|hour|min|sec)', m.group(0), re.I)]) - self.wait(wait_time, True if wait_time > 300 else False) + self.wait(wait_time, wait_time > 300) return self.info.pop('error', None) @@ -460,7 +470,7 @@ class SimpleHoster(Hoster): def checkInfo(self): self.checkErrors() - self._updateInfo(self.getInfo(self.pyfile.url, self.html or "")) + self.updateInfo(self.getInfo(self.pyfile.url, self.html or "")) self.checkNameSize() self.checkStatus() @@ -473,7 +483,7 @@ class SimpleHoster(Hoster): return self.info - def _updateInfo(self, info): + def updateInfo(self, info): self.logDebug(_("File info (before update): %s") % self.info) self.info.update(info) self.logDebug(_("File info (after update): %s") % self.info) @@ -487,7 +497,7 @@ class SimpleHoster(Hoster): self.link = link - self._updateInfo(self.getInfo(self.pyfile.url)) + self.updateInfo(self.getInfo(self.pyfile.url)) self.checkNameSize() else: self.logDebug(_("Direct download link not found")) -- cgit v1.2.3 From 69616099c133fdc783abad44c2a0916acba4b6d1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Dec 2014 22:38:24 +0100 Subject: [SimpleHoster] Fix filesize recognition --- module/plugins/internal/SimpleHoster.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 86d9b4c9a..ad140423c 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -154,7 +154,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.74" + __version__ = "0.75" __pattern__ = r'^unmatchable$' @@ -300,7 +300,7 @@ class SimpleHoster(Hoster): cls.FILE_NAME_REPLACEMENTS if hasattr(cls, "FILE_NAME_REPLACEMENTS") else cls.NAME_REPLACEMENTS) #@TODO: Remove FILE_NAME_REPLACEMENTS check in 0.4.10 if 'S' in info['pattern']: - size = replace_patterns(info['pattern']['S'] + info['pattern']['U'] if 'U' in info else info['pattern']['S'], + size = replace_patterns(info['pattern']['S'] + info['pattern']['U'] if 'U' in info['pattern'] else info['pattern']['S'], cls.FILE_SIZE_REPLACEMENTS if hasattr(cls, "FILE_SIZE_REPLACEMENTS") else cls.SIZE_REPLACEMENTS) #@TODO: Remove FILE_SIZE_REPLACEMENTS check in 0.4.10 info['size'] = parseFileSize(size) @@ -361,6 +361,7 @@ class SimpleHoster(Hoster): if self.multihost: self.logDebug("Looking for leeched download link...") + self.logDebug("File url: %s" % self.pyfile.url) self.handleMulti() elif self.directDL: @@ -404,10 +405,8 @@ class SimpleHoster(Hoster): def downloadLink(self, link): - if not link: - return - - self.download(link, disposition=True) + if link and isinstance(link, basestring): + self.download(link, disposition=True) def checkFile(self): -- cgit v1.2.3 From 0860e09f5ff16ee3f097f6f9d444f277a38abd72 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 17 Dec 2014 23:03:46 +0100 Subject: Extend SimpleHoster in multi-hoster plugins (3) --- module/plugins/internal/SimpleHoster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index ad140423c..2ff60d6ea 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -361,7 +361,7 @@ class SimpleHoster(Hoster): if self.multihost: self.logDebug("Looking for leeched download link...") - self.logDebug("File url: %s" % self.pyfile.url) + self.logDebug("File url: %s" % pyfile.url) self.handleMulti() elif self.directDL: -- cgit v1.2.3 From 4e9c8f7ab1269966a9eac9e1b6363f5458f9f970 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 18 Dec 2014 16:07:21 +0100 Subject: Update checkFile routine in some hoster plugins --- module/plugins/internal/SimpleHoster.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 2ff60d6ea..949a6c66a 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -2,6 +2,7 @@ import re +from os.path import exists from time import time from urllib import unquote from urlparse import urljoin, urlparse @@ -11,7 +12,7 @@ from module.network.CookieJar import CookieJar from module.network.RequestFactory import getURL from module.plugins.Hoster import Hoster from module.plugins.Plugin import Fail -from module.utils import fixup, parseFileSize +from module.utils import fixup, fs_encode, parseFileSize #@TODO: Adapt and move to PyFile in 0.4.10 @@ -154,7 +155,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.75" + __version__ = "0.76" __pattern__ = r'^unmatchable$' @@ -410,8 +411,19 @@ class SimpleHoster(Hoster): def checkFile(self): - if self.checkDownload({'empty': re.compile(r"^$")}) is "empty": #@TODO: Move to hoster in 0.4.10 - self.fail(_("Empty file")) + if not self.lastDownload or not exists(fs_encode(self.lastDownload)): + self.fail(_("No file downloaded")) + + else: + rules = {'empty file': re.compile(r"^$")} + + if hasattr(self, 'ERROR_PATTERN'): + rules['error'] = re.compile(self.ERROR_PATTERN) + + check = self.checkDownload(rules) + if check: #@TODO: Move to hoster in 0.4.10 + errmsg = check.strip().capitalize() + (" | " + self.lastCheck.strip() if self.lastCheck else "") + self.retry(10, 60, errmsg) def checkErrors(self): -- cgit v1.2.3 From 6d9c5ff2e06e06e33fa6674f013dd0e290092bbd Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 20 Dec 2014 14:25:57 +0100 Subject: [SimpleHoster] Improve checkFile --- module/plugins/internal/SimpleHoster.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 949a6c66a..784ef8c85 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -155,7 +155,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.76" + __version__ = "0.77" __pattern__ = r'^unmatchable$' @@ -407,11 +407,16 @@ class SimpleHoster(Hoster): def downloadLink(self, link): if link and isinstance(link, basestring): + self.correctCaptcha() self.download(link, disposition=True) def checkFile(self): - if not self.lastDownload or not exists(fs_encode(self.lastDownload)): + if self.cTask and not self.lastDownload: + self.invalidCaptcha() + self.retry(10, reason=_("Wrong captcha")) + + elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): self.fail(_("No file downloaded")) else: -- cgit v1.2.3 From e1d4186c62512d8bb76d35b6f8d1828d8d0aa94e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 23 Dec 2014 13:26:32 +0100 Subject: [SimpleHoster] Improve multi-hoster feature --- module/plugins/internal/SimpleHoster.py | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 784ef8c85..ab114c9ec 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -155,7 +155,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.77" + __version__ = "0.78" __pattern__ = r'^unmatchable$' @@ -214,9 +214,9 @@ class SimpleHoster(Hoster): TEXT_ENCODING = False #: Set to True or encoding name if encoding value in http header is not correct COOKIES = True #: or False or list of tuples [(domain, name, value)] - FORCE_CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account - CHECK_DIRECT_LINK = None #: Set to True to check for direct link, set to None to do it only if self.account is True - MULTI_HOSTER = False #: Set to True to leech other hoster link (according its multihoster hook if available) + CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account + DIRECT_LINK = None #: Set to True to looking for direct link (as defined in handleDirect method), set to None to do it if self.account is True else False + MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) @classmethod @@ -334,17 +334,13 @@ class SimpleHoster(Hoster): if (self.MULTI_HOSTER and (self.__pattern__ != self.core.pluginManager.hosterPlugins[self.__name__]['pattern'] or re.match(self.__pattern__, self.pyfile.url) is None)): + self.multihost = True + return - self.logInfo("Multi hoster detected") - - if self.account: - self.multihost = True - return - else: - self.fail(_("Only registered or premium users can use url leech feature")) - - if self.CHECK_DIRECT_LINK is None: + if self.DIRECT_LINK is None: self.directDL = bool(self.account) + else: + self.directDL = self.DIRECT_LINK self.pyfile.url = replace_patterns(self.pyfile.url, self.FILE_URL_REPLACEMENTS if hasattr(self, "FILE_URL_REPLACEMENTS") else self.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 @@ -360,16 +356,20 @@ class SimpleHoster(Hoster): def process(self, pyfile): self.prepare() - if self.multihost: + if self.directDL: + self.logDebug("Looking for direct download link...") + self.handleDirect() + + if self.multihost and not self.link and not self.lastDownload: self.logDebug("Looking for leeched download link...") self.logDebug("File url: %s" % pyfile.url) self.handleMulti() - elif self.directDL: - self.logDebug("Looking for direct download link...") - self.handleDirect() + if not self.link and not self.lastDownload: + self.MULTI_HOSTER = False + self.retry(1, reason="Multi hoster fails") - if not self.link: + if not self.link and not self.lastDownload: self.preload() if self.html is None: @@ -390,7 +390,7 @@ class SimpleHoster(Hoster): self.checkErrors() - if self.premium and (not self.FORCE_CHECK_TRAFFIC or self.checkTrafficLeft()): + if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") self.handlePremium() -- cgit v1.2.3 From badfd177fb3639869441f4738461c7f576e1d078 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 23 Dec 2014 17:22:47 +0100 Subject: [SimpleHoster] Update --- module/plugins/internal/SimpleHoster.py | 81 +++++++++++++++------------------ 1 file changed, 37 insertions(+), 44 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index ab114c9ec..95833d0cf 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -125,29 +125,34 @@ def timestamp(): #@TODO: Move to hoster class in 0.4.10 -def _isDirectLink(self, url, resumable=True): - header = self.load(url, ref=True, just_header=True, decode=True) +def _isDirectLink(self, url, resumable=False): + link = "" - if not 'location' in header or not header['location']: - return "" + for i in xrange(5 if resumable else 1): + header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) - location = header['location'] + if 'content-disposition' in header: + link = url - resumable = False #@NOTE: Testing... + elif 'location' in header and header['location']: + location = header['location'] - if resumable: #: sometimes http code may be wrong... - if 'location' in self.load(location, ref=True, cookies=True, just_header=True, decode=True): - return "" - else: - if not 'code' in header or header['code'] != 302: - return "" + if not urlparse(location).scheme: + p = urlparse(url) + base = "%s://%s" % (p.scheme, p.netloc) + location = urljoin(base, location) + + if 'code' in header and header['code'] == 302: + link = location + + elif resumable: + url = location + self.logDebug("Redirect #%d to: %s" % (++i, location)) + continue - if urlparse(location).scheme: - link = location + break else: - p = urlparse(url) - base = "%s://%s" % (p.scheme, p.netloc) - link = urljoin(base, location) + self.logError(_("Too many redirects")) return link @@ -155,7 +160,7 @@ def _isDirectLink(self, url, resumable=True): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.78" + __version__ = "0.79" __pattern__ = r'^unmatchable$' @@ -355,6 +360,7 @@ class SimpleHoster(Hoster): def process(self, pyfile): self.prepare() + self.checkInfo() if self.directDL: self.logDebug("Looking for direct download link...") @@ -371,32 +377,15 @@ class SimpleHoster(Hoster): if not self.link and not self.lastDownload: self.preload() + self.checkInfo() if self.html is None: self.fail(_("No html retrieved")) - self.updateInfo(self.getInfo(pyfile.url, self.html)) - - self.checkNameSize() - - if hasattr(self, 'PREMIUM_ONLY_PATTERN'): - premium_only = re.search(self.PREMIUM_ONLY_PATTERN, self.html) - else: - premium_only = False - - #: Usually premium only pages doesn't show any file information - if not premium_only: - self.checkStatus() - - self.checkErrors() - if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") self.handlePremium() - elif premium_only: - self.fail(_("Link require a premium account to be handled")) - else: self.logDebug("Handled as free download") self.handleFree() @@ -432,6 +421,9 @@ class SimpleHoster(Hoster): def checkErrors(self): + if hasattr(self, 'PREMIUM_ONLY_PATTERN') and self.premium and re.search(self.PREMIUM_ONLY_PATTERN, self.html): + self.fail(_("Link require a premium account to be handled")) + if hasattr(self, 'ERROR_PATTERN'): m = re.search(self.ERROR_PATTERN, self.html) if m: @@ -459,9 +451,8 @@ class SimpleHoster(Hoster): self.tempOffline() elif status is not 2: - self.logInfo(_("File status: %s") % statusMap[status], - _("File info: %s") % self.info) - self.error(_("No file info retrieved")) + self.logDebug(_("File status: %s") % statusMap[status], + _("File info: %s") % self.info) def checkNameSize(self): @@ -484,9 +475,14 @@ class SimpleHoster(Hoster): def checkInfo(self): - self.checkErrors() + self.updateInfo(self.getInfo(self.pyfile.url, self.html)) - self.updateInfo(self.getInfo(self.pyfile.url, self.html or "")) + self.checkNameSize() + + if self.html: + self.checkErrors() + + self.updateInfo(self.getInfo(self.pyfile.url, self.html)) self.checkNameSize() self.checkStatus() @@ -512,9 +508,6 @@ class SimpleHoster(Hoster): self.logInfo(_("Direct download link detected")) self.link = link - - self.updateInfo(self.getInfo(self.pyfile.url)) - self.checkNameSize() else: self.logDebug(_("Direct download link not found")) -- cgit v1.2.3 From 9c9843e6c7681ef52a882033eaabb44afacc5b8e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 23 Dec 2014 18:51:01 +0100 Subject: [SimpleHoster] Code cosmetics --- module/plugins/internal/SimpleHoster.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 95833d0cf..6726726e1 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -368,7 +368,6 @@ class SimpleHoster(Hoster): if self.multihost and not self.link and not self.lastDownload: self.logDebug("Looking for leeched download link...") - self.logDebug("File url: %s" % pyfile.url) self.handleMulti() if not self.link and not self.lastDownload: @@ -451,8 +450,8 @@ class SimpleHoster(Hoster): self.tempOffline() elif status is not 2: - self.logDebug(_("File status: %s") % statusMap[status], - _("File info: %s") % self.info) + self.logDebug("File status: %s" % statusMap[status], + "File info: %s" % self.info) def checkNameSize(self): @@ -496,9 +495,9 @@ class SimpleHoster(Hoster): def updateInfo(self, info): - self.logDebug(_("File info (before update): %s") % self.info) + self.logDebug(_("File info (BEFORE): %s") % self.info) self.info.update(info) - self.logDebug(_("File info (after update): %s") % self.info) + self.logDebug(_("File info (AFTER): %s") % self.info) def handleDirect(self): -- cgit v1.2.3 From 873f1bc17733148163829e23a456a6e724c486e3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 26 Dec 2014 04:26:20 +0100 Subject: [SimpleHoster] Improve --- module/plugins/internal/SimpleHoster.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 6726726e1..56c25e0d9 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -160,7 +160,7 @@ def _isDirectLink(self, url, resumable=False): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.79" + __version__ = "0.80" __pattern__ = r'^unmatchable$' @@ -381,7 +381,7 @@ class SimpleHoster(Hoster): if self.html is None: self.fail(_("No html retrieved")) - if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): + if self.premium and not self.CHECK_TRAFFIC or self.checkTrafficLeft(): self.logDebug("Handled as premium download") self.handlePremium() @@ -405,7 +405,11 @@ class SimpleHoster(Hoster): self.retry(10, reason=_("Wrong captcha")) elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): - self.fail(_("No file downloaded")) + errmsg = _("No file downloaded") + if 'error' in self.info: + self.fail(errmsg, self.info['error']) + else: + self.fail(errmsg) else: rules = {'empty file': re.compile(r"^$")} -- cgit v1.2.3 From c7187f2142c6e06be961bb3be45ea3b61ce31651 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 26 Dec 2014 17:24:41 +0100 Subject: [SimpleHoster] getInfo handle direct link error --- module/plugins/internal/SimpleHoster.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 56c25e0d9..89d2e629c 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -160,7 +160,7 @@ def _isDirectLink(self, url, resumable=False): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.80" + __version__ = "0.81" __pattern__ = r'^unmatchable$' @@ -233,7 +233,13 @@ class SimpleHoster(Hoster): @classmethod def getInfo(cls, url="", html=""): - info = {'name': urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3, 'url': url} + info = {'name': urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3, 'url': url} + online = False + + try: + info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here, please save api stuff to info['api'] + except Exception: + pass if not html: try: @@ -242,6 +248,11 @@ class SimpleHoster(Hoster): info['status'] = 1 raise + if _isDirectLink(url): + info['error'] = "direct link" + info['status'] = 2 + raise + try: html = getURL(url, cookies=cls.COOKIES, decode=not cls.TEXT_ENCODING) @@ -261,8 +272,6 @@ class SimpleHoster(Hoster): except: return info - online = False - if hasattr(cls, "OFFLINE_PATTERN") and re.search(cls.OFFLINE_PATTERN, html): info['status'] = 1 @@ -273,9 +282,7 @@ class SimpleHoster(Hoster): info['status'] = 6 else: - try: - info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here, please save api stuff to info['api'] - except: + if not 'pattern' in info: info['pattern'] = {} for pattern in ("FILE_INFO_PATTERN", "INFO_PATTERN", @@ -381,7 +388,7 @@ class SimpleHoster(Hoster): if self.html is None: self.fail(_("No html retrieved")) - if self.premium and not self.CHECK_TRAFFIC or self.checkTrafficLeft(): + if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") self.handlePremium() -- cgit v1.2.3 From 2260302b71a803da708f3ec6a0cc2200baae527b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 27 Dec 2014 13:44:36 +0100 Subject: [SimpleHoster] Improve _isDirectLink + move here secondsToMidnight routine + spare code cosmetics --- module/plugins/internal/SimpleHoster.py | 55 +++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 89d2e629c..d9732d063 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -131,7 +131,7 @@ def _isDirectLink(self, url, resumable=False): for i in xrange(5 if resumable else 1): header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) - if 'content-disposition' in header: + if 'content-disposition' in header or 'content-length' in header: link = url elif 'location' in header and header['location']: @@ -150,6 +150,9 @@ def _isDirectLink(self, url, resumable=False): self.logDebug("Redirect #%d to: %s" % (++i, location)) continue + elif 'content-type' in header and header['content-type' ] and "html" not in header['content-type']: + link = url + break else: self.logError(_("Too many redirects")) @@ -157,10 +160,28 @@ def _isDirectLink(self, url, resumable=False): return link +def secondsToMidnight(gmt=0): + now = datetime.utcnow() + timedelta(hours=gmt) + + if now.hour is 0 and now.minute < 10: + midnight = now + else: + midnight = now + timedelta(days=1) + + td = midnight.replace(hour=0, minute=10, second=0, microsecond=0) - now + + if hasattr(td, 'total_seconds'): + res = td.total_seconds() + else: #@NOTE: work-around for python 2.5 and 2.6 missing timedelta.total_seconds + res = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + + return int(res) + + class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.81" + __version__ = "0.82" __pattern__ = r'^unmatchable$' @@ -185,10 +206,10 @@ class SimpleHoster(Hoster): HASHSUM_PATTERN: (optional) Hash code and type of the file example: HASHSUM_PATTERN = r'(?Phash_code) (?PMD5)' - OFFLINE_PATTERN: (optional) Check if the file is yet available online + OFFLINE_PATTERN: (optional) Check if the page is unreachable example: OFFLINE_PATTERN = r'File (deleted|not found)' - TEMP_OFFLINE_PATTERN: (optional) Check if the file is temporarily offline + TEMP_OFFLINE_PATTERN: (optional) Check if the page is temporarily unreachable example: TEMP_OFFLINE_PATTERN = r'Server (maintenance|maintainance)' @@ -217,11 +238,11 @@ class SimpleHoster(Hoster): SIZE_REPLACEMENTS = [] URL_REPLACEMENTS = [] - TEXT_ENCODING = False #: Set to True or encoding name if encoding value in http header is not correct - COOKIES = True #: or False or list of tuples [(domain, name, value)] - CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account - DIRECT_LINK = None #: Set to True to looking for direct link (as defined in handleDirect method), set to None to do it if self.account is True else False - MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) + TEXT_ENCODING = False #: Set to True or encoding name if encoding value in http header is not correct + COOKIES = True #: or False or list of tuples [(domain, name, value)] + CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account + DIRECT_LINK = None #: Set to True to looking for direct link (as defined in handleDirect method), set to None to do it if self.account is True else False + MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) @classmethod @@ -451,7 +472,10 @@ class SimpleHoster(Hoster): self.info.pop('error', None) - def checkStatus(self): + def checkStatus(self, getinfo=True): + if getinfo: + self.updateInfo(self.getInfo(self.pyfile.url, self.html)) + status = self.info['status'] if status is 1: @@ -465,7 +489,10 @@ class SimpleHoster(Hoster): "File info: %s" % self.info) - def checkNameSize(self): + def checkNameSize(self, getinfo=True): + if getinfo: + self.updateInfo(self.getInfo(self.pyfile.url, self.html)) + name = self.info['name'] size = self.info['size'] url = self.info['url'] @@ -485,17 +512,13 @@ class SimpleHoster(Hoster): def checkInfo(self): - self.updateInfo(self.getInfo(self.pyfile.url, self.html)) - self.checkNameSize() if self.html: self.checkErrors() - self.updateInfo(self.getInfo(self.pyfile.url, self.html)) - self.checkNameSize() - self.checkStatus() + self.checkStatus(getinfo=False) #: Deprecated -- cgit v1.2.3 From 0c61cbb03493b15970a5ccb9a5e20b02b3884a4e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 28 Dec 2014 01:05:59 +0100 Subject: [SimpleHoster] Improve --- module/plugins/internal/SimpleHoster.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index d9732d063..5c6f8c720 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -181,7 +181,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.82" + __version__ = "0.83" __pattern__ = r'^unmatchable$' @@ -388,7 +388,7 @@ class SimpleHoster(Hoster): def process(self, pyfile): self.prepare() - self.checkInfo() + self.checkNameSize() if self.directDL: self.logDebug("Looking for direct download link...") @@ -406,9 +406,6 @@ class SimpleHoster(Hoster): self.preload() self.checkInfo() - if self.html is None: - self.fail(_("No html retrieved")) - if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") self.handlePremium() -- cgit v1.2.3 From 98ae3d727b60d3f529b39a6c275e31732231bd91 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 28 Dec 2014 11:53:37 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/983 --- module/plugins/internal/SimpleHoster.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 5c6f8c720..6075e3f67 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -181,7 +181,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.83" + __version__ = "0.84" __pattern__ = r'^unmatchable$' @@ -444,7 +444,9 @@ class SimpleHoster(Hoster): check = self.checkDownload(rules) if check: #@TODO: Move to hoster in 0.4.10 - errmsg = check.strip().capitalize() + (" | " + self.lastCheck.strip() if self.lastCheck else "") + errmsg = check.strip().capitalize() + if self.lastCheck: + errmsg += " | " + self.lastCheck.group(0).strip() self.retry(10, 60, errmsg) -- cgit v1.2.3 From db1ea11119adb71293fe2118d6257a3921709a7b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 31 Dec 2014 00:00:49 +0100 Subject: [SimpleHoster] Clean lastDownload when download fails --- module/plugins/internal/SimpleHoster.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 6075e3f67..2792834f2 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -181,7 +181,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.84" + __version__ = "0.85" __pattern__ = r'^unmatchable$' @@ -430,6 +430,8 @@ class SimpleHoster(Hoster): self.retry(10, reason=_("Wrong captcha")) elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): + self.lastDownload = "" + errmsg = _("No file downloaded") if 'error' in self.info: self.fail(errmsg, self.info['error']) @@ -447,6 +449,8 @@ class SimpleHoster(Hoster): errmsg = check.strip().capitalize() if self.lastCheck: errmsg += " | " + self.lastCheck.group(0).strip() + + self.lastDownload = "" self.retry(10, 60, errmsg) @@ -473,7 +477,8 @@ class SimpleHoster(Hoster): def checkStatus(self, getinfo=True): if getinfo: - self.updateInfo(self.getInfo(self.pyfile.url, self.html)) + self.logDebug("File info (BEFORE): %s" % self.info) + self.info.update(self.getInfo(self.pyfile.url, self.html)) status = self.info['status'] @@ -490,7 +495,9 @@ class SimpleHoster(Hoster): def checkNameSize(self, getinfo=True): if getinfo: - self.updateInfo(self.getInfo(self.pyfile.url, self.html)) + self.logDebug("File info (BEFORE): %s" % self.info) + self.info.update(self.getInfo(self.pyfile.url, self.html)) + self.logDebug("File info (AFTER): %s" % self.info) name = self.info['name'] size = self.info['size'] @@ -515,8 +522,8 @@ class SimpleHoster(Hoster): if self.html: self.checkErrors() + self.checkNameSize() - self.checkNameSize() self.checkStatus(getinfo=False) @@ -527,28 +534,22 @@ class SimpleHoster(Hoster): return self.info - def updateInfo(self, info): - self.logDebug(_("File info (BEFORE): %s") % self.info) - self.info.update(info) - self.logDebug(_("File info (AFTER): %s") % self.info) - - - def handleDirect(self): - link = _isDirectLink(self, self.pyfile.url, self.resumeDownload) + def handleDirect(self, pyfile=None): + link = _isDirectLink(self, pyfile.url, self.resumeDownload) if link: self.logInfo(_("Direct download link detected")) self.link = link else: - self.logDebug(_("Direct download link not found")) + self.logDebug("Direct download link not found") - def handleMulti(self): #: Multi-hoster handler + def handleMulti(self, pyfile=None): #: Multi-hoster handler pass - def handleFree(self): + def handleFree(self, pyfile=None): if not hasattr(self, 'LINK_FREE_PATTERN'): self.fail(_("Free download not implemented")) @@ -563,7 +564,7 @@ class SimpleHoster(Hoster): self.fail(e) - def handlePremium(self): + def handlePremium(self, pyfile=None): if not hasattr(self, 'LINK_PREMIUM_PATTERN'): self.fail(_("Premium download not implemented")) -- cgit v1.2.3 From d07caf13ccfd9b4ca6066078764f9a9267423ff1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 31 Dec 2014 00:28:56 +0100 Subject: Handle methods get pyfile argument (2) --- module/plugins/internal/SimpleHoster.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 2792834f2..7b96205c8 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -181,7 +181,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.85" + __version__ = "0.86" __pattern__ = r'^unmatchable$' @@ -392,11 +392,11 @@ class SimpleHoster(Hoster): if self.directDL: self.logDebug("Looking for direct download link...") - self.handleDirect() + self.handleDirect(pyfile) if self.multihost and not self.link and not self.lastDownload: self.logDebug("Looking for leeched download link...") - self.handleMulti() + self.handleMulti(pyfile) if not self.link and not self.lastDownload: self.MULTI_HOSTER = False @@ -534,7 +534,7 @@ class SimpleHoster(Hoster): return self.info - def handleDirect(self, pyfile=None): + def handleDirect(self, pyfile): link = _isDirectLink(self, pyfile.url, self.resumeDownload) if link: @@ -545,7 +545,7 @@ class SimpleHoster(Hoster): self.logDebug("Direct download link not found") - def handleMulti(self, pyfile=None): #: Multi-hoster handler + def handleMulti(self, pyfile): #: Multi-hoster handler pass -- cgit v1.2.3 From 3cf12589b86aed7a73a1bc5affc0a8d257f6cd60 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 31 Dec 2014 17:06:09 +0100 Subject: [SimpleHoster] Fix info stuff --- module/plugins/internal/SimpleHoster.py | 121 +++++++++++++++++++------------- 1 file changed, 71 insertions(+), 50 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 7b96205c8..0b2c1f7c3 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -2,6 +2,7 @@ import re +from inspect import isclass from os.path import exists from time import time from urllib import unquote @@ -124,12 +125,40 @@ def timestamp(): return int(time() * 1000) -#@TODO: Move to hoster class in 0.4.10 -def _isDirectLink(self, url, resumable=False): +#@TODO: Move to hoster class in 0.4.10 as staticmethod +def _isDirectLink(plugin, url, resumable=False): link = "" + if isclass(plugin) or not hasattr(plugin, "load"): + load = getURL + parse_header = True + else: + load = plugin.load + parse_header = False + for i in xrange(5 if resumable else 1): - header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) + header = load(url, just_header=True, decode=True) + + if parse_header: + h = {} + for line in header.splitlines(): + line = line.strip() + if not line or ":" not in line: + continue + + key, none, value = line.partition(":") + key = key.lower().strip() + value = value.strip() + + if key in h: + if type(h[key]) == list: + h[key].append(value) + else: + h[key] = [h[key], value] + else: + h[key] = value + + header = h if 'content-disposition' in header or 'content-length' in header: link = url @@ -147,15 +176,15 @@ def _isDirectLink(self, url, resumable=False): elif resumable: url = location - self.logDebug("Redirect #%d to: %s" % (++i, location)) + # plugin.logDebug("Redirect #%d to: %s" % (++i, location)) continue - elif 'content-type' in header and header['content-type' ] and "html" not in header['content-type']: + elif 'content-type' in header and header['content-type'] and "html" not in header['content-type']: link = url break - else: - self.logError(_("Too many redirects")) + # else: + # plugin.logError(_("Too many redirects")) return link @@ -181,7 +210,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.86" + __version__ = "0.87" __pattern__ = r'^unmatchable$' @@ -263,17 +292,15 @@ class SimpleHoster(Hoster): pass if not html: - try: - if not url: - info['error'] = "missing url" - info['status'] = 1 - raise + if not url: + info['error'] = "missing url" + info['status'] = 1 - if _isDirectLink(url): - info['error'] = "direct link" - info['status'] = 2 - raise + elif _isDirectLink(cls, url): + info['error'] = "direct link" + info['status'] = 2 + else: try: html = getURL(url, cookies=cls.COOKIES, decode=not cls.TEXT_ENCODING) @@ -285,46 +312,40 @@ class SimpleHoster(Hoster): if e.code is 404: info['status'] = 1 - raise - if e.code is 503: + elif e.code is 503: info['status'] = 6 - raise - except: - return info - if hasattr(cls, "OFFLINE_PATTERN") and re.search(cls.OFFLINE_PATTERN, html): - info['status'] = 1 + if html: + if hasattr(cls, "OFFLINE_PATTERN") and re.search(cls.OFFLINE_PATTERN, html): + info['status'] = 1 - elif hasattr(cls, "FILE_OFFLINE_PATTERN") and re.search(cls.FILE_OFFLINE_PATTERN, html): #@TODO: Remove in 0.4.10 - info['status'] = 1 + elif hasattr(cls, "FILE_OFFLINE_PATTERN") and re.search(cls.FILE_OFFLINE_PATTERN, html): #@TODO: Remove in 0.4.10 + info['status'] = 1 - elif hasattr(cls, "TEMP_OFFLINE_PATTERN") and re.search(cls.TEMP_OFFLINE_PATTERN, html): - info['status'] = 6 + elif hasattr(cls, "TEMP_OFFLINE_PATTERN") and re.search(cls.TEMP_OFFLINE_PATTERN, html): + info['status'] = 6 - else: - if not 'pattern' in info: - info['pattern'] = {} - - for pattern in ("FILE_INFO_PATTERN", "INFO_PATTERN", - "FILE_NAME_PATTERN", "NAME_PATTERN", - "FILE_SIZE_PATTERN", "SIZE_PATTERN", - "HASHSUM_PATTERN"): #@TODO: Remove old patterns starting with "FILE_" in 0.4.10 - try: - attr = getattr(cls, pattern) - pdict = re.search(attr, html).groupdict() - - if all(True for k in pdict if k not in info['pattern']): - info['pattern'].update(pdict) - - except AttributeError: - continue + else: + for pattern in ("FILE_INFO_PATTERN", "INFO_PATTERN", + "FILE_NAME_PATTERN", "NAME_PATTERN", + "FILE_SIZE_PATTERN", "SIZE_PATTERN", + "HASHSUM_PATTERN"): #@TODO: Remove old patterns starting with "FILE_" in 0.4.10 + try: + attr = getattr(cls, pattern) + pdict = re.search(attr, html).groupdict() + + if all(True for k in pdict if k not in info['pattern']): + info['pattern'].update(pdict) + + except AttributeError: + continue - else: - online = True + else: + online = True - if not info['pattern']: - info.pop('pattern', None) + if 'pattern' in info and not info['pattern']: + info.pop('pattern', None) if online: info['status'] = 2 @@ -388,7 +409,7 @@ class SimpleHoster(Hoster): def process(self, pyfile): self.prepare() - self.checkNameSize() + self.checkInfo() if self.directDL: self.logDebug("Looking for direct download link...") -- cgit v1.2.3 From 60e9c46f32d97d01d728c8515985b58ba33fdafd Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 1 Jan 2015 01:48:37 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/997 --- module/plugins/internal/SimpleHoster.py | 46 +++++---------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 0b2c1f7c3..51891c3c6 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -125,40 +125,12 @@ def timestamp(): return int(time() * 1000) -#@TODO: Move to hoster class in 0.4.10 as staticmethod -def _isDirectLink(plugin, url, resumable=False): +#@TODO: Move to hoster class in 0.4.10 +def _isDirectLink(self, url, resumable=False): link = "" - if isclass(plugin) or not hasattr(plugin, "load"): - load = getURL - parse_header = True - else: - load = plugin.load - parse_header = False - for i in xrange(5 if resumable else 1): - header = load(url, just_header=True, decode=True) - - if parse_header: - h = {} - for line in header.splitlines(): - line = line.strip() - if not line or ":" not in line: - continue - - key, none, value = line.partition(":") - key = key.lower().strip() - value = value.strip() - - if key in h: - if type(h[key]) == list: - h[key].append(value) - else: - h[key] = [h[key], value] - else: - h[key] = value - - header = h + header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) if 'content-disposition' in header or 'content-length' in header: link = url @@ -176,15 +148,15 @@ def _isDirectLink(plugin, url, resumable=False): elif resumable: url = location - # plugin.logDebug("Redirect #%d to: %s" % (++i, location)) + self.logDebug("Redirect #%d to: %s" % (++i, location)) continue elif 'content-type' in header and header['content-type'] and "html" not in header['content-type']: link = url break - # else: - # plugin.logError(_("Too many redirects")) + else: + self.logError(_("Too many redirects")) return link @@ -210,7 +182,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.87" + __version__ = "0.88" __pattern__ = r'^unmatchable$' @@ -296,10 +268,6 @@ class SimpleHoster(Hoster): info['error'] = "missing url" info['status'] = 1 - elif _isDirectLink(cls, url): - info['error'] = "direct link" - info['status'] = 2 - else: try: html = getURL(url, cookies=cls.COOKIES, decode=not cls.TEXT_ENCODING) -- cgit v1.2.3 From ea58af3c625d90aec6becfd943289e42e4a71a9a Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 2 Jan 2015 02:49:26 +0100 Subject: Code cosmetics --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 51891c3c6..7bab78ce8 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -447,13 +447,13 @@ class SimpleHoster(Hoster): if hasattr(self, 'PREMIUM_ONLY_PATTERN') and self.premium and re.search(self.PREMIUM_ONLY_PATTERN, self.html): self.fail(_("Link require a premium account to be handled")) - if hasattr(self, 'ERROR_PATTERN'): + elif hasattr(self, 'ERROR_PATTERN'): m = re.search(self.ERROR_PATTERN, self.html) if m: errmsg = self.info['error'] = m.group(1) self.error(errmsg) - if hasattr(self, 'WAIT_PATTERN'): + elif hasattr(self, 'WAIT_PATTERN'): m = re.search(self.WAIT_PATTERN, self.html) if m: wait_time = sum([int(v) * {"hr": 3600, "hour": 3600, "min": 60, "sec": 1}[u.lower()] for v, u in -- cgit v1.2.3 From f321ae380c31b345c403aa02804eabfaf586aa59 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 2 Jan 2015 15:43:35 +0100 Subject: [SimpleHoster] Fix _isDirectLink --- module/plugins/internal/SimpleHoster.py | 43 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 7bab78ce8..4e2b4803b 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -132,7 +132,7 @@ def _isDirectLink(self, url, resumable=False): for i in xrange(5 if resumable else 1): header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) - if 'content-disposition' in header or 'content-length' in header: + if 'content-disposition' in header: link = url elif 'location' in header and header['location']: @@ -143,14 +143,14 @@ def _isDirectLink(self, url, resumable=False): base = "%s://%s" % (p.scheme, p.netloc) location = urljoin(base, location) - if 'code' in header and header['code'] == 302: - link = location - - elif resumable: + if resumable: url = location self.logDebug("Redirect #%d to: %s" % (++i, location)) continue + elif 'code' in header and header['code'] == 302: + link = location + elif 'content-type' in header and header['content-type'] and "html" not in header['content-type']: link = url @@ -182,7 +182,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.88" + __version__ = "0.89" __pattern__ = r'^unmatchable$' @@ -469,6 +469,9 @@ class SimpleHoster(Hoster): self.logDebug("File info (BEFORE): %s" % self.info) self.info.update(self.getInfo(self.pyfile.url, self.html)) + if 'status' not in self.info: + return + status = self.info['status'] if status is 1: @@ -488,22 +491,24 @@ class SimpleHoster(Hoster): self.info.update(self.getInfo(self.pyfile.url, self.html)) self.logDebug("File info (AFTER): %s" % self.info) - name = self.info['name'] - size = self.info['size'] - url = self.info['url'] + try: + name = self.info['name'] + size = self.info['size'] + url = self.info['url'] - if name and name != url: - self.pyfile.name = name - else: - self.pyfile.name = name = self.info['name'] = urlparse(name).path.split('/')[-1] + if name and name != url: + self.pyfile.name = name + else: + self.pyfile.name = name = self.info['name'] = urlparse(name).path.split('/')[-1] - if size > 0: - self.pyfile.size = size - else: - size = "Unknown" + if size > 0: + self.pyfile.size = size + + except Exception: + pass - self.logDebug("File name: %s" % name, - "File size: %s" % size) + self.logDebug("File name: %s" % self.pyfile.name, + "File size: %s" % self.pyfile.size if self.pyfile.size > 0 else "Unknown") def checkInfo(self): -- cgit v1.2.3 From 9792c7f55449a97bbe4dcfa1579e1049fadbcf16 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 4 Jan 2015 20:22:06 +0100 Subject: [SimpleHoster] Improve checkTrafficLeft routine --- module/plugins/internal/SimpleHoster.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 4e2b4803b..c87a6160f 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -182,7 +182,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.89" + __version__ = "0.90" __pattern__ = r'^unmatchable$' @@ -593,6 +593,9 @@ class SimpleHoster(Hoster): def checkTrafficLeft(self): + if not self.account: + return True + traffic = self.account.getAccountInfo(self.user, True)['trafficleft'] if traffic is None: -- cgit v1.2.3 From df143e902d00903f16cf32174948f636bda56e4c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 8 Jan 2015 22:58:32 +0100 Subject: "New Year" Update: internal plugins --- module/plugins/internal/SimpleHoster.py | 55 ++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index c87a6160f..991dc6240 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -10,6 +10,7 @@ from urlparse import urljoin, urlparse from module.PyFile import statusMap as _statusMap from module.network.CookieJar import CookieJar +from module.network.HTTPRequest import BadHeader from module.network.RequestFactory import getURL from module.plugins.Hoster import Hoster from module.plugins.Plugin import Fail @@ -126,7 +127,7 @@ def timestamp(): #@TODO: Move to hoster class in 0.4.10 -def _isDirectLink(self, url, resumable=False): +def directLink(self, url, resumable=False): link = "" for i in xrange(5 if resumable else 1): @@ -182,7 +183,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.90" + __version__ = "0.91" __pattern__ = r'^unmatchable$' @@ -244,18 +245,32 @@ class SimpleHoster(Hoster): CHECK_TRAFFIC = False #: Set to True to force checking traffic left for premium account DIRECT_LINK = None #: Set to True to looking for direct link (as defined in handleDirect method), set to None to do it if self.account is True else False MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) + LOGIN_ACCOUNT = False #: Set to True to require account login + + directLink = directLink #@TODO: Remove in 0.4.10 @classmethod - def parseInfos(cls, urls): + def parseInfos(cls, urls): #@TODO: Built-in in 0.4.10 core, then remove from plugins for url in urls: url = replace_patterns(url, cls.FILE_URL_REPLACEMENTS if hasattr(cls, "FILE_URL_REPLACEMENTS") else cls.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 yield cls.getInfo(url) + @classmethod + def apiInfo(cls, url="", get={}, post={}): + url = unquote(url) + return {'name' : (urlparse(url).path.split('/')[-1] + or urlparse(url).query.split('&', 1)[0].split('=', 1)[1] + or _("Unknown")), + 'size' : 0, + 'status': 3, + 'url' : url} + + @classmethod def getInfo(cls, url="", html=""): - info = {'name': urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 'size': 0, 'status': 3, 'url': url} + info = cls.apiInfo(url) online = False try: @@ -268,7 +283,7 @@ class SimpleHoster(Hoster): info['error'] = "missing url" info['status'] = 1 - else: + elif info['status'] is 3: try: html = getURL(url, cookies=cls.COOKIES, decode=not cls.TEXT_ENCODING) @@ -343,11 +358,16 @@ class SimpleHoster(Hoster): def prepare(self): + self.pyfile.error = "" #@TODO: Remove in 0.4.10 + self.info = {} self.link = "" #@TODO: Move to hoster class in 0.4.10 self.directDL = False #@TODO: Move to hoster class in 0.4.10 self.multihost = False #@TODO: Move to hoster class in 0.4.10 + if self.LOGIN_ACCOUNT and not self.account: + self.fail(_("Required account not found")) + self.req.setOption("timeout", 120) if isinstance(self.COOKIES, list): @@ -399,7 +419,7 @@ class SimpleHoster(Hoster): self.logDebug("Handled as premium download") self.handlePremium() - else: + elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as free download") self.handleFree() @@ -420,15 +440,12 @@ class SimpleHoster(Hoster): elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): self.lastDownload = "" - - errmsg = _("No file downloaded") - if 'error' in self.info: - self.fail(errmsg, self.info['error']) - else: - self.fail(errmsg) + self.fail(errmsg, self.pyfile.error or _("No file downloaded")) else: - rules = {'empty file': re.compile(r"^$")} + rules = {'empty file': re.compile(r'\A\Z'), + 'html file' : re.compile(r'\A\s*)?\d{3}[^\d]*')} if hasattr(self, 'ERROR_PATTERN'): rules['error'] = re.compile(self.ERROR_PATTERN) @@ -529,7 +546,7 @@ class SimpleHoster(Hoster): def handleDirect(self, pyfile): - link = _isDirectLink(self, pyfile.url, self.resumeDownload) + link = self.directLink(pyfile.url, self.resumeDownload) if link: self.logInfo(_("Direct download link detected")) @@ -543,9 +560,9 @@ class SimpleHoster(Hoster): pass - def handleFree(self, pyfile=None): + def handleFree(self, pyfile): if not hasattr(self, 'LINK_FREE_PATTERN'): - self.fail(_("Free download not implemented")) + self.logError(_("Free download not implemented")) try: m = re.search(self.LINK_FREE_PATTERN, self.html) @@ -558,9 +575,11 @@ class SimpleHoster(Hoster): self.fail(e) - def handlePremium(self, pyfile=None): + def handlePremium(self, pyfile): if not hasattr(self, 'LINK_PREMIUM_PATTERN'): - self.fail(_("Premium download not implemented")) + self.logError(_("Premium download not implemented")) + self.logDebug("Handled as free download") + self.handleFree() try: m = re.search(self.LINK_PREMIUM_PATTERN, self.html) -- cgit v1.2.3 From e7d5b4df7c5b0bc859175d4d1902207f91964f89 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 9 Jan 2015 00:36:54 +0100 Subject: [SimpleHoster] Better checkDownload rules --- module/plugins/internal/SimpleHoster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 991dc6240..5450f2bc9 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -445,7 +445,7 @@ class SimpleHoster(Hoster): else: rules = {'empty file': re.compile(r'\A\Z'), 'html file' : re.compile(r'\A\s*)?\d{3}[^\d]*')} + 'html error': re.compile(r'\A\s*(<.+>)?\d{3}(\Z|\s+)')} if hasattr(self, 'ERROR_PATTERN'): rules['error'] = re.compile(self.ERROR_PATTERN) -- cgit v1.2.3 From ea2d07843d369d8b8fd2aa02930bf549ce94a661 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 9 Jan 2015 03:25:42 +0100 Subject: Spare fixes --- module/plugins/internal/SimpleHoster.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 5450f2bc9..2a6624e10 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -261,7 +261,7 @@ class SimpleHoster(Hoster): def apiInfo(cls, url="", get={}, post={}): url = unquote(url) return {'name' : (urlparse(url).path.split('/')[-1] - or urlparse(url).query.split('&', 1)[0].split('=', 1)[1] + or urlparse(url).query.split('=', 1)[::-1][0].split('&', 1)[0] or _("Unknown")), 'size' : 0, 'status': 3, @@ -417,11 +417,11 @@ class SimpleHoster(Hoster): if self.premium and (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as premium download") - self.handlePremium() + self.handlePremium(pyfile) elif not self.LOGIN_ACCOUNT or (not self.CHECK_TRAFFIC or self.checkTrafficLeft()): self.logDebug("Handled as free download") - self.handleFree() + self.handleFree(pyfile) self.downloadLink(self.link) self.checkFile() @@ -430,7 +430,7 @@ class SimpleHoster(Hoster): def downloadLink(self, link): if link and isinstance(link, basestring): self.correctCaptcha() - self.download(link, disposition=True) + self.download(link, disposition=False) #@TODO: Set `disposition=True` in 0.4.10 def checkFile(self): @@ -579,7 +579,7 @@ class SimpleHoster(Hoster): if not hasattr(self, 'LINK_PREMIUM_PATTERN'): self.logError(_("Premium download not implemented")) self.logDebug("Handled as free download") - self.handleFree() + self.handleFree(pyfile) try: m = re.search(self.LINK_PREMIUM_PATTERN, self.html) -- cgit v1.2.3 From 7124a00dccf36816aff73b3834131e7e392a0c3c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 9 Jan 2015 21:22:04 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/1022 --- module/plugins/internal/SimpleHoster.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 2a6624e10..1a2961167 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -183,7 +183,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.91" + __version__ = "0.92" __pattern__ = r'^unmatchable$' @@ -274,9 +274,10 @@ class SimpleHoster(Hoster): online = False try: - info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here, please save api stuff to info['api'] + info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here + except Exception: - pass + info['pattern'] = {} if not html: if not url: @@ -327,7 +328,7 @@ class SimpleHoster(Hoster): else: online = True - if 'pattern' in info and not info['pattern']: + if not info['pattern']: info.pop('pattern', None) if online: -- cgit v1.2.3 From 502c1437e838282aa56a286bb3751382c3aaf65e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 10 Jan 2015 16:01:38 +0100 Subject: Improve getInfo --- module/plugins/internal/SimpleHoster.py | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 1a2961167..fb19b8725 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -183,7 +183,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.92" + __version__ = "0.93" __pattern__ = r'^unmatchable$' @@ -264,7 +264,7 @@ class SimpleHoster(Hoster): or urlparse(url).query.split('=', 1)[::-1][0].split('&', 1)[0] or _("Unknown")), 'size' : 0, - 'status': 3, + 'status': 3 if url else 8, 'url' : url} @@ -462,6 +462,10 @@ class SimpleHoster(Hoster): def checkErrors(self): + if not self.html: + self.logWarning(_("No html code to check")) + return + if hasattr(self, 'PREMIUM_ONLY_PATTERN') and self.premium and re.search(self.PREMIUM_ONLY_PATTERN, self.html): self.fail(_("Link require a premium account to be handled")) @@ -483,42 +487,44 @@ class SimpleHoster(Hoster): def checkStatus(self, getinfo=True): - if getinfo: + if not self.info or getinfo: self.logDebug("File info (BEFORE): %s" % self.info) self.info.update(self.getInfo(self.pyfile.url, self.html)) - if 'status' not in self.info: - return + try: + status = self.info['status'] - status = self.info['status'] + if status is 1: + self.offline() - if status is 1: - self.offline() + elif status is 6: + self.tempOffline() - elif status is 6: - self.tempOffline() + elif status is 8: + self.fail() - elif status is not 2: + finally: self.logDebug("File status: %s" % statusMap[status], "File info: %s" % self.info) def checkNameSize(self, getinfo=True): - if getinfo: + if not self.info or getinfo: self.logDebug("File info (BEFORE): %s" % self.info) self.info.update(self.getInfo(self.pyfile.url, self.html)) self.logDebug("File info (AFTER): %s" % self.info) try: - name = self.info['name'] - size = self.info['size'] url = self.info['url'] - + name = self.info['name'] if name and name != url: self.pyfile.name = name - else: - self.pyfile.name = name = self.info['name'] = urlparse(name).path.split('/')[-1] + except Exception: + pass + + try: + size = self.info['size'] if size > 0: self.pyfile.size = size -- cgit v1.2.3 From 4747e1d7958c9fb1180da6f3a21f3093220a6655 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 10 Jan 2015 21:17:27 +0100 Subject: Code improvements --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index fb19b8725..5a32ac943 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -183,7 +183,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.93" + __version__ = "0.94" __pattern__ = r'^unmatchable$' @@ -441,7 +441,7 @@ class SimpleHoster(Hoster): elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): self.lastDownload = "" - self.fail(errmsg, self.pyfile.error or _("No file downloaded")) + self.fail(self.pyfile.error or _("No file downloaded")) else: rules = {'empty file': re.compile(r'\A\Z'), -- cgit v1.2.3 From e3bdcffc6020322d9f8985c6f6be9476e8c779c9 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 11 Jan 2015 23:20:32 +0100 Subject: [SkipRev] Fix https://github.com/pyload/pyload/issues/1036 --- module/plugins/internal/SimpleHoster.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 5a32ac943..3bdaa5aef 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -115,9 +115,9 @@ def parseFileInfo(plugin, url="", html=""): #@NOTE: Every plugin must have own parseInfos classmethod to work with 0.4.10 def create_getInfo(plugin): if hasattr(plugin, "parseInfos"): - fn = lambda urls: [(info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)] + fn = lambda urls: map(yield, (info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)) else: - fn = lambda urls: [parseFileInfo(url) for url in urls] + fn = lambda urls: map(yield, parseFileInfo(url) for url in urls) return fn @@ -183,7 +183,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.94" + __version__ = "0.95" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From db34c2493babf7a0313fb72ac2349c324d12d0ae Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 11 Jan 2015 23:34:58 +0100 Subject: [SimpleHoster] Fix previous commit --- module/plugins/internal/SimpleHoster.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 3bdaa5aef..fa1ea45f2 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -114,10 +114,15 @@ def parseFileInfo(plugin, url="", html=""): #@TODO: Remove in 0.4.10 #@NOTE: Every plugin must have own parseInfos classmethod to work with 0.4.10 def create_getInfo(plugin): + + def generator(list): + for x in list: + yield x + if hasattr(plugin, "parseInfos"): - fn = lambda urls: map(yield, (info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)) + fn = lambda urls: generator((info['name'], info['size'], info['status'], info['url']) for info in plugin.parseInfos(urls)) else: - fn = lambda urls: map(yield, parseFileInfo(url) for url in urls) + fn = lambda urls: generator(parseFileInfo(url) for url in urls) return fn @@ -183,7 +188,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.95" + __version__ = "0.96" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 6343210720782fa99f679f87447c1418ee5875cb Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 01:43:29 +0100 Subject: [SimpleCrypter] getLinks auto-complete links --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index fa1ea45f2..4c3d376ca 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -145,8 +145,8 @@ def directLink(self, url, resumable=False): location = header['location'] if not urlparse(location).scheme: - p = urlparse(url) - base = "%s://%s" % (p.scheme, p.netloc) + parsed = urlparse(url) + base = "%s://%s" % (parsed.scheme, parsed.netloc) location = urljoin(base, location) if resumable: -- cgit v1.2.3 From 99f3e73c86c84a39d3f83611d53c8fccc1b7305f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 14:53:58 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/1039 --- module/plugins/internal/SimpleHoster.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 4c3d376ca..0c8d7c5ae 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -2,6 +2,7 @@ import re +from datetime import datetime, timedelta from inspect import isclass from os.path import exists from time import time @@ -188,7 +189,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.96" + __version__ = "0.97" __pattern__ = r'^unmatchable$' @@ -446,7 +447,7 @@ class SimpleHoster(Hoster): elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): self.lastDownload = "" - self.fail(self.pyfile.error or _("No file downloaded")) + self.error(self.pyfile.error or _("No file downloaded")) else: rules = {'empty file': re.compile(r'\A\Z'), -- cgit v1.2.3 From 114542939a9ccc0d93e120d590f81a4a0f2ab809 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 22:09:47 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/1038 --- module/plugins/internal/SimpleHoster.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 0c8d7c5ae..3f14ca711 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -189,7 +189,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.97" + __version__ = "0.98" __pattern__ = r'^unmatchable$' @@ -334,9 +334,6 @@ class SimpleHoster(Hoster): else: online = True - if not info['pattern']: - info.pop('pattern', None) - if online: info['status'] = 2 @@ -357,6 +354,9 @@ class SimpleHoster(Hoster): hashtype = info['pattern']['T'] if 'T' in info['pattern'] else "hash" info[hashtype] = info['pattern']['H'] + if not info['pattern']: + info.pop('pattern', None) + return info -- cgit v1.2.3 From f2ac339fa159cd2bcea912d6fc2e40129b2dfc15 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 13 Jan 2015 23:27:54 +0100 Subject: [SimpleHoster] Improve error handling --- module/plugins/internal/SimpleHoster.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 3f14ca711..2b87c5996 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -189,7 +189,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.98" + __version__ = "0.99" __pattern__ = r'^unmatchable$' @@ -577,16 +577,12 @@ class SimpleHoster(Hoster): if not hasattr(self, 'LINK_FREE_PATTERN'): self.logError(_("Free download not implemented")) - try: - m = re.search(self.LINK_FREE_PATTERN, self.html) - if m is None: - self.error(_("Free download link not found")) - + m = re.search(self.LINK_FREE_PATTERN, self.html) + if m is None: + self.error(_("Free download link not found")) + else: self.link = m.group(1) - except Exception, e: - self.fail(e) - def handlePremium(self, pyfile): if not hasattr(self, 'LINK_PREMIUM_PATTERN'): @@ -594,16 +590,12 @@ class SimpleHoster(Hoster): self.logDebug("Handled as free download") self.handleFree(pyfile) - try: - m = re.search(self.LINK_PREMIUM_PATTERN, self.html) - if m is None: - self.error(_("Premium download link not found")) - + m = re.search(self.LINK_PREMIUM_PATTERN, self.html) + if m is None: + self.error(_("Premium download link not found")) + else: self.link = m.group(1) - except Exception, e: - self.fail(e) - def longWait(self, wait_time=None, max_tries=3): if wait_time and isinstance(wait_time, (int, long, float)): -- cgit v1.2.3 From 9f1519a690a8c0e9650ee9ec5b8ad5d7db12a2c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 16 Jan 2015 16:15:00 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/1045 --- module/plugins/internal/SimpleHoster.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 2b87c5996..4d7329541 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -137,6 +137,8 @@ def directLink(self, url, resumable=False): link = "" for i in xrange(5 if resumable else 1): + self.logDebug("Redirect #%d to: %s" % (i, url)) + header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) if 'content-disposition' in header: @@ -150,18 +152,21 @@ def directLink(self, url, resumable=False): base = "%s://%s" % (parsed.scheme, parsed.netloc) location = urljoin(base, location) - if resumable: - url = location - self.logDebug("Redirect #%d to: %s" % (++i, location)) - continue - - elif 'code' in header and header['code'] == 302: + if 'code' in header and header['code'] == 302: link = location - elif 'content-type' in header and header['content-type'] and "html" not in header['content-type']: - link = url + url = location + continue + + elif 'content-type' in header: + if "html" not in header['content-type']: + link = url + + elif link: + link = "" break + else: self.logError(_("Too many redirects")) @@ -189,7 +194,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "0.99" + __version__ = "1.00" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 1721b2e2f55e97b381da3b6a2dde034534208bc8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 18 Jan 2015 12:15:17 +0100 Subject: [SimpleHoster] Fix and improve directLink routine (now fileUrl) --- module/plugins/internal/SimpleHoster.py | 63 +++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 4d7329541..c1982ee67 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- +import mimetypes +import os import re from datetime import datetime, timedelta from inspect import isclass -from os.path import exists from time import time from urllib import unquote from urlparse import urljoin, urlparse @@ -107,7 +108,13 @@ def parseFileInfo(plugin, url="", html=""): info = plugin.getInfo(url, html) res = info['name'], info['size'], info['status'], info['url'] else: - res = urlparse(unquote(url)).path.split('/')[-1] or _("Unknown"), 0, 3, url + url = unquote(url) + res = ((urlparse(url).path.split('/')[-1] + or urlparse(url).query.split('=', 1)[::-1][0].split('&', 1)[0] + or _("Unknown")), + 0, + 3 if url else 8, + url) return res @@ -133,10 +140,17 @@ def timestamp(): #@TODO: Move to hoster class in 0.4.10 -def directLink(self, url, resumable=False): - link = "" +def fileUrl(self, url, follow_location=False): + link = "" + redirect = 1 - for i in xrange(5 if resumable else 1): + if isinstance(follow_location, int): + redirect = max(follow_location, 1) + + elif follow_location: + redirect = 5 + + for i in xrange(redirect): self.logDebug("Redirect #%d to: %s" % (i, url)) header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) @@ -144,25 +158,36 @@ def directLink(self, url, resumable=False): if 'content-disposition' in header: link = url - elif 'location' in header and header['location']: + elif 'location' in header and header['location'].strip(): location = header['location'] if not urlparse(location).scheme: - parsed = urlparse(url) - base = "%s://%s" % (parsed.scheme, parsed.netloc) - location = urljoin(base, location) + url_p = urlparse(url) + baseurl = "%s://%s" % (url_p.scheme, url_p.netloc) + location = urljoin(baseurl, location) if 'code' in header and header['code'] == 302: link = location - url = location - continue + if follow_location: + url = location + continue - elif 'content-type' in header: - if "html" not in header['content-type']: - link = url + else: + extension = os.path.splitext(urlparse(url).path.split('/')[-1])[-1] + + if 'content-type' in header and header['content-type'].strip(): + mimetype = header['content-type'].split(';')[0].strip() - elif link: + elif extension: + mimetype = mimetypes.guess_extension(extension, False)[0] or "application/octet-stream" + + else: + mimetype = "" + + if mimetype and (link or 'html' not in mimetype): + link = url + else: link = "" break @@ -194,7 +219,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.00" + __version__ = "1.01" __pattern__ = r'^unmatchable$' @@ -258,7 +283,7 @@ class SimpleHoster(Hoster): MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) LOGIN_ACCOUNT = False #: Set to True to require account login - directLink = directLink #@TODO: Remove in 0.4.10 + directLink = fileUrl #@TODO: Remove in 0.4.10 @classmethod @@ -450,7 +475,7 @@ class SimpleHoster(Hoster): self.invalidCaptcha() self.retry(10, reason=_("Wrong captcha")) - elif not self.lastDownload or not exists(fs_encode(self.lastDownload)): + elif not self.lastDownload or not os.path.exists(fs_encode(self.lastDownload)): self.lastDownload = "" self.error(self.pyfile.error or _("No file downloaded")) @@ -564,7 +589,7 @@ class SimpleHoster(Hoster): def handleDirect(self, pyfile): - link = self.directLink(pyfile.url, self.resumeDownload) + link = self.fileUrl(pyfile.url, self.resumeDownload) if link: self.logInfo(_("Direct download link detected")) -- cgit v1.2.3 From 46f690782d55d54153fdba2f6b352c9be653eae5 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 18 Jan 2015 13:29:04 +0100 Subject: [SimpleHoster] Fix typo --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index c1982ee67..afbfea1c8 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -219,7 +219,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.01" + __version__ = "1.02" __pattern__ = r'^unmatchable$' @@ -589,7 +589,7 @@ class SimpleHoster(Hoster): def handleDirect(self, pyfile): - link = self.fileUrl(pyfile.url, self.resumeDownload) + link = self.directLink(pyfile.url, self.resumeDownload) if link: self.logInfo(_("Direct download link detected")) -- cgit v1.2.3 From df84a349ce9008ce927461a53d9ead1fdf71a73e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 18 Jan 2015 18:28:07 +0100 Subject: [SimpleHoster] Fix PREMIUM_ONLY_PATTERN handling --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index afbfea1c8..e499f4e47 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -219,7 +219,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.02" + __version__ = "1.03" __pattern__ = r'^unmatchable$' @@ -502,7 +502,7 @@ class SimpleHoster(Hoster): self.logWarning(_("No html code to check")) return - if hasattr(self, 'PREMIUM_ONLY_PATTERN') and self.premium and re.search(self.PREMIUM_ONLY_PATTERN, self.html): + if hasattr(self, 'PREMIUM_ONLY_PATTERN') and not self.premium and re.search(self.PREMIUM_ONLY_PATTERN, self.html): self.fail(_("Link require a premium account to be handled")) elif hasattr(self, 'ERROR_PATTERN'): -- cgit v1.2.3 From 04c47a8052c4180cb0c7222b9f0cd5929c825b07 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 18 Jan 2015 19:16:28 +0100 Subject: [SimpleHoster] Fix fileUrl follow_location --- module/plugins/internal/SimpleHoster.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index e499f4e47..d55ed6f99 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -144,12 +144,12 @@ def fileUrl(self, url, follow_location=False): link = "" redirect = 1 - if isinstance(follow_location, int): - redirect = max(follow_location, 1) - - elif follow_location: + if isinstance(follow_location, bool): redirect = 5 + elif isinstance(follow_location, int): + redirect = max(follow_location, 1) + for i in xrange(redirect): self.logDebug("Redirect #%d to: %s" % (i, url)) @@ -219,7 +219,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.03" + __version__ = "1.04" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 8f45ccee3c26f991738288805963a5961cd68267 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 20 Jan 2015 01:23:33 +0100 Subject: [SimpleHoster] Improve downloadLink routine --- module/plugins/internal/SimpleHoster.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index d55ed6f99..78f5e531d 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -219,7 +219,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.04" + __version__ = "1.05" __pattern__ = r'^unmatchable$' @@ -467,6 +467,12 @@ class SimpleHoster(Hoster): def downloadLink(self, link): if link and isinstance(link, basestring): self.correctCaptcha() + + if not urlparse(link).scheme: + url_p = urlparse(self.pyfile.url) + baseurl = "%s://%s" % (url_p.scheme, url_p.netloc) + link = urljoin(baseurl, link) + self.download(link, disposition=False) #@TODO: Set `disposition=True` in 0.4.10 -- cgit v1.2.3 From 96ee02d0120690291962269d23f1a324ff674e99 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 20 Jan 2015 02:46:39 +0100 Subject: [SimpleHoster] Improve getInfo --- module/plugins/internal/SimpleHoster.py | 41 +++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 78f5e531d..819572a7e 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -151,9 +151,33 @@ def fileUrl(self, url, follow_location=False): redirect = max(follow_location, 1) for i in xrange(redirect): - self.logDebug("Redirect #%d to: %s" % (i, url)) + try: + self.logDebug("Redirect #%d to: %s" % (i, url)) + header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) + + except Exception: #: Bad bad bad... + req = pyreq.getHTTPRequest() + res = req.load(url, cookies=True, just_header=True, decode=True) + + req.close() + + header = {"code": req.code} + for line in res.splitlines(): + line = line.strip() + if not line or ":" not in line: + continue + + key, none, value = line.partition(":") + key = key.lower().strip() + value = value.strip() - header = self.load(url, ref=True, cookies=True, just_header=True, decode=True) + if key in header: + if type(header[key]) == list: + header[key].append(value) + else: + header[key] = [header[key], value] + else: + header[key] = value if 'content-disposition' in header: link = url @@ -193,7 +217,10 @@ def fileUrl(self, url, follow_location=False): break else: - self.logError(_("Too many redirects")) + try: + self.logError(_("Too many redirects")) + except Exception: + pass return link @@ -219,7 +246,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.05" + __version__ = "1.06" __pattern__ = r'^unmatchable$' @@ -320,7 +347,7 @@ class SimpleHoster(Hoster): info['error'] = "missing url" info['status'] = 1 - elif info['status'] is 3: + elif info['status'] is 3 and not fileUrl(None, url): try: html = getURL(url, cookies=cls.COOKIES, decode=not cls.TEXT_ENCODING) @@ -464,7 +491,7 @@ class SimpleHoster(Hoster): self.checkFile() - def downloadLink(self, link): + def downloadLink(self, link, disposition=False): if link and isinstance(link, basestring): self.correctCaptcha() @@ -473,7 +500,7 @@ class SimpleHoster(Hoster): baseurl = "%s://%s" % (url_p.scheme, url_p.netloc) link = urljoin(baseurl, link) - self.download(link, disposition=False) #@TODO: Set `disposition=True` in 0.4.10 + self.download(link, disposition=disposition) #@TODO: Set `disposition=True` in 0.4.10 def checkFile(self): -- cgit v1.2.3 From f531393337b58e570c2b23f63275b883506cb92c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 22 Jan 2015 22:14:47 +0100 Subject: [SimpleDereferer][SimpleHoster] Fix https://github.com/pyload/pyload/issues/1065 --- module/plugins/internal/SimpleHoster.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 819572a7e..13a26c732 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -246,7 +246,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.06" + __version__ = "1.07" __pattern__ = r'^unmatchable$' @@ -453,6 +453,7 @@ class SimpleHoster(Hoster): def preload(self): + self.req.renewHTTPRequest() #@NOTE: Remove in 0.4.10 self.html = self.load(self.pyfile.url, cookies=bool(self.COOKIES), decode=not self.TEXT_ENCODING) if isinstance(self.TEXT_ENCODING, basestring): -- cgit v1.2.3 From 312bbd1e82404a8e73bb14fae2acb81f7ea62193 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 24 Jan 2015 02:15:18 +0100 Subject: [SimpleHoster] Fix https://github.com/pyload/pyload/issues/1070 --- module/plugins/internal/SimpleHoster.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 13a26c732..3770d0575 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -140,15 +140,14 @@ def timestamp(): #@TODO: Move to hoster class in 0.4.10 -def fileUrl(self, url, follow_location=False): +def fileUrl(self, url, follow_location=None): link = "" redirect = 1 - if isinstance(follow_location, bool): - redirect = 5 - - elif isinstance(follow_location, int): + if type(follow_location) is int: redirect = max(follow_location, 1) + else: + redirect = 5 for i in xrange(redirect): try: @@ -204,7 +203,7 @@ def fileUrl(self, url, follow_location=False): mimetype = header['content-type'].split(';')[0].strip() elif extension: - mimetype = mimetypes.guess_extension(extension, False)[0] or "application/octet-stream" + mimetype = mimetypes.guess_type(extension, False)[0] or "application/octet-stream" else: mimetype = "" @@ -246,7 +245,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.07" + __version__ = "1.08" __pattern__ = r'^unmatchable$' -- cgit v1.2.3 From 031d86706aa13270793e31c21ad3f386ca62752b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 24 Jan 2015 03:50:33 +0100 Subject: Spare code improvements --- module/plugins/internal/SimpleHoster.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 3770d0575..506974259 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -245,7 +245,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.08" + __version__ = "1.09" __pattern__ = r'^unmatchable$' @@ -424,6 +424,7 @@ class SimpleHoster(Hoster): self.pyfile.error = "" #@TODO: Remove in 0.4.10 self.info = {} + self.html = "" self.link = "" #@TODO: Move to hoster class in 0.4.10 self.directDL = False #@TODO: Move to hoster class in 0.4.10 self.multihost = False #@TODO: Move to hoster class in 0.4.10 -- cgit v1.2.3 From be322927f8bedbe86e801326651bd548eeda1dd3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 25 Jan 2015 00:27:21 +0100 Subject: [BasePlugin] Fix https://github.com/pyload/pyload/issues/1073 --- module/plugins/internal/SimpleHoster.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 506974259..5c9d993e7 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -245,7 +245,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.09" + __version__ = "1.10" __pattern__ = r'^unmatchable$' @@ -492,7 +492,7 @@ class SimpleHoster(Hoster): self.checkFile() - def downloadLink(self, link, disposition=False): + def downloadLink(self, link, disposition=False): #@TODO: Set `disposition=True` in 0.4.10 if link and isinstance(link, basestring): self.correctCaptcha() @@ -501,7 +501,7 @@ class SimpleHoster(Hoster): baseurl = "%s://%s" % (url_p.scheme, url_p.netloc) link = urljoin(baseurl, link) - self.download(link, disposition=disposition) #@TODO: Set `disposition=True` in 0.4.10 + self.download(link, ref=False, disposition=disposition) def checkFile(self): -- cgit v1.2.3 From e704a6cdd07c01a2f79eb851d7f2ecdf78da77fd Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 28 Jan 2015 01:18:23 +0100 Subject: [UploadedTo] Rewritten --- module/plugins/internal/SimpleHoster.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 5c9d993e7..30add3f41 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -245,7 +245,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.10" + __version__ = "1.11" __pattern__ = r'^unmatchable$' @@ -333,7 +333,7 @@ class SimpleHoster(Hoster): @classmethod def getInfo(cls, url="", html=""): info = cls.apiInfo(url) - online = False + online = False if info['status'] != 2 else True try: info['pattern'] = re.match(cls.__pattern__, url).groupdict() #: pattern groups will be saved here @@ -341,7 +341,7 @@ class SimpleHoster(Hoster): except Exception: info['pattern'] = {} - if not html: + if not html and not online: if not url: info['error'] = "missing url" info['status'] = 1 -- cgit v1.2.3 From 31b5cf3426accb16268ce0d968b619c4893cd34f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Thu, 29 Jan 2015 00:25:13 +0100 Subject: [SimpleDereferer][SimpleHoster] Revert renewHTTPRequest --- module/plugins/internal/SimpleHoster.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 30add3f41..c74e33d59 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -245,7 +245,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.11" + __version__ = "1.12" __pattern__ = r'^unmatchable$' @@ -453,7 +453,6 @@ class SimpleHoster(Hoster): def preload(self): - self.req.renewHTTPRequest() #@NOTE: Remove in 0.4.10 self.html = self.load(self.pyfile.url, cookies=bool(self.COOKIES), decode=not self.TEXT_ENCODING) if isinstance(self.TEXT_ENCODING, basestring): -- cgit v1.2.3 From 79725268402043906f619f7c09e848e02ab8a17b Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 31 Jan 2015 22:00:59 +0100 Subject: Spare code cosmetics --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index c74e33d59..da178ef9c 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -547,8 +547,8 @@ class SimpleHoster(Hoster): elif hasattr(self, 'WAIT_PATTERN'): m = re.search(self.WAIT_PATTERN, self.html) if m: - wait_time = sum([int(v) * {"hr": 3600, "hour": 3600, "min": 60, "sec": 1}[u.lower()] for v, u in - re.findall(r'(\d+)\s*(hr|hour|min|sec)', m.group(0), re.I)]) + wait_time = sum(int(v) * {"hr": 3600, "hour": 3600, "min": 60, "sec": 1}[u.lower()] for v, u in + re.findall(r'(\d+)\s*(hr|hour|min|sec)', m.group(0), re.I)) self.wait(wait_time, wait_time > 300) return -- cgit v1.2.3 From d622107c1c869dd27f2104f97184e24bc35c48be Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 2 Feb 2015 01:41:15 +0100 Subject: [MultiHoster][SimpleHoster] Improve info stuff --- module/plugins/internal/SimpleHoster.py | 43 +++++++++++++++------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index da178ef9c..4a1f62395 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -108,13 +108,14 @@ def parseFileInfo(plugin, url="", html=""): info = plugin.getInfo(url, html) res = info['name'], info['size'], info['status'], info['url'] else: - url = unquote(url) - res = ((urlparse(url).path.split('/')[-1] - or urlparse(url).query.split('=', 1)[::-1][0].split('&', 1)[0] - or _("Unknown")), - 0, - 3 if url else 8, - url) + url = unquote(url) + url_p = urlparse(url) + res = ((url_p.path.split('/')[-1] + or url_p.query.split('=', 1)[::-1][0].split('&', 1)[0] + or url_p.netloc.split('.', 1)[0]), + 0, + 3 if url else 8, + url) return res @@ -245,7 +246,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.12" + __version__ = "1.13" __pattern__ = r'^unmatchable$' @@ -315,16 +316,17 @@ class SimpleHoster(Hoster): @classmethod def parseInfos(cls, urls): #@TODO: Built-in in 0.4.10 core, then remove from plugins for url in urls: - url = replace_patterns(url, cls.FILE_URL_REPLACEMENTS if hasattr(cls, "FILE_URL_REPLACEMENTS") else cls.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 + url = replace_patterns(url, cls.URL_REPLACEMENTS) yield cls.getInfo(url) @classmethod def apiInfo(cls, url="", get={}, post={}): - url = unquote(url) - return {'name' : (urlparse(url).path.split('/')[-1] - or urlparse(url).query.split('=', 1)[::-1][0].split('&', 1)[0] - or _("Unknown")), + 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} @@ -366,17 +368,11 @@ class SimpleHoster(Hoster): if hasattr(cls, "OFFLINE_PATTERN") and re.search(cls.OFFLINE_PATTERN, html): info['status'] = 1 - elif hasattr(cls, "FILE_OFFLINE_PATTERN") and re.search(cls.FILE_OFFLINE_PATTERN, html): #@TODO: Remove in 0.4.10 - info['status'] = 1 - elif hasattr(cls, "TEMP_OFFLINE_PATTERN") and re.search(cls.TEMP_OFFLINE_PATTERN, html): info['status'] = 6 else: - for pattern in ("FILE_INFO_PATTERN", "INFO_PATTERN", - "FILE_NAME_PATTERN", "NAME_PATTERN", - "FILE_SIZE_PATTERN", "SIZE_PATTERN", - "HASHSUM_PATTERN"): #@TODO: Remove old patterns starting with "FILE_" in 0.4.10 + for pattern in ("INFO_PATTERN", "NAME_PATTERN", "SIZE_PATTERN", "HASHSUM_PATTERN"): try: attr = getattr(cls, pattern) pdict = re.search(attr, html).groupdict() @@ -395,11 +391,11 @@ class SimpleHoster(Hoster): if 'N' in info['pattern']: info['name'] = replace_patterns(unquote(info['pattern']['N'].strip()), - cls.FILE_NAME_REPLACEMENTS if hasattr(cls, "FILE_NAME_REPLACEMENTS") else cls.NAME_REPLACEMENTS) #@TODO: Remove FILE_NAME_REPLACEMENTS check in 0.4.10 + cls.NAME_REPLACEMENTS) if 'S' in info['pattern']: size = replace_patterns(info['pattern']['S'] + info['pattern']['U'] if 'U' in info['pattern'] else info['pattern']['S'], - cls.FILE_SIZE_REPLACEMENTS if hasattr(cls, "FILE_SIZE_REPLACEMENTS") else cls.SIZE_REPLACEMENTS) #@TODO: Remove FILE_SIZE_REPLACEMENTS check in 0.4.10 + cls.SIZE_REPLACEMENTS) info['size'] = parseFileSize(size) elif isinstance(info['size'], basestring): @@ -448,8 +444,7 @@ class SimpleHoster(Hoster): else: self.directDL = self.DIRECT_LINK - self.pyfile.url = replace_patterns(self.pyfile.url, - self.FILE_URL_REPLACEMENTS if hasattr(self, "FILE_URL_REPLACEMENTS") else self.URL_REPLACEMENTS) #@TODO: Remove FILE_URL_REPLACEMENTS check in 0.4.10 + self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS) def preload(self): -- cgit v1.2.3 From 7b6a9a68dfbf67f075bfe86e67be5390da4b8c1d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 2 Feb 2015 18:48:06 +0100 Subject: Fix https://github.com/pyload/pyload/issues/1134 --- module/plugins/internal/SimpleHoster.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 4a1f62395..0ac49de19 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -246,7 +246,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.13" + __version__ = "1.14" __pattern__ = r'^unmatchable$' @@ -552,8 +552,10 @@ class SimpleHoster(Hoster): def checkStatus(self, getinfo=True): if not self.info or getinfo: - self.logDebug("File info (BEFORE): %s" % self.info) + self.logDebug("Update file info...") + self.logDebug("Previous file info: %s" % self.info) self.info.update(self.getInfo(self.pyfile.url, self.html)) + self.logDebug("Current file info: %s" % self.info) try: status = self.info['status'] @@ -568,19 +570,19 @@ class SimpleHoster(Hoster): self.fail() finally: - self.logDebug("File status: %s" % statusMap[status], - "File info: %s" % self.info) + self.logDebug("File status: %s" % statusMap[status]) def checkNameSize(self, getinfo=True): if not self.info or getinfo: - self.logDebug("File info (BEFORE): %s" % self.info) + self.logDebug("Update file info...") + self.logDebug("Previous file info: %s" % self.info) self.info.update(self.getInfo(self.pyfile.url, self.html)) - self.logDebug("File info (AFTER): %s" % self.info) + self.logDebug("Current file info: %s" % self.info) try: - url = self.info['url'] - name = self.info['name'] + url = self.info['url'].strip() + name = self.info['name'].strip() if name and name != url: self.pyfile.name = name -- cgit v1.2.3 From b25bc61dd47d8d3c42969bd0f72443b21c4b059e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 8 Feb 2015 02:09:45 +0100 Subject: Spare code cosmetics --- module/plugins/internal/SimpleHoster.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index 0ac49de19..ca8fce05f 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -667,8 +667,7 @@ class SimpleHoster(Hoster): self.logInfo(_("Download limit reached, reconnect or wait %s") % time_str) - self.setWait(wait_time, True) - self.wait() + self.wait(wait_time, True) self.retry(max_tries=max_tries, reason=_("Download limit reached")) -- cgit v1.2.3 From 6616c00ba1c40f5d56959bd0e4725f26250e1292 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 9 Feb 2015 17:42:31 +0100 Subject: Spare code cosmetics --- module/plugins/internal/SimpleHoster.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index ca8fce05f..e820ab141 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -246,7 +246,7 @@ def secondsToMidnight(gmt=0): class SimpleHoster(Hoster): __name__ = "SimpleHoster" __type__ = "hoster" - __version__ = "1.14" + __version__ = "1.15" __pattern__ = r'^unmatchable$' @@ -309,6 +309,7 @@ class SimpleHoster(Hoster): DIRECT_LINK = None #: Set to True to looking for direct link (as defined in handleDirect method), set to None to do it if self.account is True else False MULTI_HOSTER = False #: Set to True to leech other hoster link (as defined in handleMulti method) LOGIN_ACCOUNT = False #: Set to True to require account login + DISPOSITION = True #: Work-around to `filename*=UTF-8` bug; remove in 0.4.10 directLink = fileUrl #@TODO: Remove in 0.4.10 @@ -482,11 +483,11 @@ class SimpleHoster(Hoster): self.logDebug("Handled as free download") self.handleFree(pyfile) - self.downloadLink(self.link) + self.downloadLink(self.link, self.DISPOSITION) #: Remove `DISPOSITION` in 0.4.10 self.checkFile() - def downloadLink(self, link, disposition=False): #@TODO: Set `disposition=True` in 0.4.10 + def downloadLink(self, link, disposition=True): if link and isinstance(link, basestring): self.correctCaptcha() @@ -598,7 +599,7 @@ class SimpleHoster(Hoster): pass self.logDebug("File name: %s" % self.pyfile.name, - "File size: %s" % self.pyfile.size if self.pyfile.size > 0 else "Unknown") + "File size: %s" % (self.pyfile.size if self.pyfile.size > 0 else "Unknown")) def checkInfo(self): -- cgit v1.2.3 From d952efb58d72b0add82efe34a7f2fbdc51423490 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 11 Feb 2015 03:58:19 +0100 Subject: [XFSHoster] Fix https://github.com/pyload/pyload/issues/1112 --- module/plugins/internal/SimpleHoster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/internal/SimpleHoster.py') diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index e820ab141..e4ff1a2d8 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -483,7 +483,7 @@ class SimpleHoster(Hoster): self.logDebug("Handled as free download") self.handleFree(pyfile) - self.downloadLink(self.link, self.DISPOSITION) #: Remove `DISPOSITION` in 0.4.10 + self.downloadLink(self.link, self.DISPOSITION) #: Remove `self.DISPOSITION` in 0.4.10 self.checkFile() @@ -599,7 +599,7 @@ class SimpleHoster(Hoster): pass self.logDebug("File name: %s" % self.pyfile.name, - "File size: %s" % (self.pyfile.size if self.pyfile.size > 0 else "Unknown")) + "File size: %s byte" % self.pyfile.size if self.pyfile.size > 0 else "File size: Unknown") def checkInfo(self): -- cgit v1.2.3