diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 16:27:52 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-04-07 16:27:52 +0200 |
commit | 5c00de8d1a74aa097b856a8c479f219e8e1ef2ae (patch) | |
tree | c537d810da129b69cc9dee3c56c57ac91db91eb3 | |
parent | Merge pull request #1301 from saintego/patch-5 (diff) | |
parent | [hoster request]yadi.sk #1292 (diff) | |
download | pyload-5c00de8d1a74aa097b856a8c479f219e8e1ef2ae.tar.xz |
Merge pull request #1318 from saintego/patch-6
New plugin: YadiSk
-rw-r--r-- | module/plugins/hoster/YadiSk | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/module/plugins/hoster/YadiSk b/module/plugins/hoster/YadiSk new file mode 100644 index 000000000..33f791352 --- /dev/null +++ b/module/plugins/hoster/YadiSk @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- + +import re +import pycurl +import random + +from module.common.json_layer import json_loads +from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo + + +class YadiSk(SimpleHoster): + __name__ = "YadiSk" + __type__ = "hoster" + __version__ = "0.01" + + __pattern__ = r'https?://yadi\.sk/d/.+' + + __description__ = """yadi.sk hoster plugin""" + __license__ = "GPLv3" + __authors__ = [("GammaC0de", "nomail@fakemailbox.com")] + + OFFLINE_PATTERN = r"Nothing found" + + + def setup(self): + self.resumeDownload = False + self.multiDL = False + self.chunkLimit = 1 + + def prepare(self): + self.req.http.c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0") + return super(YadiSk, self).prepare() + + def handleFree(self, pyfile): + m = re.search(r'<script id="models-client" type="application/json">(.+?)</script>', self.html) + if m is None: + self.fail(_("could not find required json data")) + + json = m.group(1) + + res = json_loads(json) + + yadisk_ver = yadisk_sk = yadisk_id = yadisk_size = yadisk_name = yadisk_hash = None + try: + for sect in res: + if 'model' in sect: + if sect['model'] == 'config': + yadisk_ver = sect['data']['version'] + yadisk_sk = sect['data']['sk'] + elif sect['model'] == 'resource': + yadisk_id = sect['data']['id'] + yadisk_size = sect['data']['meta']['size'] + yadisk_name = sect['data']['name'] + except: + self.fail(_("Unexpected server response")) + if yadisk_id is None or yadisk_sk is None or yadisk_id is None or yadisk_size is None or yadisk_name is None: + self.fail(_("json data is missing important information, cannot continue")) + + + self.pyfile.size = yadisk_size + self.pyfile.name = yadisk_name + + yadisk_idclient = "" + for i in range(1, 32): + yadisk_idclient += random.choice('0123456abcdef') + + post_data = {'idClient': yadisk_idclient, + 'version': yadisk_ver, + '_model.0': 'do-get-resource-url', + 'sk': yadisk_sk, + 'id.0': yadisk_id} + + result_json = self.load("https://yadi.sk/models/?_m=do-get-resource-url", post=post_data) + + res = json_loads(result_json) + try: + url = res['models'][0]['data']['file'] + except: + self.fail(_("faild to retrieve the download url")) + + self.download(url) + + +getInfo = create_getInfo(YadiSk) |