# -*- coding: utf-8 -*-

import re
from time import strptime, mktime

from module.plugins.Account import Account


class FreakshareCom(Account):
    __name__    = "FreakshareCom"
    __type__    = "account"
    __version__ = "0.1"

    __description__ = """Freakshare.com account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("RaNaN", "RaNaN@pyload.org")]


    def loadAccountInfo(self, user, req):
        page = req.load("http://freakshare.com/")

        validuntil = r'ltig bis:</td>\s*<td><b>([\d.:-]+)</b></td>'
        validuntil = re.search(validuntil, page, re.M)
        validuntil = validuntil.group(1).strip()
        validuntil = mktime(strptime(validuntil, "%d.%m.%Y - %H:%M"))

        traffic = r'Traffic verbleibend:</td>\s*<td>([^<]+)'
        traffic = re.search(traffic, page, re.M)
        traffic = traffic.group(1).strip()
        traffic = self.parseTraffic(traffic)

        return {"validuntil": validuntil, "trafficleft": traffic}


    def login(self, user, data, req):
        page = req.load("http://freakshare.com/login.html", None,
                        {"submit": "Login", "user": user, "pass": data['password']}, cookies=True)

        if "Falsche Logindaten!" in page or "Wrong Username or Password!" in page:
            self.wrongPassword()

@@ -222,16 +222,17 @@
 _ = %220.1
+1
 %22%0A%0A    _
@@ -1003,32 +1003,97 @@
 er, data, req):%0A
+        req.load(%22http://freakshare.com/index.php?language=EN%22)%0A%0A
         page = r
@@ -1258,41 +1258,9 @@
 if %22
-Falsche Logindaten!%22 in page or %22
+%3E
 Wron
@@ -1285,9 +1285,8 @@
 word
-!
 %22 in

Improve account