From a64c0d41a27da58dc004f97bc934c8b3018a1de9 Mon Sep 17 00:00:00 2001 From: stickell Date: Fri, 12 Sep 2014 17:54:39 +0200 Subject: [Premium4Me] Renamed to PremiumTo + partial rewrite + special traffic support --- module/plugins/hoster/PremiumTo.py | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 module/plugins/hoster/PremiumTo.py (limited to 'module/plugins/hoster/PremiumTo.py') diff --git a/module/plugins/hoster/PremiumTo.py b/module/plugins/hoster/PremiumTo.py new file mode 100644 index 000000000..3ab7e34ac --- /dev/null +++ b/module/plugins/hoster/PremiumTo.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +from os import remove +from os.path import exists +from urllib import quote + +from module.plugins.Hoster import Hoster +from module.utils import fs_encode + + +class PremiumTo(Hoster): + __name__ = "PremiumTo" + __type__ = "hoster" + __version__ = "0.09" + __pattern__ = r'https?://(?:www\.)?premium.to/.*' + __description__ = """Premium.to hoster plugin""" + __author_name__ = ("RaNaN", "zoidberg", "stickell") + __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz", "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): + f = open(lastDownload, "rb") + err = f.read(256).strip() + f.close() + 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: + traffic = 0 + return traffic -- cgit v1.2.3