diff options
author | Stefano <l.stickell@yahoo.it> | 2014-05-04 15:47:11 +0200 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2014-05-04 15:47:11 +0200 |
commit | dd57d1155d5dd2a2dc36578b37a7ab4e49d0cec9 (patch) | |
tree | 22858f5b16cd9060d1bea1a50fa451b03f0f7423 /module/plugins/hoster/LinksnappyCom.py | |
parent | File4safe premium (diff) | |
download | pyload-dd57d1155d5dd2a2dc36578b37a7ab4e49d0cec9.tar.xz |
New multihoster: Linksnappy
Diffstat (limited to 'module/plugins/hoster/LinksnappyCom.py')
-rw-r--r-- | module/plugins/hoster/LinksnappyCom.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/module/plugins/hoster/LinksnappyCom.py b/module/plugins/hoster/LinksnappyCom.py new file mode 100644 index 000000000..a2d07d9d8 --- /dev/null +++ b/module/plugins/hoster/LinksnappyCom.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +import re +from urlparse import urlsplit + +from module.plugins.Hoster import Hoster +from module.common.json_layer import json_loads, json_dumps + + +class LinksnappyCom(Hoster): + __name__ = "LinksnappyCom" + __version__ = "0.01" + __type__ = "hoster" + __pattern__ = r'https?://(?:[^/]*\.)?linksnappy\.com' + __description__ = """Linksnappy.com hoster plugin""" + __author_name__ = "stickell" + __author_mail__ = "l.stickell@yahoo.it" + + def setup(self): + 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 = urlsplit(pyfile.url).netloc + host = re.search(r'[\w-]+\.\w+$', host).group(0) + 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) + + j = json_loads(r)['links'][0] + + if j['error']: + self.logError('Error converting the link: %s' % j['error']) + self.fail('Error converting the link') + + pyfile.name = j['filename'] + new_url = j['generated'] + + if new_url != pyfile.url: + self.logDebug("New URL: " + new_url) + + self.download(new_url, disposition=True) |