diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-13 15:56:57 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-13 15:56:57 +0100 |
commit | acc46fc3497a66a427b795b4a22c6e71d69185a1 (patch) | |
tree | 2d315b838a76435fc456b972c99c28d1732b2f70 /pyload/plugin/hoster/PremiumTo.py | |
parent | Code fixes (diff) | |
download | pyload-acc46fc3497a66a427b795b4a22c6e71d69185a1.tar.xz |
Update
Diffstat (limited to 'pyload/plugin/hoster/PremiumTo.py')
-rw-r--r-- | pyload/plugin/hoster/PremiumTo.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/pyload/plugin/hoster/PremiumTo.py b/pyload/plugin/hoster/PremiumTo.py new file mode 100644 index 000000000..4591ec7bc --- /dev/null +++ b/pyload/plugin/hoster/PremiumTo.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +from __future__ import with_statement + +from os import remove +from os.path import exists +from urllib import quote + +from pyload.plugin.Hoster import Hoster +from pyload.utils import fs_encode + + +class PremiumTo(Hoster): + __name = "PremiumTo" + __type = "hoster" + __version = "0.11" + + __pattern = r'https?://(?:www\.)?premium\.to/.+' + + __description = """Premium.to hoster plugin""" + __license = "GPLv3" + __authors = [("RaNaN", "RaNaN@pyload.org"), + ("zoidberg", "zoidberg@mujmail.cz"), + ("stickell", "l.stickell@yahoo.it")] + + + def setup(self): + self.resumeDownload = True + self.chunkLimit = 1 + + + def process(self, pyfile): + if not self.account: + self.logError(_("Please enter your %s account or deactivate this plugin") % "premium.to") + self.fail(_("No premium.to account provided")) + + self.logDebug("Old URL: %s" % pyfile.url) + + tra = self.getTraffic() + + #raise timeout to 2min + self.req.setOption("timeout", 120) + + self.download("http://premium.to/api/getfile.php", + get={'username': self.account.username, + 'password': self.account.password, + 'link' : quote(pyfile.url, "")}, + disposition=True) + + check = self.checkDownload({"nopremium": "No premium account available"}) + + if check == "nopremium": + self.retry(60, 5 * 60, "No premium account available") + + err = '' + if self.req.http.code == '420': + # Custom error code send - fail + lastDownload = fs_encode(self.lastDownload) + + if exists(lastDownload): + with open(lastDownload, "rb") as f: + err = f.read(256).strip() + remove(lastDownload) + else: + err = _('File does not exist') + + trb = self.getTraffic() + self.logInfo(_("Filesize: %d, Traffic used %d, traffic left %d") % (pyfile.size, tra - trb, trb)) + + if err: + self.fail(err) + + + def getTraffic(self): + try: + api_r = self.load("http://premium.to/api/straffic.php", + get={'username': self.account.username, 'password': self.account.password}) + traffic = sum(map(int, api_r.split(';'))) + except Exception: + traffic = 0 + return traffic |