summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-10-10 12:31:24 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-10-10 12:31:24 +0200
commit184f678213f493ac9441a026db998f78c2989c5c (patch)
tree6a587aa7d18ae3e45c519de61633a4e2487cece7
parentSpare code cosmetics (diff)
downloadpyload-184f678213f493ac9441a026db998f78c2989c5c.tar.xz
[Base] New methods: init_base and setup_base
[Hoster] Improve download method
-rw-r--r--module/plugins/internal/Base.py31
-rw-r--r--module/plugins/internal/Crypter.py23
-rw-r--r--module/plugins/internal/Hoster.py50
3 files changed, 60 insertions, 44 deletions
diff --git a/module/plugins/internal/Base.py b/module/plugins/internal/Base.py
index 052fc228f..c2f3a6e98 100644
--- a/module/plugins/internal/Base.py
+++ b/module/plugins/internal/Base.py
@@ -46,7 +46,7 @@ def check_abort(fn):
class Base(Plugin):
__name__ = "Base"
__type__ = "base"
- __version__ = "0.08"
+ __version__ = "0.10"
__status__ = "testing"
__pattern__ = r'^unmatchable$'
@@ -63,6 +63,9 @@ class Base(Plugin):
def __init__(self, pyfile):
self._init(pyfile.m.core)
+ #:
+ self.premium = None
+
#: Engage wan reconnection
self.wantReconnect = False #@TODO: Change to `want_reconnect` in 0.4.10
@@ -94,6 +97,9 @@ class Base(Plugin):
#: Dict of the amount of retries already made
self.retries = {}
+ self.init_base()
+ self.init()
+
def _log(self, level, plugintype, pluginname, messages):
log = getattr(self.pyload.log, level)
@@ -123,6 +129,10 @@ class Base(Plugin):
return info
+ def init_base(self):
+ pass
+
+
def init(self):
"""
Initialize the plugin (in addition to `__init__`)
@@ -130,6 +140,10 @@ class Base(Plugin):
pass
+ def setup_base(self):
+ pass
+
+
def setup(self):
"""
Setup for enviroment and other things, called before downloading (possibly more than one time)
@@ -155,16 +169,13 @@ class Base(Plugin):
pass
if self.account:
- self.req = self.pyload.requestFactory.getRequest(self.__name__, self.account.user)
- self.chunk_limit = -1 #: -1 for unlimited
- self.resume_download = True
- self.premium = self.account.info['data']['premium'] #: Don't use `self.account.premium` to avoid one unnecessary get_info call
+ self.req = self.pyload.requestFactory.getRequest(self.__name__, self.account.user)
+ self.premium = self.account.info['data']['premium'] #@NOTE: Avoid one unnecessary get_info call by `self.account.premium` here
else:
- self.req = self.pyload.requestFactory.getRequest(self.__name__)
- self.chunk_limit = 1
- self.resume_download = False
- self.premium = False
+ self.req = self.pyload.requestFactory.getRequest(self.__name__)
+ self.premium = False
+ self.setup_base()
self.setup()
@@ -305,7 +316,7 @@ class Base(Plugin):
if msg:
self.pyfile.error = msg
else:
- msg = self.pyfile.error or (self.info['error'] if 'error' in self.info else self.pyfile.getStatusName())
+ msg = self.pyfile.error or self.info.get('error') or self.pyfile.getStatusName()
raise Fail(encode(msg)) #@TODO: Remove `encode` in 0.4.10
diff --git a/module/plugins/internal/Crypter.py b/module/plugins/internal/Crypter.py
index db13e445c..20322bb33 100644
--- a/module/plugins/internal/Crypter.py
+++ b/module/plugins/internal/Crypter.py
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
-from module.plugins.internal.Base import Base, parse_name
+from module.plugins.internal.Base import Base, check_abort, create_getInfo, parse_fileInfo
+from module.plugins.internal.Plugin import parse_name
from module.utils import save_path as safe_filename
class Crypter(Base):
__name__ = "Crypter"
__type__ = "crypter"
- __version__ = "0.12"
+ __version__ = "0.13"
__status__ = "testing"
__pattern__ = r'^unmatchable$'
@@ -20,22 +21,12 @@ class Crypter(Base):
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- def __init__(self, *args, **kwargs):
- super(Crypter, self).__init__(*args, **kwargs)
+ def init_base(self):
+ self.packages = [] #: Put all packages here. It's a list of tuples like: ( name, [list of links], folder )
+ self.urls = [] #: List of urls, pyLoad will generate packagenames
- #: Put all packages here. It's a list of tuples like: ( name, [list of links], folder )
- self.packages = []
-
- #: List of urls, pyLoad will generate packagenames
- self.urls = []
-
- self._setup()
- self.init()
-
-
- def _setup(self):
- super(Crypter, self)._setup()
+ def setup_base(self):
self.packages = []
self.urls = []
diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py
index c65946413..d81154554 100644
--- a/module/plugins/internal/Hoster.py
+++ b/module/plugins/internal/Hoster.py
@@ -5,7 +5,7 @@ from __future__ import with_statement
import os
import re
-from module.plugins.internal.Base import Base, check_abort, create_getInfo, getInfo, parse_fileInfo
+from module.plugins.internal.Base import Base, check_abort, create_getInfo, parse_fileInfo
from module.plugins.internal.Plugin import Fail, Retry, encode, exists, fixurl, parse_name
from module.utils import fs_decode, fs_encode, save_join as fs_join, save_path as safe_filename
@@ -13,7 +13,7 @@ from module.utils import fs_decode, fs_encode, save_join as fs_join, save_path a
class Hoster(Base):
__name__ = "Hoster"
__type__ = "hoster"
- __version__ = "0.36"
+ __version__ = "0.37"
__status__ = "testing"
__pattern__ = r'^unmatchable$'
@@ -26,11 +26,15 @@ class Hoster(Base):
__authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
- def __init__(self, *args, **kwargs):
- super(Hoster, self).__init__(*args, **kwargs)
-
+ def init_base(self):
#: Enable simultaneous processing of multiple downloads
- self.limitDL = 0 #@TODO: Change to `limit_dl` in 0.4.10
+ self.limitDL = 0 #@TODO: Change to `limit_dl` in 0.4.10
+
+ #:
+ self.chunk_limit = None
+
+ #:
+ self.resume_download = False
#: Location where the last call to download was saved
self.last_download = None
@@ -41,17 +45,19 @@ class Hoster(Base):
#: Restart flag
self.rst_free = False #@TODO: Recheck in 0.4.10
- self._setup()
- self.init()
-
-
- def _setup(self):
- super(Hoster, self)._setup()
+ def setup_base(self):
self.last_download = None
self.last_check = None
self.rst_free = False
+ if self.account:
+ self.chunk_limit = -1 #: -1 for unlimited
+ self.resume_download = True
+ else:
+ self.chunk_limit = 1
+ self.resume_download = False
+
def load_account(self):
if self.rst_free:
@@ -76,7 +82,8 @@ class Hoster(Base):
self.pyfile.setStatus("starting")
try:
- self.log_debug("PROCESS URL " + self.pyfile.url, "PLUGIN VERSION %s" % self.__version__) #@TODO: Remove in 0.4.10
+ self.log_debug("PROCESS URL " + self.pyfile.url,
+ "PLUGIN VERSION %s" % self.__version__) #@TODO: Remove in 0.4.10
self.process(self.pyfile)
self.check_abort()
@@ -94,7 +101,7 @@ class Hoster(Base):
@check_abort
- def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=True):
+ def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=True, resume=None, chunks=None):
"""
Downloads the content at url to download folder
@@ -141,10 +148,16 @@ class Hoster(Base):
self.check_abort()
+ chunks = min(self.pyload.config.get("download", "chunks"), chunks or self.chunk_limit or -1)
+
+ if resume is None:
+ resume = self.resume_download
+
try:
- newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies,
- chunks=self.get_chunk_count(), resume=self.resume_download,
- progressNotify=self.pyfile.setProgress, disposition=disposition)
+ newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref,
+ cookies=cookies, chunks=chunks, resume=resume,
+ progressNotify=self.pyfile.setProgress,
+ disposition=disposition)
finally:
self.pyfile.size = self.req.size
@@ -159,7 +172,8 @@ class Hoster(Base):
os.rename(oldname_enc, newname_enc)
except OSError, e:
- self.log_warning(_("Error renaming `%s` to `%s`") % (newname, finalname), e)
+ self.log_warning(_("Error renaming `%s` to `%s`")
+ % (newname, finalname), e)
finalname = newname
self.log_info(_("`%s` saved as `%s`") % (self.pyfile.name, finalname))