summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-21 18:23:33 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-11-21 18:23:33 +0100
commite08fb5d3361627ad866aed86be9597b32c8c50f9 (patch)
treed78fd1aabf6bbd1eec95ed34fa294f58f939d37a
parent[SimpleCrypter] Extend SimpleHoster (diff)
downloadpyload-e08fb5d3361627ad866aed86be9597b32c8c50f9.tar.xz
[SimpleHoster] Code cosmetics
-rw-r--r--module/plugins/Plugin.py2
-rw-r--r--module/plugins/internal/SimpleHoster.py39
2 files changed, 25 insertions, 16 deletions
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 55d93e357..550169034 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -16,7 +16,7 @@ from itertools import islice
from traceback import print_exc
from urlparse import urlparse
-from module.utils import fs_decode, fs_encode, html_unescape, save_join, save_path
+from module.utils import fs_decode, fs_encode, save_join, save_path
def chunks(iterable, size):
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 7ab562779..1de872261 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -7,12 +7,16 @@ from urlparse import urlparse
from pycurl import FOLLOWLOCATION
-from module.PyFile import statusMap
+from module.PyFile import statusMap as _statusMap
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, html_unescape, parseFileSize
+from module.utils import fixup, parseFileSize
+
+
+#@TODO: Adapt and move to PyFile in 0.4.10
+statusMap = {v: k for k, v in _statusMap.iteritems()}
#@TODO: Remove in 0.4.10 and redirect to self.error instead
@@ -21,7 +25,7 @@ def _error(self, reason, type):
type = "unknown"
msg = _("%s error") % type.strip().capitalize() if type else _("Error")
- msg += ": " + reason.strip() if reason else ""
+ msg += ": %s" % reason.strip() if reason else ""
msg += _(" | Plugin may be out of date")
raise Fail(msg)
@@ -89,11 +93,13 @@ def parseHtmlForm(attr_str, html, input_names=None):
return {}, None #: no matching form found
+#: Deprecated
def parseFileInfo(plugin, url="", html=""):
info = plugin.getInfo(url, html)
return info['name'], info['size'], info['status'], info['url']
+#@TODO: Remove in 0.4.10
def create_getInfo(plugin):
return lambda urls: list(plugin.parseInfo(urls))
@@ -120,7 +126,7 @@ def _getDirectLink(self, url):
class SimpleHoster(Hoster):
__name__ = "SimpleHoster"
__type__ = "hoster"
- __version__ = "0.56"
+ __version__ = "0.57"
__pattern__ = r'^unmatchable$'
@@ -279,12 +285,13 @@ class SimpleHoster(Hoster):
self.fail(_("No html retrieved"))
info = self.getInfo(pyfile.url, self.html)
- self._updateInfo(info)
+ premium_only = hasattr(self, 'PREMIUM_ONLY_PATTERN') and re.search(self.PREMIUM_ONLY_PATTERN, self.html)
+ self._updateInfo(info)
self.checkNameSize()
- premium_only = hasattr(self, 'PREMIUM_ONLY_PATTERN') and re.search(self.PREMIUM_ONLY_PATTERN, self.html)
- if not premium_only: #: Usually premium only pages doesn't show any file information
+ #: Usually premium only pages doesn't show any file information
+ if not premium_only:
self.checkStatus()
if self.premium and (not self.FORCE_CHECK_TRAFFIC or self.checkTrafficLeft()):
@@ -312,8 +319,9 @@ class SimpleHoster(Hoster):
self.tempOffline()
elif status is not 2:
- self.error(_("File status: %s") % filter(lambda key, val: val == status, statusMap.iteritems())[0],
- _("File info: %s") % self.info)
+ self.logDebug("File status: %s" % statusMap[status],
+ "File info: %s" % self.info)
+ self.error(_("No file info"))
def checkNameSize(self):
@@ -324,14 +332,15 @@ class SimpleHoster(Hoster):
if name and name != url:
self.pyfile.name = name
else:
- self.pyfile.name = self.info['name'] = urlparse(html_unescape(name)).path.split('/')[-1]
+ self.pyfile.name = name = self.info['name'] = urlparse(name).path.split('/')[-1]
if size > 0:
self.pyfile.size = size
else:
- self.logError(_("File size not found"))
+ size = "Unknown"
- self.logDebug("File name: %s" % self.pyfile.name, "File size: %s" % self.pyfile.size or _("Unknown"))
+ self.logDebug("File name: %s" % name,
+ "File size: %s" % size)
def checkInfo(self):
@@ -340,10 +349,10 @@ class SimpleHoster(Hoster):
self.checkStatus()
- def _updateInfo(self, info)
- self.logDebug(_("File info (previous): %s") % self.info)
+ def _updateInfo(self, info):
+ self.logDebug(_("File info (before update): %s") % self.info)
self.info.update(info)
- self.logDebug(_("File info (current): %s") % self.info)
+ self.logDebug(_("File info (after update): %s") % self.info)
def handleDirect(self):