diff options
| author | 2011-04-21 21:25:41 +0200 | |
|---|---|---|
| committer | 2011-04-21 21:25:41 +0200 | |
| commit | 4133fb008c9cb7c13a6a741986549c3b6e5e79a2 (patch) | |
| tree | f18e9f4d74640e574da8c8d36e39d3705f7ba622 /module | |
| parent | UploadStation: New plugin (diff) | |
| download | pyload-4133fb008c9cb7c13a6a741986549c3b6e5e79a2.tar.xz | |
UploadStation: Fixes & Refactoring
Diffstat (limited to 'module')
| -rw-r--r-- | module/plugins/hoster/UploadStationCom.py | 114 | 
1 files changed, 67 insertions, 47 deletions
| diff --git a/module/plugins/hoster/UploadStationCom.py b/module/plugins/hoster/UploadStationCom.py index 7d28f0065..2723ae2ef 100644 --- a/module/plugins/hoster/UploadStationCom.py +++ b/module/plugins/hoster/UploadStationCom.py @@ -11,6 +11,9 @@ from module.plugins.ReCaptcha import ReCaptcha  from module.network.RequestFactory import getURL
 +def unicode2str(unitext):
 +    return unicodedata.normalize('NFKD', unitext).encode('ascii', 'ignore') 
 +
  def getInfo(urls):
      result = []
 @@ -30,71 +33,78 @@ def getInfo(urls):          # Size
          pattern = r'''<div><span>File size: <b>(.*?) (KB|MB|GB)</b>'''
          m = re.search(pattern, html)
 -        units = float(m.group(1))
 +        value = float(m.group(1))
          pow = {'KB' : 1, 'MB' : 2, 'GB' : 3}[m.group(2)] 
 -        size = int(units*1024**pow)
 +        size = int(value*1024**pow)
          # Return info
          result.append((name, size, 2, url))
      yield result
 +
  class UploadStationCom(Hoster):
      __name__ = "UploadStationCom"
      __type__ = "hoster"
      __pattern__ = r"http://(www\.)?uploadstation\.com/file/[A-Za-z0-9]+"
 -    __version__ = "0.1"
 +    __version__ = "0.2"
      __description__ = """UploadStation.Com File Download Hoster"""
      __author_name__ = ("fragonib")
      __author_mail__ = ("fragonib[AT]yahoo[DOT]es")
      def setup(self):
          self.multiDL = False
 -        self.file_id = re.search(r"uploadstation\.com/file/([a-zA-Z0-9]+)(http:.*)?", self.pyfile.url).group(1)
 -        self.pyfile.url = "http://www.uploadstation.com/file/" + self.file_id
 +        self.fileId = re.search(r"uploadstation\.com/file/([a-zA-Z0-9]+)(http:.*)?", self.pyfile.url).group(1)
 +        self.pyfile.url = "http://www.uploadstation.com/file/" + self.fileId
      def process(self, pyfile):
 -        self.html = self.load(self.pyfile.url, ref=False, cookies=False if self.account else True, utf8=True)
 +        
 +        # Get URL
 +        self.html = self.load(self.pyfile.url, ref=False, cookies=True, utf8=True)
 -        pattern = r'''<h1>File not available</h1>|<b>The file could not be found\. Please check the download link''' 
 -        if re.search(pattern, self.html):
 +        # Is offline?
 +        pattern = r'''<h1>File not available</h1>|<b>The file could not be found\. Please check the download link'''
 +        m = re.search(pattern, self.html) 
 +        if m is not None:
              self.offline()
 +        # Title
          pattern = r'''<div class=\"download_item\">(.*?)</div>'''
          title = re.search(pattern, self.html).group(1)
 -        self.pyfile.name = unicodedata.normalize('NFKD', title).encode('ascii','ignore')            
 +        self.pyfile.name = unicode2str(title)            
 +        # Free account
          self.handleFree()
      def handleFree(self):
 -
 -        self.html = self.load(self.pyfile.url)
          # Not needed yet
 -        #jsPage = re.search(r"\"(/landing/.*?/download_captcha\.js)\"", self.html)
 -        #jsPage = self.load("http://uploadstation.com" + jsPage.group(1))
 +        #pattern = r'''\"(/landing/.*?/download_captcha\.js)\"'''
 +        #jsPage = re.search(pattern, self.html).group(1)
 +        #self.jsPage = self.load("http://uploadstation.com" + jsPage)
 -        self.action = self.load(self.pyfile.url, post={"checkDownload" : "check"})
 -        if "success\":\"showCaptcha\"" in self.action:
 -            self.handleErrors()
 +        # Check download
 +        response = self.load(self.pyfile.url, post={"checkDownload" : "check"})
 +        if not '"success":"showCaptcha"' in response:
 +            self.handleErrors(response)
 -        if r'<div class="speedBox" id="showCaptcha" style="display:none;">' in self.html:
 -            # we got a captcha
 +        # We got a captcha?
 +        if '<div class="speedBox" id="showCaptcha" style="display:none;">' in self.html:
              id = re.search(r"var reCAPTCHA_publickey='(.*?)';", self.html).group(1)
              recaptcha = ReCaptcha(self)
              challenge, code = recaptcha.challenge(id)
 -            
 -            self.html = self.load(r'http://www.uploadstation.com/checkReCaptcha.php', post={'recaptcha_challenge_field':challenge,
 -                'recaptcha_response_field':code, 'recaptcha_shortencode_field': self.file_id})
 -                
 -            if r'incorrect-captcha-sol' in self.html:
 -                self.invalidCaptcha()
 -                self.retry()
 -
 -        wait = self.load(self.pyfile.url, post={"downloadLink":"wait"})
 -        wait = re.search(r".*?(\d+).*?", wait)
 -        if wait:
 -            wait = wait.group(1)
 +            response = self.load('http://www.uploadstation.com/checkReCaptcha.php', 
 +                                  post={'recaptcha_challenge_field' : challenge,
 +                                        'recaptcha_response_field' : code, 
 +                                        'recaptcha_shortencode_field' : self.fileId})
 +            if r'incorrect-captcha-sol' in response:
 +                self.handleCaptchaErrors(response)
 +
 +        # Process waiting
 +        response = self.load(self.pyfile.url, post={"downloadLink":"wait"})
 +        m = re.search(r".*?(\d+).*?", response)
 +        if m is not None:
 +            wait = m.group(1)
              if wait == "404":
                  self.log.debug("No wait time returned")
                  self.fail("No wait time returned")
 @@ -103,32 +113,42 @@ class UploadStationCom(Hoster):              self.wait()
 -        # show download link
 +        # Show download link
          self.load(self.pyfile.url, post={"downloadLink":"show"})
 -        # this may either download our file or forward us to an error page
 +        # This may either download our file or forward us to an error page
          dl = self.download(self.pyfile.url, post={"download":"normal"})
 -        self.handleDownload()
 +        self.handleDownloadedFile()
 +        
 +    def handleErrors(self, response):
 -    def handleErrors(self):
 -        if "timeLimit" in self.action:
 +        text = '"fail":"timeLimit"'
 +        if text in response:
 +            wait = 300
              html = self.load(self.pyfile.url, post={"checkDownload" : "showError", "errorType" : "timeLimit"})
 -            wait = re.search(r"You need to wait (\d+) seconds to start another download", html)
 -            if wait:
 -                wait = int(wait.group(1))
 -            else:
 -                wait = 720
 +            m = re.search(r"You need to wait (\d+) seconds to download next file.", html)
 +            if m is not None:
 +                wait = int(m.group(1))
              self.setWait(wait, True)
              self.wait()
              self.retry()
 -
 -    def handleDownload(self):
 -        check = self.checkDownload({"expired": "Your download link has expired",
 -                                    "wait": re.compile(r'You need to wait (\d+) seconds to start another download')})
 -        if check == "expired":
 +            
 +        text = '"To remove download restriction, please choose your suitable plan as below</h1>"'
 +        if text in response:
 +            wait = 720
 +            self.setWait(wait, True)
 +            self.wait()
              self.retry()
 -        elif check == "wait":
 +            
 +    def handleCaptchaErrors(self, response):
 +        self.invalidCaptcha()
 +        self.retry()
 +
 +    def handleDownloadedFile(self):
 +        check = self.checkDownload({"wait": re.compile(r'You need to wait (\d+) seconds to download next file.')})
 +        
 +        if check == "wait":
              wait_time = 720
              if self.lastCheck is not None:
                  wait_time = int(self.lastCheck.group(1))
 @@ -136,4 +156,4 @@ class UploadStationCom(Hoster):              self.log.debug("%s: You need to wait %d seconds for another download." % (self.__name__, wait_time))
              self.wantReconnect = True
              self.wait()
 -            self.retry()
\ No newline at end of file +            self.retry() 
\ No newline at end of file | 
