summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-30 09:09:35 +0100
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-12-30 09:09:35 +0100
commit5c2e005e3efcce34061782317c5d91adf6dadbe3 (patch)
treef4d80ad6b1f72b30070d298c6ab28c7367aeb85d
parentMerge pull request #2236 from GammaC0de/property.setter (diff)
parentsimpler version (diff)
downloadpyload-5c2e005e3efcce34061782317c5d91adf6dadbe3.tar.xz
Merge pull request #2231 from sebdelsol/patch-4
simpler version
-rw-r--r--module/plugins/hoster/ZippyshareCom.py46
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))