summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-18 19:19:51 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-07-18 19:19:51 +0200
commitce3788f41d400e486c13126891641ad45740020c (patch)
treea991c0111a118193ec1fd7134683c027c1e8797b
parentNo more need to use the req argument when call load method (diff)
downloadpyload-ce3788f41d400e486c13126891641ad45740020c.tar.xz
Reorder some functions
-rw-r--r--module/plugins/internal/Hoster.py40
-rw-r--r--module/plugins/internal/Plugin.py26
-rw-r--r--module/plugins/internal/SimpleHoster.py70
3 files changed, 68 insertions, 68 deletions
diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py
index 722fae2e0..9a9e61e46 100644
--- a/module/plugins/internal/Hoster.py
+++ b/module/plugins/internal/Hoster.py
@@ -6,25 +6,47 @@ import inspect
import os
import random
import time
+import urllib
import urlparse
if os.name != "nt":
import grp
import pwd
-from module.plugins.internal.Plugin import Plugin, Abort, Fail, Reconnect, Retry, Skip, parse_html_form
+from module.plugins.internal.Plugin import (Plugin, Abort, Fail, Reconnect, Retry, Skip
+ chunks, replace_patterns, seconds_to_midnight,
+ set_cookies, parse_html_form, parse_html_tag_attr_value,
+ timestamp)
from module.utils import fs_decode, fs_encode, save_join as fs_join
-def get_info(urls):
+#@TODO: Remove in 0.4.10
+def parse_fileInfo(klass, url="", html=""):
+ info = klass.get_info(url, html)
+ return info['name'], info['size'], info['status'], info['url']
+
+
+#@TODO: Remove in 0.4.10
+def getInfo(urls):
# result = [ .. (name, size, status, url) .. ]
pass
+#@TODO: Remove in 0.4.10
+def create_getInfo(klass):
+ def get_info(urls):
+ for url in urls:
+ if hasattr(klass, "URL_REPLACEMENTS"):
+ url = replace_patterns(url, klass.URL_REPLACEMENTS)
+ yield parse_fileInfo(klass, url)
+
+ return get_info
+
+
class Hoster(Plugin):
__name__ = "Hoster"
__type__ = "hoster"
- __version__ = "0.04"
+ __version__ = "0.05"
__pattern__ = r'^unmatchable$'
__config__ = [] #: [("name", "type", "desc", "default")]
@@ -111,6 +133,18 @@ class Hoster(Plugin):
self.init()
+ @classmethod
+ def get_info(cls, url="", html=""):
+ url = urllib.unquote(url)
+ url_p = urlparse.urlparse(url)
+ return {'name' : (url_p.path.split('/')[-1]
+ or url_p.query.split('=', 1)[::-1][0].split('&', 1)[0]
+ or url_p.netloc.split('.', 1)[0]),
+ 'size' : 0,
+ 'status': 3 if url else 8,
+ 'url' : url}
+
+
def init(self):
"""
Initialize the plugin (in addition to `__init__`)
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py
index 01294ea92..d1b8bb1cf 100644
--- a/module/plugins/internal/Plugin.py
+++ b/module/plugins/internal/Plugin.py
@@ -11,6 +11,29 @@ from module.plugins.Plugin import Abort, Fail, Reconnect, Retry, SkipDownload as
from module.utils import fs_encode, fs_decode, html_unescape, save_join as fs_join
+#@TODO: Move to utils in 0.4.10
+def timestamp():
+ return int(time.time() * 1000)
+
+
+def seconds_to_midnight(gmt=0):
+ now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt)
+
+ if now.hour is 0 and now.minute < 10:
+ midnight = now
+ else:
+ midnight = now + datetime.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 datetime.timedelta.total_seconds
+ res = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6
+
+ return int(res)
+
+
def replace_patterns(string, ruleslist):
for r in ruleslist:
rf, rt = r
@@ -67,6 +90,7 @@ def parse_html_form(attr_str, html, input_names={}):
return {}, None #: no matching form found
+#@TODO: Move to utils in 0.4.10
def chunks(iterable, size):
it = iter(iterable)
item = list(islice(it, size))
@@ -78,7 +102,7 @@ def chunks(iterable, size):
class Plugin(object):
__name__ = "Plugin"
__type__ = "hoster"
- __version__ = "0.12"
+ __version__ = "0.13"
__pattern__ = r'^unmatchable$'
__config__ = [] #: [("name", "type", "desc", "default")]
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 0e4b94534..772e6ea2f 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -13,70 +13,19 @@ import urlparse
from module.PyFile import statusMap as _statusMap
from module.network.HTTPRequest import BadHeader
from module.network.RequestFactory import getURL
-from module.plugins.internal.Hoster import Hoster
+from module.plugins.internal.Hoster import Hoster, parse_fileInfo, create_getInfo
from module.plugins.internal.Plugin import Fail, Retry, replace_patterns, set_cookies
-from module.utils import fixup, fs_encode, parseFileSize
+from module.utils import fixup, fs_encode, parseFileSize as parse_size
#@TODO: Adapt and move to PyFile in 0.4.10
statusMap = dict((v, k) for k, v in _statusMap.iteritems())
-#@TODO: Remove in 0.4.10
-def parseFileInfo(plugin, url="", html=""):
- if hasattr(plugin, "getInfo"):
- info = plugin.get_info(url, html)
- res = info['name'], info['size'], info['status'], info['url']
- else:
- url = urllib.unquote(url)
- url_p = urlparse.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
-
-
-#@TODO: Remove in 0.4.10
-def create_getInfo(plugin):
- def get_info(urls):
- for url in urls:
- if hasattr(plugin, "URL_REPLACEMENTS"):
- url = replace_patterns(url, plugin.URL_REPLACEMENTS)
- yield parseFileInfo(plugin, url)
-
- return getInfo
-
-
-def timestamp():
- return int(time.time() * 1000)
-
-
-def seconds_to_midnight(gmt=0):
- now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt)
-
- if now.hour is 0 and now.minute < 10:
- midnight = now
- else:
- midnight = now + datetime.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 datetime.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__ = "1.70"
+ __version__ = "1.71"
__pattern__ = r'^unmatchable$'
__config__ = [("use_premium", "bool", "Use premium account if available" , True),
@@ -166,14 +115,7 @@ class SimpleHoster(Hoster):
@classmethod
def api_info(cls, url):
- url = urllib.unquote(url)
- url_p = urlparse.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}
+ return super(SimpleHoster, self).get_info(url)
@classmethod
@@ -240,11 +182,11 @@ class SimpleHoster(Hoster):
if 'S' in info['pattern']:
size = replace_patterns(info['pattern']['S'] + info['pattern']['U'] if 'U' in info['pattern'] else info['pattern']['S'],
cls.SIZE_REPLACEMENTS)
- info['size'] = parseFileSize(size)
+ info['size'] = parse_size(size)
elif isinstance(info['size'], basestring):
unit = info['units'] if 'units' in info else None
- info['size'] = parseFileSize(info['size'], unit)
+ info['size'] = parse_size(info['size'], unit)
if 'H' in info['pattern']:
hashtype = info['pattern']['T'] if 'T' in info['pattern'] else "hash"