<commit_before># -*- coding: utf-8 -*-

import re
import time

from module.plugins.internal.Account import Account
from module.PyFile import PyFile
from module.plugins.captcha.ReCaptcha import ReCaptcha


class NitroflareCom(Account):
    __name__    = "NitroflareCom"
    __type__    = "account"
    __version__ = "0.12"
    __status__  = "testing"

    __description__ = """Nitroflare.com account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("<NAME>", "<EMAIL>"         ),
                       ("GammaC0de",      "nitzo2001[AT]yahoo[DOT]com")]


    VALID_UNTIL_PATTERN  = r'>Time Left</label><strong>(.+?)</'
    TRAFFIC_LEFT_PATTERN = r'>Your Daily Limit</label><strong>([\d.,]+) / ([\d.,]+)'
    LOGIN_FAIL_PATTERN   = r'<ul class="errors">\s*<li>'

    TOKEN_PATTERN =   r'name="token" value="(.+?)"'


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

        html = self.load("https://nitroflare.com/member",
                         get={'s': "premium"})

        m = re.search(self.VALID_UNTIL_PATTERN, html)
        if m is not None:
            expiredate = m.group(1).strip()
            self.log_debug("Time Left: " + expiredate)

            try:
                validuntil = sum(int(v) * {'day': 24 * 3600, 'hour': 3600, 'minute': 60}[u.lower()] for v, u in
                                 re.findall(r'(\d+)\s*(day|hour|minute)', expiredate, re.I))

            except Exception, e:
                self.log_error(e, trace=True)

            else:
                self.log_debug("Valid until: %s" % validuntil)

                if validuntil:
                    validuntil += time.time()
                    premium = True
                else:
                    validuntil = -1

        m = re.search(self.TRAFFIC_LEFT_PATTERN, html)
        if m is not None:
            try:
                trafficleft = self.parse_traffic(str(max(0, float(m.group(2)) - float(m.group(1)))),  "GB")

            except Exception, e:
                self.log_error(e, trace=True)
        else:
            self.log_debug("TRAFFIC_LEFT_PATTERN not found")

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


    def signin(self, user, password, data):
        login_url = "https://nitroflare.com/login"
        post_data = {'login'   : "",
                     'email'   : user,
                     'password': password}

        self.data = self.load(login_url)

        # dummy pyfile
        pyfile = PyFile(self.pyload.files, -1, login_url, login_url, 0, 0, "", self.classname, -1, -1)
        pyfile.plugin = self

        self.captcha = ReCaptcha(pyfile)

        captcha_key = self.captcha.detect_key()
        if captcha_key:
            response, challenge = self.captcha.challenge()
            post_data['g-recaptcha-response'] = response

        token = re.search(self.TOKEN_PATTERN, self.data).group(1)
        post_data['token'] = token

        self.data = self.load("https://nitroflare.com/login", post=post_data)

        if re.search(self.LOGIN_FAIL_PATTERN, self.data):
            self.fail_login()

    """
     @NOTE: below are methods
      necessary for captcha to work with account plugins
    """
    def check_status(self):
        pass

    def retry_captcha(self, attemps=10, wait=1, msg=_("Max captcha retries reached")):
        self.captcha.invalid()
        self.fail_login(msg="Invalid captcha")


<commit_msg>[NitroflareCom] Update TRAFFIC_LEFT_PATTERN<commit_after># -*- coding: utf-8 -*-

import re
import time

from module.plugins.internal.Account import Account
from module.PyFile import PyFile
from module.plugins.captcha.ReCaptcha import ReCaptcha


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

    __description__ = """Nitroflare.com account plugin"""
    __license__     = "GPLv3"
    __authors__     = [("<NAME>", "<EMAIL>"         ),
                       ("GammaC0de",      "nitzo2001[AT]yahoo[DOT]com")]


    VALID_UNTIL_PATTERN  = r'>Time Left</label><strong>(.+?)</'
    TRAFFIC_LEFT_PATTERN = r'>Your Daily Limit</label><strong>([\d.,]+) (?:[\w^_]+ )?/ ([\d.,]+)'
    LOGIN_FAIL_PATTERN   = r'<ul class="errors">\s*<li>'

    TOKEN_PATTERN =   r'name="token" value="(.+?)"'


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

        html = self.load("https://nitroflare.com/member",
                         get={'s': "premium"})

        m = re.search(self.VALID_UNTIL_PATTERN, html)
        if m is not None:
            expiredate = m.group(1).strip()
            self.log_debug("Time Left: " + expiredate)

            try:
                validuntil = sum(int(v) * {'day': 24 * 3600, 'hour': 3600, 'minute': 60}[u.lower()] for v, u in
                                 re.findall(r'(\d+)\s*(day|hour|minute)', expiredate, re.I))

            except Exception, e:
                self.log_error(e, trace=True)

            else:
                self.log_debug("Valid until: %s" % validuntil)

                if validuntil:
                    validuntil += time.time()
                    premium = True
                else:
                    validuntil = -1

        m = re.search(self.TRAFFIC_LEFT_PATTERN, html)
        if m is not None:
            try:
                trafficleft = self.parse_traffic(str(max(0, float(m.group(2)) - float(m.group(1)))),  "GB")

            except Exception, e:
                self.log_error(e, trace=True)
        else:
            self.log_debug("TRAFFIC_LEFT_PATTERN not found")

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


    def signin(self, user, password, data):
        login_url = "https://nitroflare.com/login"
        post_data = {'login'   : "",
                     'email'   : user,
                     'password': password}

        self.data = self.load(login_url)

        # dummy pyfile
        pyfile = PyFile(self.pyload.files, -1, login_url, login_url, 0, 0, "", self.classname, -1, -1)
        pyfile.plugin = self

        self.captcha = ReCaptcha(pyfile)

        captcha_key = self.captcha.detect_key()
        if captcha_key:
            response, challenge = self.captcha.challenge()
            post_data['g-recaptcha-response'] = response

        token = re.search(self.TOKEN_PATTERN, self.data).group(1)
        post_data['token'] = token

        self.data = self.load("https://nitroflare.com/login", post=post_data)

        if re.search(self.LOGIN_FAIL_PATTERN, self.data):
            self.fail_login()

    """
     @NOTE: below are methods
      necessary for captcha to work with account plugins
    """
    def check_status(self):
        pass

    def retry_captcha(self, attemps=10, wait=1, msg=_("Max captcha retries reached")):
        self.captcha.invalid()
        self.fail_login(msg="Invalid captcha")



{'fraction_non_alphanumeric': 0.13479667933023778, 'fraction_numerical': 0.01041226959335866, 'mean_word_length': 1.9629012088370155, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3506743', 'n_tokens_mistral': 2386, 'n_tokens_neox': 2203, 'n_words': 455}