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

import re

from module.plugins.internal.Account import Account
from module.plugins.internal.misc import set_cookie


class FastshareCz(Account):
    __name__    = "FastshareCz"
    __type__    = "account"
    __version__ = "0.13"
    __status__  = "testing"

    __description__ = """Fastshare.cz account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("zoidberg", "zoidberg@mujmail.cz"),
                       ("stickell", "l.stickell@yahoo.it")]


    CREDIT_PATTERN = r'Credit\s*:\s*</td>\s*<td>(.+?)\s*<'


    def grab_info(self, user, password, data):
        validuntil  = -1
        trafficleft = None
        premium     = False

        html = self.load("http://www.fastshare.cz/user")

        m = re.search(self.CREDIT_PATTERN, html)
        if m is not None:
            trafficleft = self.parse_traffic(m.group(1))

        premium = bool(trafficleft)

        return {'validuntil' : validuntil,
                'trafficleft': trafficleft,
                'premium'    : premium}


    def signin(self, user, password, data):
        set_cookie(self.req.cj, "fastshare.cz", "lang", "en")

        self.load('http://www.fastshare.cz/login')  #@NOTE: Do not remove or it will not login

        html = self.load("https://www.fastshare.cz/sql.php",
                         post={'login': user,
                               'heslo': password})

        if ">Wrong username or password" in html:
            self.fail_login()

@@ -245,17 +245,17 @@
 _ = %220.1
-3
+4
 %22%0A    __
@@ -485,69 +485,141 @@
 it%22)
-%5D%0A%0A%0A    CREDIT_PATTERN = r'Credit%5Cs*:%5Cs*%3C/td%3E%5Cs*%3Ctd%3E(.+?)%5Cs*%3C
+,%0A                       (%22ondrej%22, %22git@ondrej.it%22)%5D%0A%0A%0A    CREDIT_PATTERN = r'%3Ca href=%22/user%22%3E.+%3Cspan%3E%5C((%5Cd+) (%5BMGT%5D+B)%5C)%3C/span%3E%3C/a%3E
 '%0A%0A%0A
@@ -934,16 +934,36 @@
 group(1)
+, m.group(2).lower()
 )%0A%0A     
@@ -1249,24 +1249,25 @@
 f.load('http
+s
 ://www.fasts

Fix FastshareCz acc (#2708)