diff options
Diffstat (limited to 'pyload/plugin/hoster/YadiSk.py')
-rw-r--r-- | pyload/plugin/hoster/YadiSk.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/pyload/plugin/hoster/YadiSk.py b/pyload/plugin/hoster/YadiSk.py new file mode 100644 index 000000000..28576d5d6 --- /dev/null +++ b/pyload/plugin/hoster/YadiSk.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +import random +import re + +from pyload.plugin.internal.SimpleHoster import SimpleHoster +from pyload.utils import json_loads + + +class YadiSk(SimpleHoster): + __name__ = "YadiSk" + __type__ = "hoster" + __version__ = "0.03" + + __pattern__ = r'https?://yadi\.sk/d/\w+' + + __description__ = """Yadi.sk hoster plugin""" + __license__ = "GPLv3" + __authors__ = [("GammaC0de", None)] + + + OFFLINE_PATTERN = r'Nothing found' + + + def setup(self): + self.resumeDownload = False + self.multiDL = False + self.chunkLimit = 1 + + + def handleFree(self, pyfile): + m = re.search(r'<script id="models-client" type="application/json">(.+?)</script>', self.html) + if m is None: + self.error(_("could not find required json data")) + + res = json_loads(m.group(1)) + + yadisk_ver = None + yadisk_sk = None + yadisk_id = None + yadisk_size = None + yadisk_name = None + + try: #@TODO: Copy to apiInfo + 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 Exception, e: + self.fail(_("Unexpected server response"), e) + + if None in (yadisk_id, yadisk_sk, yadisk_id, yadisk_size, yadisk_name): + self.error(_("Missing JSON data")) + + self.pyfile.size = yadisk_size + self.pyfile.name = yadisk_name + + yadisk_idclient = "" + for _i in range(32): + yadisk_idclient += random.choice('0123456abcdef') + + try: + self.html = self.load("https://yadi.sk/models/", + get={'_m': "do-get-resource-url"}, + post={'idClient': yadisk_idclient, + 'version' : yadisk_ver, + '_model.0': "do-get-resource-url", + 'sk' : yadisk_sk, + 'id.0' : yadisk_id}) + + self.link = json_loads(self.html)['models'][0]['data']['file'] + + except Exception: + pass |