From 1bb6ebf544b43cacf7c0755c5a8608b79b95e2d6 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Jan 2012 20:11:16 +0100 Subject: MultiHoster plugin type, some fixes, new documentation structure --- module/plugins/MultiHoster.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 module/plugins/MultiHoster.py (limited to 'module/plugins/MultiHoster.py') diff --git a/module/plugins/MultiHoster.py b/module/plugins/MultiHoster.py new file mode 100644 index 000000000..f7e560c10 --- /dev/null +++ b/module/plugins/MultiHoster.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from time import time + +from Account import Account + +#noinspection PyUnresolvedReferences +class MultiHoster(Account): + """ + Base class for MultiHoster services. + This is also an Account instance so you should see :class:`Account` and overwrite necessary methods. + Multihoster becomes only active when an Account was entered and the MultiHoster hook was activated. + You need to overwrite `loadHosterList` and a corresponding :class:`Hoster` plugin with the same name should + be available to make your service working. + """ + + #: List of hoster names that will be replaced so pyLoad will recognize them: (orig_name, pyload_name) + replacements = [("freakshare.net", "freakshare.com")] + + #: Load new hoster list every x seconds + hoster_timeout = 300 + + def __init__(self, *args, **kwargs): + + # Hoster list + self.hoster = [] + # Timestamp + self.ts = 0 + + Account.__init__(*args, **kwargs) + + def loadHosterList(self, req): + """Load list of supported hoster + + :return: List of domain names + """ + raise NotImplementedError + + def getHosterList(self, force=False): + if self.ts + self.hoster_timeout < time() or force: + req = self.getAccountRequest() + try: + self.hoster = self.loadHosterList(req) + except Exception, e: + self.logError(e) + return [] + finally: + req.close() + + for rep in self.replacements: + if rep[0] in self.hosters: + self.hosters.remove(rep[0]) + if rep[1] not in self.hosters: + self.hosters.append(rep[1]) + + self.ts = time() + + return self.hosters \ No newline at end of file -- cgit v1.2.3 From 6eaa7bb25e2254c80c43fe46166142d590e86c64 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 7 Jan 2012 23:58:28 +0100 Subject: some cleanups --- module/plugins/MultiHoster.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'module/plugins/MultiHoster.py') diff --git a/module/plugins/MultiHoster.py b/module/plugins/MultiHoster.py index f7e560c10..047b9155e 100644 --- a/module/plugins/MultiHoster.py +++ b/module/plugins/MultiHoster.py @@ -2,8 +2,14 @@ from time import time +from module.utils import remove_chars + from Account import Account +def normalize(domain): + """ Normalize domain/plugin name, so they are comparable """ + return remove_chars(domain.strip().lower(), "-.") + #noinspection PyUnresolvedReferences class MultiHoster(Account): """ @@ -36,6 +42,15 @@ class MultiHoster(Account): """ raise NotImplementedError + + def isHosterUsuable(self, domain): + """ Determine before downloading if hoster should be used. + + :param domain: domain name + :return: True to let the MultiHoster download, False to fallback to default plugin + """ + return True + def getHosterList(self, force=False): if self.ts + self.hoster_timeout < time() or force: req = self.getAccountRequest() -- cgit v1.2.3 From bac28b7740aae772636d8b90e291d9c17dfd59a7 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 8 Jan 2012 14:44:59 +0100 Subject: new MultiHoster hook --- module/plugins/MultiHoster.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'module/plugins/MultiHoster.py') diff --git a/module/plugins/MultiHoster.py b/module/plugins/MultiHoster.py index 047b9155e..abbc14466 100644 --- a/module/plugins/MultiHoster.py +++ b/module/plugins/MultiHoster.py @@ -33,7 +33,7 @@ class MultiHoster(Account): # Timestamp self.ts = 0 - Account.__init__(*args, **kwargs) + Account.__init__(self, *args, **kwargs) def loadHosterList(self, req): """Load list of supported hoster @@ -63,11 +63,11 @@ class MultiHoster(Account): req.close() for rep in self.replacements: - if rep[0] in self.hosters: - self.hosters.remove(rep[0]) - if rep[1] not in self.hosters: - self.hosters.append(rep[1]) + if rep[0] in self.hoster: + self.hoster.remove(rep[0]) + if rep[1] not in self.hoster: + self.hoster.append(rep[1]) self.ts = time() - return self.hosters \ No newline at end of file + return self.hoster \ No newline at end of file -- cgit v1.2.3 From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- module/plugins/MultiHoster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/MultiHoster.py') diff --git a/module/plugins/MultiHoster.py b/module/plugins/MultiHoster.py index abbc14466..1936478b4 100644 --- a/module/plugins/MultiHoster.py +++ b/module/plugins/MultiHoster.py @@ -15,7 +15,7 @@ class MultiHoster(Account): """ Base class for MultiHoster services. This is also an Account instance so you should see :class:`Account` and overwrite necessary methods. - Multihoster becomes only active when an Account was entered and the MultiHoster hook was activated. + Multihoster becomes only active when an Account was entered and the MultiHoster addon was activated. You need to overwrite `loadHosterList` and a corresponding :class:`Hoster` plugin with the same name should be available to make your service working. """ -- cgit v1.2.3