diff options
author | sebdelsol <seb.morin@gmail.com> | 2015-12-29 17:27:10 +0100 |
---|---|---|
committer | sebdelsol <seb.morin@gmail.com> | 2015-12-29 17:27:10 +0100 |
commit | 73c179e971a97a238d0088ed416d92e815e0c0ba (patch) | |
tree | a47df1480d1cbfba51142ed5988adc5c980dc299 /module/plugins | |
parent | Tiny code cosmetics (diff) | |
download | pyload-73c179e971a97a238d0088ed416d92e815e0c0ba.tar.xz |
simpler version
It uses some JS to emulate a document - so it'll be simpler to add any JS function in case Zippyshare's devs decide to add deeper instrospection.
It has worked for several months on my side - quite the same code actually.
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/hoster/ZippyshareCom.py | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/module/plugins/hoster/ZippyshareCom.py b/module/plugins/hoster/ZippyshareCom.py index b1b084ee8..491bf727a 100644 --- a/module/plugins/hoster/ZippyshareCom.py +++ b/module/plugins/hoster/ZippyshareCom.py @@ -12,7 +12,7 @@ from module.plugins.internal.SimpleHoster import SimpleHoster class ZippyshareCom(SimpleHoster): __name__ = "ZippyshareCom" __type__ = "hoster" - __version__ = "0.86" + __version__ = "0.87" __status__ = "testing" __pattern__ = r'http://www\d{0,3}\.zippyshare\.com/v(/|iew\.jsp.*key=)(?P<KEY>[\w^_]+)' @@ -66,32 +66,30 @@ class ZippyshareCom(SimpleHoster): def get_link(self): #: Get all the scripts inside the html body soup = BeautifulSoup.BeautifulSoup(self.data) - scripts = (s.getText().strip() for s in soup.body.findAll('script', type='text/javascript')) - - #: Meant to be populated with the initialization of all the DOM elements found in the scripts - initScripts = set() - - def repl_element_by_id(element): - id = element.group(1) #: Id might be either 'x' (a real id) or x (a variable) - attr = element.group(4) #: Attr might be None - - varName = re.sub(r'-', '', 'GVAR[%s+"_%s"]' %(id, attr)) - - realid = id.strip('"\'') - if id is not realid: #: Id is not a variable, so look for realid.attr in the html - initValues = filter(None, [elt.get(attr, None) for elt in soup.findAll(id=realid)]) - initValue = '"%s"' % initValues[-1] if initValues else 'null' - initScripts.add('%s = %s;' % (varName, initValue)) - - return varName - - #: Handle all getElementById - reVar = r'document.getElementById\(([\'"\w\-]+)\)(\.)?(getAttribute\([\'"])?(\w+)?([\'"]\))?' - scripts = [re.sub(reVar, repl_element_by_id, script) for script in scripts if script] + scripts = [s.getText() for s in soup.body.findAll('script', type='text/javascript')] + + #: Emulate a document in JS + inits = [''' + var document = {} + document.getElementById = function(x) { + if (!this.hasOwnProperty(x)) { + this[x] = {getAttribute : function(x) { return this[x] } } + } + return this[x] + } + '''] + + #: inits is meant to be populated with the initialization of all the DOM elements found in the scripts + eltRE = r'getElementById\([\'"](.+?)[\'"]\)(\.)?(getAttribute\([\'"])?(\w+)?([\'"]\))?' + for m in re.findall(eltRE, ' '.join(scripts)): + JSid, JSattr = m[0], m[3] + values = filter(None, (elt.get(JSattr, None) for elt in soup.findAll(id=JSid))) + if values: + inits.append('document.getElementById("%s")["%s"] = "%s"' %(JSid, JSattr, values[-1])) #: Add try/catch in JS to handle deliberate errors scripts = ['\n'.join(('try{', script, '} catch(err){}')) for script in scripts] #: Get the file's url by evaluating all the scripts - scripts = ["var GVAR = {}"] + list(initScripts) + scripts + ['GVAR["dlbutton_href"]'] + scripts = inits + scripts + ['document.dlbutton.href'] return self.js.eval('\n'.join(scripts)) |