diff options
Diffstat (limited to 'module')
| -rw-r--r-- | module/network/HTTPRequest.py | 6 | ||||
| -rw-r--r-- | module/network/RequestFactory.py | 5 | ||||
| -rw-r--r-- | module/plugins/Account.py | 53 | ||||
| -rw-r--r-- | module/plugins/Hook.py | 13 | ||||
| -rw-r--r-- | module/plugins/Plugin.py | 20 | ||||
| -rw-r--r-- | module/plugins/accounts/FilesonicCom.py | 35 | ||||
| -rw-r--r-- | module/plugins/accounts/WuploadCom.py | 51 | ||||
| -rw-r--r-- | module/plugins/hoster/FilesonicCom.py | 27 | 
8 files changed, 148 insertions, 62 deletions
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index cc1a05852..bf23bb202 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -154,7 +154,7 @@ class HTTPRequest():              self.getCookies() -    def load(self, url, get={}, post={}, referer=True, cookies=True, just_header=False, multipart=False): +    def load(self, url, get={}, post={}, referer=True, cookies=True, just_header=False, multipart=False, decode=False):          """ load and returns a given page """          self.setRequestContext(url, get, post, referer, cookies, multipart) @@ -180,7 +180,9 @@ class HTTPRequest():          self.lastEffectiveURL = self.c.getinfo(pycurl.EFFECTIVE_URL)          self.addCookies() -        #rep = self.decodeResponse(rep) +        if decode: +            rep = self.decodeResponse(rep) +          return rep      def verifyHeader(self): diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py index 9b32ed570..44f66efab 100644 --- a/module/network/RequestFactory.py +++ b/module/network/RequestFactory.py @@ -58,9 +58,10 @@ class RequestFactory():          """ returns a http request, dont forget to close it ! """          return HTTPRequest(CookieJar(None), self.getOptions()) -    def getURL(self, url, get={}, post={}, multipart=False): +    def getURL(self, *args, **kwargs): +        """ see HTTPRequest for argument list """          h = HTTPRequest(None, self.getOptions()) -        rep = h.load(url, get, post, multipart=multipart) +        rep = h.load(*args, **kwargs)          h.close()          return rep diff --git a/module/plugins/Account.py b/module/plugins/Account.py index c5d7930e9..557689fe9 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -48,9 +48,9 @@ class Account():          self.infos = {} # cache for account information          self.timestamps = {}          self.setAccounts(accounts) -        self.setup() +        self.init() -    def setup(self): +    def init(self):          pass      def login(self, user, data, req): @@ -62,15 +62,15 @@ class Account():              self.login(user, data, req)              self.timestamps[user] = time()          except WrongPassword: -            self.core.log.warning( -                _("Could not login with %(plugin)s account %(user)s | %(msg)s") % {"plugin": self.__name__, "user": user -                                                                                   , "msg": _("Wrong Password")}) +            self.logWarning( +                _("Could not login with account %(user)s | %(msg)s") % {"user": user +                                                                        , "msg": _("Wrong Password")})              data["valid"] = False          except Exception, e: -            self.core.log.warning( -                _("Could not login with %(plugin)s account %(user)s | %(msg)s") % {"plugin": self.__name__, "user": user -                                                                                   , "msg": e}) +            self.logWarning( +                _("Could not login with account %(user)s | %(msg)s") % {"user": user +                                                                        , "msg": e})              data["valid"] = False              if self.core.debug:                  print_exc() @@ -95,7 +95,7 @@ class Account():      def updateAccounts(self, user, password=None, options={}):          """ updates account and return true if anything changed """ -         +          if self.accounts.has_key(user):              self.accounts[user]["valid"] = True #do not remove or accounts will not login              if password: @@ -124,7 +124,7 @@ class Account():          data = Account.loadAccountInfo(self, name)          if force or not self.infos.has_key(name): -            self.core.log.debug("Get %s Account Info for %s" % (self.__name__, name)) +            self.logDebug("Get Account Info for %s" % name)              req = self.getAccountRequest(name)              try: @@ -136,11 +136,12 @@ class Account():              if req: req.close() -            self.core.log.debug("Account Info: %s" % str(infos)) +            self.logDebug("Account Info: %s" % str(infos))              infos["timestamp"] = time()              self.infos[name] = infos -        elif self.infos[name].has_key("timestamp") and self.infos[name]["timestamp"] + self.info_threshold * 60 < time(): +        elif self.infos[name].has_key("timestamp") and self.infos[name][ +                                                       "timestamp"] + self.info_threshold * 60 < time():              self.scheduleRefresh(name)          data.update(self.infos[name]) @@ -202,7 +203,7 @@ class Account():                      if not compare_time(start.split(":"), end.split(":")):                          continue                  except: -                    self.core.log.warning(_("Your Time %s has wrong format, use: 1:22-3:44") % time_data) +                    self.logWarning(_("Your Time %s has wrong format, use: 1:22-3:44") % time_data)              if self.infos.has_key(user):                  if self.infos[user].has_key("validuntil"): @@ -228,32 +229,42 @@ class Account():      def empty(self, user):          if self.infos.has_key(user): -            self.core.log.warning(_("%(plugin)s Account %(user)s has not enough traffic, checking again in 30min") % { -                "plugin": self.__name__, "user": user}) +            self.logWarning(_("Account %s has not enough traffic, checking again in 30min") % user)              self.infos[user].update({"trafficleft": 0})              self.scheduleRefresh(user, 30 * 60)      def expired(self, user):          if self.infos.has_key(user): -            self.core.log.warning( -                _("%(plugin)s Account %(user)s is expired, checking again in 1h") % {"plugin": self.__name__, -                                                                                     "user": user}) +            self.logWarning(_("Account %s is expired, checking again in 1h") % user)              self.infos[user].update({"validuntil": time() - 1})              self.scheduleRefresh(user, 60 * 60)      def scheduleRefresh(self, user, time=0, force=True):          """ add task to refresh account info to sheduler """ -        self.core.log.debug("Scheduled Account refresh for %s:%s in %s seconds." % (self.__name__, user, time)) +        self.logDebug("Scheduled Account refresh for %s in %s seconds." % (user, time))          self.core.scheduler.addJob(time, self.getAccountInfo, [user, force])      def checkLogin(self, user):          """ checks if user is still logged in """          if self.timestamps.has_key(user):              if self.timestamps[user] + self.login_timeout * 60 < time(): -                self.core.log.debug("Reached login timeout for %s:%s" % (self.__name__, user)) +                self.logDebug("Reached login timeout for %s" % user)                  self.relogin(user)                  return False -        return True
\ No newline at end of file +        return True + +    #log functions +    def logInfo(self, msg): +        self.core.log.info("%s: %s" % (self.__name__, msg)) + +    def logWarning(self, msg): +        self.core.log.warning("%s: %s" % (self.__name__, msg)) + +    def logError(self, msg): +        self.core.log.error("%s: %s" % (self.__name__, msg)) + +    def logDebug(self, msg): +        self.core.log.debug("%s: %s" % (self.__name__, msg)) diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py index c9d9c8778..5c8a3384f 100644 --- a/module/plugins/Hook.py +++ b/module/plugins/Hook.py @@ -76,7 +76,18 @@ class Hook():      def setConfig(self, option, value):          """ sets config value """          self.config.setPlugin(self.__name__, option, value) -     + +    #log functions +    def logInfo(self, msg): +        self.log.info("%s: %s" % (self.__name__, msg)) +    def logWarning(self, msg): +        self.log.warning("%s: %s" % (self.__name__, msg)) +    def logError(self, msg): +        self.log.error("%s: %s" % (self.__name__, msg)) +    def logDebug(self, msg): +        self.log.debug("%s: %s" % (self.__name__, msg)) + +    #event methods - overwrite these if needed          def coreReady(self):          pass diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index d8bd3bcd0..e4ec532d4 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -299,15 +299,12 @@ class Plugin(object):          return result -    def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, utf8=False): +    def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, utf8=False, decode=False):          """ returns the content loaded """          if self.pyfile.abort: raise Abort +        #utf8 vs decode -> please use decode attribute in all future plugins -        res = self.req.load(url, get, post, ref, cookies, just_header) - -        if utf8: -            res = self.req.http.decodeResponse(res) -            #res = decode(res) +        res = self.req.load(url, get, post, ref, cookies, just_header, decode=utf8 or decode)          if self.core.debug:              from inspect import currentframe @@ -473,6 +470,17 @@ class Plugin(object):              self.log.debug("File %s not skipped, because it does not exists." % self.pyfile.name) + +    #log functions +    def logInfo(self, msg): +        self.log.info("%s: %s" % (self.__name__, msg)) +    def logWarning(self, msg): +        self.log.warning("%s: %s" % (self.__name__, msg)) +    def logError(self, msg): +        self.log.error("%s: %s" % (self.__name__, msg)) +    def logDebug(self, msg): +        self.log.debug("%s: %s" % (self.__name__, msg)) +      def clean(self):          """ clean everything and remove references """          if hasattr(self, "pyfile"): diff --git a/module/plugins/accounts/FilesonicCom.py b/module/plugins/accounts/FilesonicCom.py index 9f57809ad..ff4e066e2 100644 --- a/module/plugins/accounts/FilesonicCom.py +++ b/module/plugins/accounts/FilesonicCom.py @@ -27,36 +27,39 @@ try:  except ImportError: # pragma: no cover      from module.lib.simplejson import loads as json_loads -  class FilesonicCom(Account):      __name__ = "FilesonicCom"      __version__ = "0.31"      __type__ = "account"      __description__ = """filesonic.com account plugin""" -    __author_name__ = ("RaNaN","Paul King") -    __author_mail__ = ("RaNaN@pyload.org","") -	 +    __author_name__ = ("RaNaN", "Paul King") +    __author_mail__ = ("RaNaN@pyload.org", "") + +    API_URL = "http://api.filesonic.com" +      def getDomain(self, req): -        xml = req.load("http://api.filesonic.com/utility?method=getFilesonicDomainForCurrentIp&format=json").decode("utf8") +        xml = req.load(self.API_URL + "/utility?method=getFilesonicDomainForCurrentIp&format=json", +                       decode=True)          return json_loads(xml)["FSApi_Utility"]["getFilesonicDomainForCurrentIp"]["response"] -         +      def loadAccountInfo(self, user, req): -        xml = req.load("http://api.filesonic.com/user?method=getInfo&format=json",  -                       post = {"u": user,  -                               "p" : self.accounts[user]["password"]} -                      ).decode("utf8") -        self.core.log.debug("%s: account status retrieved from api %s" % (self.__name__,xml)) +        xml = req.load(self.API_URL + "/user?method=getInfo&format=json", +                       post={"u": user, +                             "p": self.accounts[user]["password"]}, decode=True) + +        self.logDebug("account status retrieved from api %s" % xml) +          json = json_loads(xml)          if json["FSApi_User"]["getInfo"]["status"] != "success": -           self.core.log.error(_("%s: Invalid login retrieving user details" % self.__name__)) -           return {"validuntil": -1, "trafficleft": -1, "premium" : False} +            self.logError(_("Invalid login retrieving user details")) +            return {"validuntil": -1, "trafficleft": -1, "premium": False}          premium = json["FSApi_User"]["getInfo"]["response"]["users"]["user"]["is_premium"]          if premium:              validuntil = json["FSApi_User"]["getInfo"]["response"]["users"]["user"]["premium_expiration"]              validuntil = int(mktime(strptime(validuntil, "%Y-%m-%d %H:%M:%S")))          else:              validuntil = -1 -        return {"validuntil": validuntil, "trafficleft": -1, "premium" : premium} +        return {"validuntil": validuntil, "trafficleft": -1, "premium": premium}      def login(self, user, data, req):          domain = self.getDomain(req) @@ -64,9 +67,9 @@ class FilesonicCom(Account):          post_vars = {              "email": user,              "password": data["password"], -            "rememberMe" : 1 +            "rememberMe": 1          } -        page = req.load("http://www%s/user/login" % domain, cookies=True, post=post_vars).decode("utf8") +        page = req.load("http://www%s/user/login" % domain, cookies=True, post=post_vars, decode=True)          if "Provided password does not match." in page or "You must be logged in to view this page." in page:              self.wrongPassword() diff --git a/module/plugins/accounts/WuploadCom.py b/module/plugins/accounts/WuploadCom.py new file mode 100644 index 000000000..884a4768e --- /dev/null +++ b/module/plugins/accounts/WuploadCom.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +""" +    This program is free software; you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation; either version 3 of the License, +    or (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +    See the GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program; if not, see <http://www.gnu.org/licenses/>. + +    @author: RaNaN +""" + +from types import MethodType + +from module.plugins.Account import Account + +try: +    from json import loads as json_loads +except ImportError: # pragma: no cover +    from module.lib.simplejson import loads as json_loads + +class WuploadCom(Account): +    __name__ = "WuploadCom" +    __version__ = "0.1" +    __type__ = "account" +    __description__ = """filesonic.com account plugin""" +    __author_name__ = ("RaNaN", "Paul King") +    __author_mail__ = ("RaNaN@pyload.org", "") + +    API_URL = "http://api.filesonic.com" + +    def init(self): +        fs = self.core.pluginManager.getAccountPlugin("FilesonicCom") + +        methods = ["loadAccountInfo", "login"] +        #methods to bind from fs + +        for m in methods: +            setattr(self, m, MethodType(fs.__dict__[m], self, WuploadCom)) + +    def getDomain(self, req): +        xml = req.load(self.API_URL + "/utility?method=getWuploadDomainForCurrentIp&format=json", +                       decode=True) +        return json_loads(xml)["FSApi_Utility"]["getWuploadDomainForCurrentIp"]["response"]
\ No newline at end of file diff --git a/module/plugins/hoster/FilesonicCom.py b/module/plugins/hoster/FilesonicCom.py index 48f8c3849..cbe74f214 100644 --- a/module/plugins/hoster/FilesonicCom.py +++ b/module/plugins/hoster/FilesonicCom.py @@ -9,7 +9,6 @@ from module.plugins.ReCaptcha import ReCaptcha  from module.plugins.Plugin import chunks
  from module.network.RequestFactory import getURL
 -from module.utils import decode
  try:
      from json import loads as json_loads
 @@ -29,7 +28,7 @@ def getInfo(urls):          if len(ids) > 0:
              check_url = "http://api.filesonic.com/link?method=getInfo&format=json&ids=" + ",".join(ids.keys())
 -            response = json_loads(getURL(check_url).decode("utf8", "ignore"))
 +            response = json_loads(getURL(check_url, decode=True))
              for item in response["FSApi_Link"]["getInfo"]["response"]["links"]:
                  if item["status"] != "AVAILABLE":
                      result.append((None, 0, 1, ids[item["id"]]))
 @@ -84,13 +83,13 @@ class FilesonicCom(Hoster):      def checkFile(self, url):
          id = getId(url)
 -        self.log.debug("%s: file id is %s" % (self.__name__, id))
 +        self.logDebug("file id is %s" % id)
          if id:
              # Use the api to check the current status of the file and fixup data
              check_url = self.API_ADDRESS + "/link?method=getInfo&format=json&ids=%s" % id
 -            result = json_loads(self.load(check_url).decode("utf8", "ignore"))
 +            result = json_loads(self.load(check_url, decode=True))
              item = result["FSApi_Link"]["getInfo"]["response"]["links"][0]
 -            self.log.debug("%s: api check returns %s" % (self.__name__, item))
 +            self.logDebug("api check returns %s" % item)
              if item["status"] != "AVAILABLE":
                  self.offline()
 @@ -108,24 +107,24 @@ class FilesonicCom(Hoster):              urlparts = re.search(self.URL_DOMAIN_PATTERN, url)
              if urlparts:
                  url = urlparts.group("prefix") + self.getDomain() + urlparts.group("suffix")
 -                self.log.debug("%s: localised url is %s" % (self.__name__, url))
 +                self.logDebug("localised url is %s" % url)
              return url
          else:
              self.fail("Invalid URL")
      def getDomain(self):
          result = json_loads(
 -            self.load(self.API_ADDRESS + "/utility?method=getFilesonicDomainForCurrentIp&format=json", utf8=True))
 -        self.log.debug("%s: response to get domain %s" % (self.__name__, result))
 +            self.load(self.API_ADDRESS + "/utility?method=getFilesonicDomainForCurrentIp&format=json", decode=True))
 +        self.logDebug("response to get domain %s" % result)
          return result["FSApi_Utility"]["getFilesonicDomainForCurrentIp"]["response"]
      def downloadPremium(self):
 -        self.log.debug("%s: Premium download" % self.__name__)
 +        self.logDebug("Premium download")
          self.download(self.pyfile.url)
      def downloadFree(self):
 -        self.log.debug("%s: Free download" % self.__name__)
 +        self.logDebug("Free download")
          # Get initial page
          self.html = self.load(self.pyfile.url)
          url = self.pyfile.url + "?start=1"
 @@ -143,10 +142,10 @@ class FilesonicCom(Hoster):                  for i in range(5):
                      re_captcha = ReCaptcha(self)
                      if chall:
 -                        self.log.debug("%s: Captcha type1" % self.__name__)
 +                        self.logDebug("Captcha type1")
                          challenge, result = re_captcha.challenge(chall.group(1))
                      else:
 -                        self.log.debug("%s: Captcha type2" % self.__name__)
 +                        self.logDebug("Captcha type2")
                          server = chall2.group(1)
                          challenge = chall2.group(2)
                          result = re_captcha.result(server, challenge)
 @@ -170,7 +169,7 @@ class FilesonicCom(Hoster):          if not finalUrl:
              self.fail("Couldn't find free download link")
 -        self.log.debug("%s: got download url %s" % (self.__name__, finalUrl.group(1)))
 +        self.logDebug("got download url %s" % finalUrl.group(1))
          self.download(finalUrl.group(1))
      def doWait(self, url):
 @@ -187,7 +186,7 @@ class FilesonicCom(Hoster):                  self.wantReconnect = True
              self.setWait(wait)
 -            self.log.debug("%s: Waiting %d seconds." % (self.__name__, wait))
 +            self.logDebug("Waiting %d seconds." % wait)
              self.wait()
              tm = re.search(self.WAIT_TM_PATTERN, self.html)
  | 
