diff options
| author | 2013-11-03 14:16:45 +0100 | |
|---|---|---|
| committer | 2013-11-03 14:16:45 +0100 | |
| commit | 78f6e231b9be3e0376a584b260f035978eb4ff58 (patch) | |
| tree | 52eb31183965e5743a9f01a699aaf3caeff74652 | |
| parent | Merge pull request #351 from AndroKev/stable (diff) | |
| download | pyload-78f6e231b9be3e0376a584b260f035978eb4ff58.tar.xz | |
New multi-hoster: RPNetBiz
Merged #339
| -rw-r--r-- | module/plugins/accounts/RPNetBiz.py | 45 | ||||
| -rw-r--r-- | module/plugins/hooks/RPNetBiz.py | 47 | ||||
| -rw-r--r-- | module/plugins/hoster/RPNetBiz.py | 76 | 
3 files changed, 168 insertions, 0 deletions
| diff --git a/module/plugins/accounts/RPNetBiz.py b/module/plugins/accounts/RPNetBiz.py new file mode 100644 index 000000000..ceb5e6bbb --- /dev/null +++ b/module/plugins/accounts/RPNetBiz.py @@ -0,0 +1,45 @@ +from module.plugins.Account import Account +from module.common.json_layer import json_loads + + +class RPNetBiz(Account): +    __name__ = "RPNetBiz" +    __version__ = "0.1" +    __type__ = "account" +    __description__ = """RPNet.biz account plugin""" +    __author_name__ = ("Dman") +    __author_mail__ = ("dmanugm@gmail.com") + +    def loadAccountInfo(self, user, req): +        # Get account information from rpnet.biz +        response = self.getAccountStatus(user, req) +        try: +            if response['accountInfo']['isPremium']: +                # Parse account info. Change the trafficleft later to support per host info. +                account_info = {"validuntil": int(response['accountInfo']['premiumExpiry']), +                                "trafficleft": -1, "premium": True} +            else: +                account_info = {"validuntil": None, "trafficleft": None, "premium": False} + +        except KeyError: +            #handle wrong password exception +            account_info = {"validuntil": None, "trafficleft": None, "premium": False} + +        return account_info + +    def login(self, user, data, req): +        # Get account information from rpnet.biz +        response = self.getAccountStatus(user, req) + +        # If we have an error in the response, we have wrong login information +        if 'error' in response: +            self.wrongPassword() + +    def getAccountStatus(self, user, req): +        # Using the rpnet API, check if valid premium account +        response = req.load("https://premium.rpnet.biz/client_api.php", +                            get={"username": user, "password": self.accounts[user]['password'], +                                 "action": "showAccountInformation"}) +        self.logDebug("JSON data: %s" % response) + +        return json_loads(response) diff --git a/module/plugins/hooks/RPNetBiz.py b/module/plugins/hooks/RPNetBiz.py new file mode 100644 index 000000000..69976ffc9 --- /dev/null +++ b/module/plugins/hooks/RPNetBiz.py @@ -0,0 +1,47 @@ +from module.plugins.internal.MultiHoster import MultiHoster +from module.common.json_layer import json_loads +from module.network.RequestFactory import getURL + + +class RPNetBiz(MultiHoster): +    __name__ = "RPNetBiz" +    __version__ = "0.1" +    __type__ = "hook" +    __description__ = """RPNet.Biz hook plugin""" +    __config__ = [("activated", "bool", "Activated", "False"), +                  ("hosterListMode", "all;listed;unlisted", "Use for hosters (if supported):", "all"), +                  ("hosterList", "str", "Hoster list (comma separated)", ""), +                  ("unloadFailing", "bool", "Revert to stanard download if download fails", "False"), +                  ("interval", "int", "Reload interval in hours (0 to disable)", "24")] +    __author_name__ = ("Dman") +    __author_mail__ = ("dmanugm@gmail.com") + +    def getHoster(self): +        # No hosts supported if no account +        if not self.account or not self.account.canUse(): +            return [] + +        # Get account data +        (user, data) = self.account.selectAccount() + +        response = getURL("https://premium.rpnet.biz/client_api.php", +                          get={"username": user, "password": data['password'], "action": "showHosterList"}) +        hoster_list = json_loads(response) + +        # If account is not valid thera are no hosters available +        if 'error' in hoster_list: +            return [] + +        # Extract hosters from json file  +        return hoster_list['hosters'] + +    def coreReady(self): +        # Get account plugin and check if there is a valid account available +        self.account = self.core.accountManager.getAccountPlugin("RPNetBiz") +        if not self.account.canUse(): +            self.account = None +            self.logError(_("Please enter your %s account or deactivate this plugin") % "rpnet") +            return + +        # Run the overwriten core ready which actually enables the multihoster hook  +        return MultiHoster.coreReady(self) diff --git a/module/plugins/hoster/RPNetBiz.py b/module/plugins/hoster/RPNetBiz.py new file mode 100644 index 000000000..ae8ccf8a9 --- /dev/null +++ b/module/plugins/hoster/RPNetBiz.py @@ -0,0 +1,76 @@ +import re + +from module.plugins.Hoster import Hoster +from module.common.json_layer import json_loads + + +class RPNetBiz(Hoster): +    __name__ = "RPNetBiz" +    __version__ = "0.1" +    __type__ = "hoster" +    __description__ = """RPNet.Biz hoster plugin""" +    __pattern__ = r"https?://.*rpnet\.biz" +    __author_name__ = ("Dman") +    __author_mail__ = ("dmanugm@gmail.com") + +    def setup(self): +        self.chunkLimit = -1 +        self.resumeDownload = True + +    def process(self, pyfile): + +        if re.match(self.__pattern__, pyfile.url): +            link_status = {'generated': pyfile.url} +        elif not self.account: +            # Check account +            self.logError(_("Please enter your %s account or deactivate this plugin") % "rpnet") +            self.fail("No rpnet account provided") +        else: +            (user, data) = self.account.selectAccount() + +            self.logDebug("Original URL: %s" % pyfile.url) +            # Get the download link  +            response = self.load("https://premium.rpnet.biz/client_api.php", +                                 get={"username": user, "password": data['password'], +                                      "action": "generate", "links": self.pyfile.url}) + +            self.logDebug("JSON data: %s" % response) +            link_status = json_loads(response)['links'][0]  # get the first link... since we only queried one + +            # Check if we only have an id as a HDD link +            if 'id' in link_status: +                self.logDebug("Need to wait at least 30 seconds before requery") +                self.setWait(30)  # wait for 30 seconds +                self.wait() +                # Lets query the server again asking for the status on the link, +                # we need to keep doing this until we reach 100 +                max_tries = 30 +                my_try = 0 +                while (my_try <= max_tries): +                    self.logDebug("Try: %d ; Max Tries: %d" % (my_try, max_tries)) +                    response = self.load("https://premium.rpnet.biz/client_api.php", +                                         get={"username": user, "password": data['password'], +                                              "action": "downloadInformation", "id": link_status['id']}) +                    self.logDebug("JSON data hdd query: %s" % response) +                    download_status = json_loads(response)['download'] + +                    if download_status['status'] == '100': +                        link_status['generated'] = download_status['rpnet_link'] +                        self.logDebug("Successfully downloaded to rpnet HDD: %s" % link_status['generated']) +                        break +                    else: +                        self.logDebug("At %s%% for the file download" % download_status['status']) + +                    self.setWait(30) +                    self.wait() +                    my_try += 1 + +                if my_try > max_tries:  # We went over the limit! +                    self.fail("Waited for about 15 minutes for download to finish but failed") + +        if 'generated' in link_status: +            self.download(link_status['generated'], disposition=True) +        elif 'error' in link_status: +            self.fail(link_status['error']) +        else: +            self.fail("Something went wrong, not supposed to enter here") | 
