diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-17 20:02:20 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-17 20:02:20 +0100 |
commit | 57300575fa97107d172e0c9909b244c8c8ae6c12 (patch) | |
tree | 86dcbc38175e55c3ac077ff9a894fe74bb3d54ea /module/plugins/hoster/LinksnappyCom.py | |
parent | [FilerNet] Typo (diff) | |
download | pyload-57300575fa97107d172e0c9909b244c8c8ae6c12.tar.xz |
Extend SimpleHoster in multi-hoster plugins
Diffstat (limited to 'module/plugins/hoster/LinksnappyCom.py')
-rw-r--r-- | module/plugins/hoster/LinksnappyCom.py | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/module/plugins/hoster/LinksnappyCom.py b/module/plugins/hoster/LinksnappyCom.py index b8694e141..1f97fab31 100644 --- a/module/plugins/hoster/LinksnappyCom.py +++ b/module/plugins/hoster/LinksnappyCom.py @@ -5,10 +5,10 @@ import re from urlparse import urlsplit from module.common.json_layer import json_loads, json_dumps -from module.plugins.Hoster import Hoster +from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo -class LinksnappyCom(Hoster): +class LinksnappyCom(SimpleHoster): __name__ = "LinksnappyCom" __type__ = "hoster" __version__ = "0.02" @@ -24,48 +24,42 @@ class LinksnappyCom(Hoster): def setup(self): - self.chunkLimit = -1 + self.chunkLimit = -1 self.resumeDownload = True - def process(self, pyfile): - if re.match(self.__pattern__, pyfile.url): - new_url = pyfile.url - elif not self.account: - self.logError(_("Please enter your %s account or deactivate this plugin") % "Linksnappy.com") - self.fail(_("No Linksnappy.com account provided")) - else: - self.logDebug("Old URL: %s" % pyfile.url) - host = self._get_host(pyfile.url) - json_params = json_dumps({'link': pyfile.url, - 'type': host, - 'username': self.user, - 'password': self.account.getAccountData(self.user)['password']}) - r = self.load('http://gen.linksnappy.com/genAPI.php', - post={'genLinks': json_params}) - self.logDebug("JSON data: " + r) + def handleMulti(self): + host = self._get_host(self.pyfile.url) + json_params = json_dumps({'link': self.pyfile.url, + 'type': host, + 'username': self.user, + 'password': self.account.getAccountData(self.user)['password']}) + r = self.load('http://gen.linksnappy.com/genAPI.php', + post={'genLinks': json_params}) + self.logDebug("JSON data: " + r) - j = json_loads(r)['links'][0] + j = json_loads(r)['links'][0] - if j['error']: - msg = _("Error converting the link") - self.logError(msg, j['error']) - self.fail(msg) + if j['error']: + msg = _("Error converting the link") + self.logError(msg, j['error']) + self.fail(msg) - pyfile.name = j['filename'] - new_url = j['generated'] + self.pyfile.name = j['filename'] + self.link = j['generated'] - if host in self.SINGLE_CHUNK_HOSTERS: - self.chunkLimit = 1 - else: - self.setup() + if host in self.SINGLE_CHUNK_HOSTERS: + self.chunkLimit = 1 + else: + self.setup() - if new_url != pyfile.url: - self.logDebug("New URL: " + new_url) + if self.link != self.pyfile.url: + self.logDebug("New URL: " + self.link) - self.download(new_url, disposition=True) + def checkFile(self): check = self.checkDownload({"html302": "<title>302 Found</title>"}) + if check == "html302": self.retry(wait_time=5, reason=_("Linksnappy returns only HTML data")) @@ -74,3 +68,6 @@ class LinksnappyCom(Hoster): def _get_host(url): host = urlsplit(url).netloc return re.search(r'[\w-]+\.\w+$', host).group(0) + + +getInfo = create_getInfo(LinksnappyCom) |