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

import re
from module.plugins.Account import Account
from module.common.json_layer import json_loads


class RapiduNet(Account):
    __name__ = "RapiduNet"
    __type__ = "account"
    __version__ = "0.01"

    __description__ = """Rapidu.net account plugin"""
    __license__ = "GPLv3"
    __authors__ = [("prOq", None)]


    ACCOUNT_INFO_PATTERN = '<a href="premium/" style="padding-left: 0px;">Account: <b>(.*?)</b></a>'


    def loadAccountInfo(self, user, req):
	premium = False

        req.load('https://rapidu.net/ajax.php?a=getChangeLang', post={"_go": "", "lang": "en"})
	self.html = req.load('https://rapidu.net/', decode=True)

	m = re.search(self.ACCOUNT_INFO_PATTERN, self.html)
	if m:
	    if m.group(1) == "Premium":
		premium = True

        return {"validuntil": None, "trafficleft": None, "premium": premium}


    def login(self, user, data, req):
        try:
            json = req.load('https://rapidu.net/ajax.php?a=getUserLogin', post={"_go": "", "login": user, "pass": data['password'], "member": "1"})
            json = json_loads(json)
            self.logDebug(json)

            if not json['message'] == "success":
		self.wrongPassword()
        except Exception, e:
            self.logError(e)


@@ -159,16 +159,19 @@
 __name__
+   
  = %22Rapi
@@ -189,16 +189,19 @@
 __type__
+   
  = %22acco
@@ -227,17 +227,17 @@
 _ = %220.0
-1
+2
 %22%0A%0A    _
@@ -300,16 +300,20 @@
 icense__
+    
  = %22GPLv
@@ -330,16 +330,20 @@
 uthors__
+    
  = %5B(%22pr
@@ -360,28 +360,23 @@
 %5D%0A%0A%0A    
-ACCOUNT_INFO
+PREMIUM
 _PATTERN
@@ -378,16 +378,17 @@
 TTERN = 
+r
 '%3Ca href
@@ -442,13 +442,15 @@
  %3Cb%3E
-(.*?)
+Premium
 %3C/b%3E
@@ -503,24 +503,82 @@
 q):%0A
-%09
+        info = %7B'validuntil': None, 'trafficleft': None, '
 premium
- =
+':
  False
+%7D
 %0A%0A  
@@ -584,33 +584,33 @@
        req.load(
-'
+%22
 https://rapidu.n
@@ -620,19 +620,30 @@
 ajax.php
-?a=
+%22, get=%7B'a': %22
 getChang
@@ -647,17 +647,18 @@
 angeLang
-'
+%22%7D
 , post=%7B
@@ -683,22 +683,24 @@
  %22en%22%7D)%0A
-%09self.
+        
 html = r
@@ -699,33 +699,33 @@
 html = req.load(
-'
+%22
 https://rapidu.n
@@ -727,17 +727,17 @@
 idu.net/
-'
+%22
 , decode
@@ -748,12 +748,18 @@
 e)%0A%0A
-%09m =
+        if
  re.
@@ -774,90 +774,59 @@
 elf.
-ACCOUNT_INFO_PATTERN, self.html)%0A%09if m:%0A%09    if m.group(1) == %22Premium%22:%0A%09%09
+PREMIUM_PATTERN, html):%0A            info%5B'
 premium
+'%5D
  = T
@@ -849,69 +849,12 @@
 urn 
-%7B%22validuntil%22: None, %22trafficleft%22: None, %22premium%22: premium%7D
+info
 %0A%0A%0A 
@@ -922,16 +922,27 @@
  json = 
+json_loads(
 req.load
@@ -942,17 +942,17 @@
 eq.load(
-'
+%22
 https://
@@ -989,49 +989,178 @@
 ogin
-',
+%22,%0A                                      
  post=%7B
-%22_go%22
+'_go'
 : %22%22,
- %22
+%0A                                             '
 login
-%22
+'
 : user,
- %22
+%0A                                             '
 pass
-%22
+'
 : da
@@ -1178,60 +1178,71 @@
 d'%5D,
- %22member%22: %221%22%7D)%0A            json = json_loads(json)
+%0A                                             'member': %221%22%7D))%0A
 %0A   
@@ -1324,10 +1324,24 @@
 s%22:%0A
-%09%09
+                
 self
@@ -1357,16 +1357,17 @@
 sword()%0A
+%0A
         
@@ -1416,9 +1416,8 @@
 rror(e)%0A
-%0A

Improve account plugin