diff options
-rw-r--r-- | module/plugins/accounts/FilecloudIo.py | 49 | ||||
-rw-r--r-- | module/plugins/hooks/Checksum.py | 18 | ||||
-rw-r--r-- | module/plugins/hoster/FilecloudIo.py | 112 | ||||
-rw-r--r-- | module/plugins/hoster/IfileIt.py | 4 |
4 files changed, 173 insertions, 10 deletions
diff --git a/module/plugins/accounts/FilecloudIo.py b/module/plugins/accounts/FilecloudIo.py new file mode 100644 index 000000000..cf9f92209 --- /dev/null +++ b/module/plugins/accounts/FilecloudIo.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: zoidberg +""" + +from module.plugins.Account import Account + +class FilecloudIo(Account): + __name__ = "FilecloudIo" + __version__ = "0.01" + __type__ = "account" + __description__ = """FilecloudIo account plugin""" + __author_name__ = ("zoidberg") + __author_mail__ = ("zoidberg@mujmail.cz") + + def loadAccountInfo(self, user, req): + return ({"validuntil": -1, "trafficleft": -1, "premium": False}) + + def login(self, user, data, req): + req.cj.setCookie("secure.filecloud.io", "lang", "en") + html = req.load('https://secure.filecloud.io/user-login.html') + + if not hasattr(self, "form_data"): + self.form_data = {} + + self.form_data["username"] = user + self.form_data["password"] = data['password'] + + html = req.load('https://secure.filecloud.io/user-login_p.html', + post = self.form_data, + multipart = True) + + self.logged_in = True if "you have successfully logged in - filecloud.io" in html else False + self.form_data = {} +
\ No newline at end of file diff --git a/module/plugins/hooks/Checksum.py b/module/plugins/hooks/Checksum.py index 0c2751e7a..cb6f4bfe8 100644 --- a/module/plugins/hooks/Checksum.py +++ b/module/plugins/hooks/Checksum.py @@ -49,7 +49,7 @@ def computeChecksum(local_file, algorithm): class Checksum(Hook): __name__ = "Checksum" - __version__ = "0.04" + __version__ = "0.05" __description__ = "Verify downloaded file size and checksum (enable in general preferences)" __config__ = [("activated", "bool", "Activated", True), ("action", "fail;retry;nothing", "What to do if check fails?", "retry"), @@ -59,7 +59,7 @@ class Checksum(Hook): def setup(self): self.algorithms = sorted(getattr(hashlib, "algorithms", ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")), reverse = True) - self.algorithms.append(["crc32", "adler32"]) + self.algorithms.extend(["crc32", "adler32"]) if not self.config['general']['checksum']: self.logInfo("Checksum validation is disabled in general configuration") @@ -70,14 +70,15 @@ class Checksum(Hook): pyfile.plugin.check_data should be a dictionary which can contain: a) if known, the exact filesize in bytes (e.g. "size": 123456789) b) hexadecimal hash string with algorithm name as key (e.g. "md5": "d76505d0869f9f928a17d42d66326307") - """ - + """ if hasattr(pyfile.plugin, "check_data") and (isinstance(pyfile.plugin.check_data, dict)): - data = pyfile.plugin.check_data + data = pyfile.plugin.check_data.copy() elif hasattr(pyfile.plugin, "api_data") and (isinstance(pyfile.plugin.api_data, dict)): - data = pyfile.plugin.api_data + data = pyfile.plugin.api_data.copy() else: - return + return + + self.logDebug(data) download_folder = self.config['general']['download_folder'] local_file = fs_encode(save_join(download_folder, pyfile.package().folder, pyfile.name)) @@ -92,9 +93,10 @@ class Checksum(Hook): if api_size != file_size: self.logWarning("File %s has incorrect size: %d B (%d expected)" % (pyfile.name, file_size, api_size)) self.checkFailed(pyfile, "Incorrect file size") + del data['size'] # validate checksum - if self.config['general']['checksum']: + if data and self.config['general']['checksum']: if "checksum" in data: data['md5'] = data['checksum'] diff --git a/module/plugins/hoster/FilecloudIo.py b/module/plugins/hoster/FilecloudIo.py new file mode 100644 index 000000000..4a096e400 --- /dev/null +++ b/module/plugins/hoster/FilecloudIo.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: zoidberg +""" + +import re +from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo, PluginParseError +from module.common.json_layer import json_loads +from module.plugins.ReCaptcha import ReCaptcha +from module.network.RequestFactory import getURL + +class FilecloudIo(SimpleHoster): + __name__ = "FilecloudIo" + __type__ = "hoster" + __pattern__ = r"http://(?:\w*\.)*(?:filecloud\.io|ifile\.it|mihd\.net)/(?P<ID>\w+).*" + __version__ = "0.01" + __description__ = """Filecloud.io (formerly Ifile.it) plugin - free account only""" + __author_name__ = ("zoidberg") + + FILE_SIZE_PATTERN = r'{var __ab1 = (?P<S>\d+);}' + FILE_NAME_PATTERN = r'id="aliasSpan">(?P<N>.*?) <' + FILE_OFFLINE_PATTERN = r'l10n.(FILES__DOESNT_EXIST|REMOVED)' + TEMP_OFFLINE_PATTERN = r'l10n.FILES__WARNING' + + UKEY_PATTERN = r"'ukey'\s*:'(\w+)'," + AB1_PATTERN = r"if\( __ab1 == '(\w+)' \)" + ERROR_MSG_PATTERN = r"var __error_msg\s*=\s*l10n\.(.*?);" + DOWNLOAD_LINK_PATTERN = r'"(http://s\d+.filecloud.io/%s/\d+/.*?)"' + RECAPTCHA_KEY_PATTERN = r"var __recaptcha_public\s*=\s*'([^']+)';" + RECAPTCHA_KEY = '6Lf5OdISAAAAAEZObLcx5Wlv4daMaASRov1ysDB1' + + def setup(self): + self.resumeDownload = self.multiDL = True + self.chunkLimit = 1 + + def handleFree(self): + data = {"ukey": self.file_info['ID']} + + found = re.search(self.AB1_PATTERN, self.html) + if not found: + raise PluginParseError("__AB1") + data["__ab1"] = found.group(1) + + if not self.account: + self.fail("User not logged in") + elif not self.account.logged_in: + recaptcha = ReCaptcha(self) + captcha_challenge, captcha_response = recaptcha.challenge(self.RECAPTCHA_KEY) + self.account.form_data = {"recaptcha_challenge_field" : captcha_challenge, + "recaptcha_response_field" : captcha_response} + self.account.relogin(self.user) + self.retry(max_tries = 2) + + json_url = "http://filecloud.io/download-request.json" + response = self.load(json_url, post = data) + self.logDebug(response) + response = json_loads(response) + + if "error" in response and response["error"]: + self.fail(response) + + self.logDebug(response) + if response["captcha"]: + recaptcha = ReCaptcha(self) + found = re.search(self.RECAPTCHA_KEY_PATTERN, self.html) + captcha_key = found.group(1) if found else self.RECAPTCHA_KEY + data["ctype"] = "recaptcha" + + for i in range(5): + data["recaptcha_challenge"], data["recaptcha_response"] = recaptcha.challenge(captcha_key) + + json_url = "http://filecloud.io/download-request.json" + response = self.load(json_url, post = data) + self.logDebug(response) + response = json_loads(response) + + if "retry" in response and response["retry"]: + self.invalidCaptcha() + else: + self.correctCaptcha() + break + else: + self.fail("Incorrect captcha") + + if response["dl"]: + self.html = self.load('http://filecloud.io/download.html') + found = re.search(self.DOWNLOAD_LINK_PATTERN % self.file_info['ID'], self.html) + if not found: + raise PluginParseError("Download URL") + download_url = found.group(1) + self.logDebug("Download URL: %s" % download_url) + + if "size" in self.file_info and self.file_info['size']: + self.check_data = {"size": int(self.file_info['size'])} + self.download(download_url) + else: + self.fail("Unexpected server response") + +getInfo = create_getInfo(FilecloudIo)
\ No newline at end of file diff --git a/module/plugins/hoster/IfileIt.py b/module/plugins/hoster/IfileIt.py index 1626b1853..bf394f340 100644 --- a/module/plugins/hoster/IfileIt.py +++ b/module/plugins/hoster/IfileIt.py @@ -25,8 +25,8 @@ from module.network.RequestFactory import getURL class IfileIt(SimpleHoster): __name__ = "IfileIt" __type__ = "hoster" - __pattern__ = r"http://(?:\w*\.)*(?:ifile\.it|mihd\.net)/(\w+).*" - __version__ = "0.26" + __pattern__ = r"^unmatchable$" + __version__ = "0.27" __description__ = """Ifile.it""" __author_name__ = ("zoidberg") |