diff options
| author | 2014-11-09 22:20:05 +0100 | |
|---|---|---|
| committer | 2014-11-09 22:20:05 +0100 | |
| commit | f1f4531ce644e6bb4dd2af71ca38586e864aa19e (patch) | |
| tree | 2d97d2cf4183cd5c0a3b12f3b8607c35a102c956 /module/plugins | |
| parent | [AccountManager] I/O error handling (diff) | |
| download | pyload-f1f4531ce644e6bb4dd2af71ca38586e864aa19e.tar.xz | |
[Keep2shareCc] Account plugin
Diffstat (limited to 'module/plugins')
| -rw-r--r-- | module/plugins/accounts/Keep2shareCc.py | 69 | 
1 files changed, 69 insertions, 0 deletions
| diff --git a/module/plugins/accounts/Keep2shareCc.py b/module/plugins/accounts/Keep2shareCc.py new file mode 100644 index 000000000..fa0c9d2e7 --- /dev/null +++ b/module/plugins/accounts/Keep2shareCc.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import re + +from time import gmtime, mktime, strptime + +from module.plugins.Account import Account + + +class Keep2shareCc(Account): +    __name__    = "Keep2shareCC" +    __type__    = "account" +    __version__ = "0.01" + +    __description__ = """Keep2share.cc account plugin""" +    __license__     = "GPLv3" +    __authors__     = [("aeronaut", "aeronaut@pianoguy.de")] + + +    VALID_UNTIL_PATTERN  = r'Premium expires: <b>(.+?)</b>' +    TRAFFIC_LEFT_PATTERN = r'Available traffic \(today\):<b><a href="/user/statistic.html">(.+?)</a>' + +    LOGIN_FAIL_PATTERN = r'Please fix the following input errors' + + +    def loadAccountInfo(self, user, req): +        validuntil  = None +        trafficleft = None +        premium     = None + +        html = req.load("http://keep2share.cc/site/profile.html", decode=True) + +        m = re.search(self.VALID_UNTIL_PATTERN, html) +        if m: +            expiredate = m.group(1).strip() +            self.logDebug("Expire date: " + expiredate) + +            try: +                validuntil = mktime(strptime(expiredate, "%Y.%m.%d")) + +            except Exception, e: +                self.logError(str(e)) + +            else: +                if validuntil > mktime(gmtime()): +                    premium = True +                else: +                    premium = False +                    validuntil = None + +        m = re.search(self.TRAFFIC_LEFT_PATTERN, html) +        if m: +            try: +                trafficleft = self.parseTraffic(m.group(1)) + +            except Exception, e: +                self.logError(str(e)) + +        return {'validuntil': validuntil, 'trafficleft': trafficleft, 'premium': premium} + + +    def login(self, user, data, req): +        req.cj.setCookie(".keep2share.cc", "lang", "en") + +        html = req.load("http://keep2share.cc/login.html", +                        post={'LoginForm[username]': user, 'LoginForm[password]': data["password"]}) + +        if re.search(self.LOGIN_FAIL_PATTERN, html): +            self.wrongPassword() | 
