summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/accounts/NoPremiumPl.py81
-rw-r--r--module/plugins/hooks/NoPremiumPl.py31
-rw-r--r--module/plugins/hoster/NoPremiumPl.py104
3 files changed, 216 insertions, 0 deletions
diff --git a/module/plugins/accounts/NoPremiumPl.py b/module/plugins/accounts/NoPremiumPl.py
new file mode 100644
index 000000000..f2223b7d9
--- /dev/null
+++ b/module/plugins/accounts/NoPremiumPl.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+
+from datetime import datetime
+import hashlib
+
+from module.plugins.Account import Account
+from time import mktime
+from module.common.json_layer import json_loads as loads
+
+
+class NoPremiumPl(Account):
+ __name__ = "NoPremiumPl"
+ __version__ = "0.01"
+ __type__ = "account"
+ __description__ = "NoPremium.pl account plugin"
+ __license__ = "GPLv3"
+ __authors__ = [("goddie", "dev@nopremium.pl")]
+
+ _api_url = "http://crypt.nopremium.pl"
+
+ _api_query = {
+ "site": "nopremium",
+ "username": "",
+ "password": "",
+ "output": "json",
+ "loc": "1",
+ "info": "1"
+ }
+
+ _req = None
+ _usr = None
+ _pwd = None
+
+ def loadAccountInfo(self, name, req):
+ self._req = req
+ try:
+ result = loads(self.runAuthQuery())
+ except:
+ # todo: return or let it be thrown?
+ return
+
+ premium = False
+ valid_untill = -1
+
+ if "expire" in result.keys() and result["expire"]:
+ premium = True
+ valid_untill = mktime(datetime.fromtimestamp(int(result["expire"])).timetuple())
+ traffic_left = result["balance"] * 1024
+
+ return ({
+ "validuntil": valid_untill,
+ "trafficleft": traffic_left,
+ "premium": premium
+ })
+
+ def login(self, user, data, req):
+ self._usr = user
+ self._pwd = hashlib.sha1(hashlib.md5(data["password"]).hexdigest()).hexdigest()
+ self._req = req
+
+ try:
+ response = loads(self.runAuthQuery())
+ except:
+ self.wrongPassword()
+
+ if "errno" in response.keys():
+ self.wrongPassword()
+ data['usr'] = self._usr
+ data['pwd'] = self._pwd
+
+ def createAuthQuery(self):
+ query = self._api_query
+ query["username"] = self._usr
+ query["password"] = self._pwd
+
+ return query
+
+ def runAuthQuery(self):
+ data = self._req.load(self._api_url, post=self.createAuthQuery())
+
+ return data \ No newline at end of file
diff --git a/module/plugins/hooks/NoPremiumPl.py b/module/plugins/hooks/NoPremiumPl.py
new file mode 100644
index 000000000..f60cb3dd6
--- /dev/null
+++ b/module/plugins/hooks/NoPremiumPl.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from module.plugins.internal.MultiHoster import MultiHoster
+from module.network.RequestFactory import getURL
+from module.common.json_layer import json_loads as loads
+
+
+class NoPremiumPl(MultiHoster):
+ __name__ = "NoPremiumPl"
+ __version__ = "0.01"
+ __type__ = "hook"
+
+ __config__ = [("activated", "bool", "Activated", "False"),
+ ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"),
+ ("hosterList", "str", "Hoster list (comma separated)", ""),
+ ("unloadFailing", "bool", "Try standard download if download fails", "False"),
+ ("interval", "int", "Reload supported hosts interval in hours (0 to disable)", "24")]
+
+ __description__ = "NoPremium.pl hook"
+ __license__ = "GPLv3"
+ __authors__ = [("goddie", "dev@nopremium.pl")]
+
+ def getHoster(self):
+ hostings = loads(getURL("https://www.nopremium.pl/clipboard.php?json=3").strip())
+
+ return [domain for row in hostings for domain in row["domains"] if row["sdownload"] == "0"]
+
+ def getHosterCached(self):
+ return self.getHoster()
+
+
diff --git a/module/plugins/hoster/NoPremiumPl.py b/module/plugins/hoster/NoPremiumPl.py
new file mode 100644
index 000000000..f4f7ba56a
--- /dev/null
+++ b/module/plugins/hoster/NoPremiumPl.py
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+
+from module.plugins.internal.SimpleHoster import SimpleHoster
+from module.common.json_layer import json_loads as loads
+
+
+class NoPremiumPl(SimpleHoster):
+ __name__ = "NoPremiumPl"
+ __version__ = "0.01"
+ __type__ = "hoster"
+
+ __pattern__ = r"https?://direct\.nopremium\.pl.*"
+ __description__ = "NoPremium.pl hoster plugin"
+ __license__ = "GPLv3"
+ __authors__ = [("goddie", "dev@nopremium.pl")]
+
+ _api_url = "http://crypt.nopremium.pl"
+
+ _api_query = {"site": "nopremium",
+ "output": "json",
+ "username": "",
+ "password": "",
+ "url": ""}
+
+ _error_codes = {
+ 0: "[%s] Incorrect login credentials",
+ 1: "[%s] Not enough transfer to download - top-up your account",
+ 2: "[%s] Incorrect / dead link",
+ 3: "[%s] Error connecting to hosting, try again later",
+ 9: "[%s] Premium account has expired",
+ 15: "[%s] Hosting no longer supported",
+ 80: "[%s] Too many incorrect login attempts, account blocked for 24h"
+ }
+
+ _usr = False
+ _pwd = False
+
+ def setup(self):
+ self.resumeDownload = True
+ self.multiDL = True
+
+ def get_username_password(self):
+ if not self.account:
+ self.fail(_("Please enter your %s account or deactivate this plugin") % "NoPremium.pl")
+ else:
+ self._usr = self.account.getAccountData(self.user).get('usr')
+ self._pwd = self.account.getAccountData(self.user).get('pwd')
+
+ def runFileQuery(self, url, mode=None):
+ query = self._api_query.copy()
+ query["username"] = self._usr
+ query["password"] = self._pwd
+ query["url"] = url
+
+ if mode == "fileinfo":
+ query['check'] = 2
+ query['loc'] = 1
+ self.logDebug(query)
+
+ return self.load(self._api_url, post=query)
+
+ def process(self, pyfile):
+ self.get_username_password()
+ try:
+ data = self.runFileQuery(pyfile.url, 'fileinfo')
+ except Exception:
+ self.logDebug("runFileQuery error")
+ self.tempOffline()
+
+ try:
+ parsed = loads(data)
+ except Exception:
+ self.logDebug("loads error")
+ self.tempOffline()
+
+ self.logDebug(parsed)
+
+ if "errno" in parsed.keys():
+ if parsed["errno"] in self._error_codes:
+ # error code in known
+ self.fail(self._error_codes[parsed["errno"]] % self.__name__)
+ else:
+ # error code isn't yet added to plugin
+ self.fail(
+ parsed["errstring"]
+ or "Unknown error (code: %s)" % parsed["errno"]
+ )
+
+ if "sdownload" in parsed:
+ if parsed["sdownload"] == "1":
+ self.fail(
+ "Download from %s is possible only using NoPremium.pl webiste \
+ directly. Update this plugin." % parsed["hosting"])
+
+ pyfile.name = parsed["filename"]
+ pyfile.size = parsed["filesize"]
+
+ try:
+ result_dl = self.runFileQuery(pyfile.url, 'filedownload')
+ except Exception:
+ self.logDebug("runFileQuery error #2")
+ self.tempOffline()
+
+ self.download(result_dl, disposition=True)