summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-05 23:51:32 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-01-05 23:51:32 +0100
commit905eb08ba4db5eb50971dc4c0c1a1c3367d93885 (patch)
treeaa2b0a6f097a03f75bec3b45eb2904c46b9cf11a
parentMerge pull request #1015 from sahilshekhawat/stable (diff)
parentAdded multihoster smoozed.com (diff)
downloadpyload-905eb08ba4db5eb50971dc4c0c1a1c3367d93885.tar.xz
Merge pull request #1013 from smoozed/stable
New plugin: SmoozedCom
-rw-r--r--module/plugins/accounts/SmoozedCom.py55
-rw-r--r--module/plugins/hooks/SmoozedCom.py43
-rw-r--r--module/plugins/hoster/SmoozedCom.py70
3 files changed, 168 insertions, 0 deletions
diff --git a/module/plugins/accounts/SmoozedCom.py b/module/plugins/accounts/SmoozedCom.py
new file mode 100644
index 000000000..8157806c8
--- /dev/null
+++ b/module/plugins/accounts/SmoozedCom.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+from module.plugins.Account import Account
+
+from module.common.json_layer import json_loads
+
+from time import time
+
+import hashlib
+from beaker.crypto.pbkdf2 import PBKDF2
+
+
+
+class SmoozedCom(Account):
+ __name__ = "SmoozedCom"
+ __type__ = "account"
+ __version__ = "0.01"
+
+ __description__ = """Smoozed.com account plugin"""
+ __license__ = "GPLv3"
+ __authors__ = []
+
+
+ def loadAccountInfo(self, user, req):
+ # Get user data from premiumize.me
+ status = self.getAccountStatus(user, req)
+ self.logDebug(status)
+
+ # Parse account info
+ account_info = {"validuntil": float(status["data"]["user"]["user_premium"]),
+ "trafficleft": max(0, status["data"]["traffic"][1] - status["data"]["traffic"][0]),
+ "session_key": status["data"]["session_key"],
+ "hoster": [hoster["name"] for hoster in status["data"]["hoster"]]}
+
+ if account_info["validuntil"] < time():
+ account_info['premium'] = False
+ else:
+ account_info['premium'] = True
+
+ return account_info
+
+ def login(self, user, data, req):
+ # Get user data from premiumize.me
+ status = self.getAccountStatus(user, req)
+
+ # Check if user and password are valid
+ if status['state'] != 'ok':
+ self.wrongPassword()
+
+ def getAccountStatus(self, user, req):
+ salt = hashlib.sha256(self.accounts[user]['password']).hexdigest()
+ encrypted = PBKDF2(self.accounts[user]['password'], salt, iterations=1000).hexread(32)
+ answer = req.load('http://www2.smoozed.com/api/login?auth=%s&password=%s' % (
+ user, encrypted))
+ return json_loads(answer)
diff --git a/module/plugins/hooks/SmoozedCom.py b/module/plugins/hooks/SmoozedCom.py
new file mode 100644
index 000000000..0aff36c0f
--- /dev/null
+++ b/module/plugins/hooks/SmoozedCom.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+
+from module.plugins.internal.MultiHook import MultiHook
+
+
+class SmoozedCom(MultiHook):
+ __name__ = "SmoozedCom"
+ __type__ = "hook"
+ __version__ = "0.01"
+
+ __config__ = [("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"),
+ ("hosterList", "str", "Hoster list (comma separated)", ""),
+ ("unloadFailing", "bool", "Revert to stanard download if download fails", False),
+ ("interval", "int", "Reload interval in hours (0 to disable)", 24)]
+
+ __description__ = """Smoozed.com hook plugin"""
+ __license__ = "GPLv3"
+ __authors__ = []
+
+
+ def getHosters(self):
+ # If no accounts are available there will be no hosters available
+ if not self.account or not self.account.canUse():
+ return []
+
+ # Get account data
+ (user, data) = self.account.selectAccount()
+ account_info = self.account.getAccountInfo(user, True)
+
+ # Return hoster list
+ return account_info["hoster"]
+
+
+ def coreReady(self):
+ # Get account plugin and check if there is a valid account available
+ self.account = self.core.accountManager.getAccountPlugin("SmoozedCom")
+ if not self.account.canUse():
+ self.account = None
+ self.logError(_("Please add a valid premiumize.me account first and restart pyLoad"))
+ return
+
+ # Run the overwriten core ready which actually enables the multihook hook
+ return MultiHook.coreReady(self)
diff --git a/module/plugins/hoster/SmoozedCom.py b/module/plugins/hoster/SmoozedCom.py
new file mode 100644
index 000000000..ce0eeedda
--- /dev/null
+++ b/module/plugins/hoster/SmoozedCom.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+
+from module.plugins.Hoster import Hoster
+
+from module.common.json_layer import json_loads
+
+
+class SmoozedCom(Hoster):
+ __name__ = "SmoozedCom"
+ __type__ = "hoster"
+ __version__ = "0.01"
+
+ __pattern__ = r'^unmatchable$' #: Since we want to allow the user to specify the list of hoster to use we let MultiHoster.coreReady
+
+ __description__ = """Smoozed.com hoster plugin"""
+ __license__ = "GPLv3"
+ __authors__ = []
+
+
+ def process(self, pyfile):
+ # Check account
+ if not self.account or not self.account.canUse():
+ self.logError(_("Please enter your %s account or deactivate this plugin") % "smoozed.com")
+ self.fail(_("No valid smoozed.com account provided"))
+
+ # In some cases hostsers do not supply us with a filename at download, so we
+ # are going to set a fall back filename (e.g. for freakshare or xfileshare)
+ pyfile.name = pyfile.name.split('/').pop() # Remove everthing before last slash
+
+ # Correction for automatic assigned filename: Removing html at end if needed
+ suffix_to_remove = ["html", "htm", "php", "php3", "asp", "shtm", "shtml", "cfml", "cfm"]
+ temp = pyfile.name.split('.')
+ if temp.pop() in suffix_to_remove:
+ pyfile.name = ".".join(temp)
+
+ # Get account data
+ (user, data) = self.account.selectAccount()
+ account_info = self.account.getAccountInfo(user, True)
+
+ # Check the link
+ get_data = {
+ "session_key": account_info['session_key'],
+ "url": pyfile.url
+ }
+ answer = self.load("http://www2.smoozed.com/api/check", get=get_data)
+ data = json_loads(answer)
+ if data["state"] != "ok":
+ self.fail(_(data["message"]))
+ if data["data"].get("state", "ok") != "ok":
+ if data["data"] == "Offline":
+ self.offline()
+ else:
+ self.fail(_(data["data"]["message"]))
+ pyfile.name = data["data"]["name"]
+ pyfile.size = int(data["data"]["size"])
+
+ # Start the download
+ header = self.load("http://www2.smoozed.com/api/download", get=get_data, just_header=True)
+ if not "location" in header:
+ self.fail(_("Unable to initialize download"))
+
+ if isinstance(header["location"], list):
+ url = header["location"][-1]
+ else:
+ url = header["location"]
+ self.download(url, disposition=True)
+
+ check = self.checkDownload({"error": '{"state":"error"}', "retry": '{"state":"retry"}'})
+ if check == "error" or check == "retry":
+ self.fail(_("Error response received - contact Smoozed support"))