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

from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo
from module.plugins.ReCaptcha import ReCaptcha
import re


class EgoFilesCom(SimpleHoster):
    __name__ = "EgoFilesCom"
    __type__ = "hoster"
    __pattern__ = r"https?://(www\.)?egofiles.com/(\w+)"
    __version__ = "0.10"
    __description__ = """Egofiles.com Download Hoster"""
    __author_name__ = ("stickell")
    __author_mail__ = ("<EMAIL>")

    FILE_INFO_PATTERN = r'<div class="down-file">\s+(?P<N>\S+)\s+<div class="file-properties">\s+(File size|Rozmiar): (?P<S>[\w.]+) (?P<U>\w+) \|'
    FILE_OFFLINE_PATTERN = r'(File size|Rozmiar): 0 KB'
    WAIT_TIME_PATTERN = r'For next free download you have to wait <strong>((?P<m>\d*)m)? ?((?P<s>\d+)s)?</strong>'
    DIRECT_LINK_PATTERN = r'<a href="(?P<link>[^"]+)">Download ></a>'
    RECAPTCHA_KEY = '<KEY>'

    def init(self):
        self.file_info = {}
        # Set English language
        self.load("https://egofiles.com/ajax/lang.php?lang=en", just_header=True)

    def handleFree(self):
        self.html = self.load(self.pyfile.url, decode=True)

        # Wait time between free downloads
        if 'For next free download you have to wait' in self.html:
            m = re.search(self.WAIT_TIME_PATTERN, self.html).groupdict('0')
            waittime = int(m['m']) * 60 + int(m['s'])
            self.setWait(waittime, True)
            self.wait()

        downloadURL = ''
        recaptcha = ReCaptcha(self)
        for i in xrange(5):
            challenge, response = recaptcha.challenge(self.RECAPTCHA_KEY)
            post_data = {'recaptcha_challenge_field': challenge,
                         'recaptcha_response_field': response}
            self.html = self.load(self.pyfile.url, post=post_data, decode=True)
            m = re.search(self.DIRECT_LINK_PATTERN, self.html)
            if not m:
                self.logInfo('Wrong captcha')
                self.invalidCaptcha()
            elif hasattr(m, 'group'):
                downloadURL = m.group('link')
                self.correctCaptcha()
                break
            else:
                self.fail('Unknown error - Plugin may be out of date')

        if not downloadURL:
            self.fail("No Download url retrieved/all captcha attempts failed")

        self.download(downloadURL)

    def handlePremium(self):
        header = self.load(self.pyfile.url, just_header=True)
        if header.has_key('location'):
            self.logDebug('DIRECT LINK from header: ' + header['location'])
            self.download(header['location'])
        else:
            self.html = self.load(self.pyfile.url, decode=True)
            m = re.search(r'<a href="(?P<link>[^"]+)">Download ></a>', self.html)
            if not m:
                self.parseError('Unable to detect direct download url')
            else:
                self.logDebug('DIRECT URL from html: ' + m.group('link'))
                self.download(m.group('link'))

getInfo = create_getInfo(EgoFilesCom)<commit_msg>EgoFilesCom: fixed bug in premium downloads. Sometimes for premium users pyfile.url redirect directly to the file, so the load call in the process function of SimpleHoster causes a pyCurl error. + content-disposition<commit_after># -*- coding: utf-8 -*-

############################################################################
# This program is free software: you can redistribute it and/or modify     #
# it under the terms of the GNU Affero General Public License as           #
# published by the Free Software Foundation, either version 3 of the       #
# License, or (at your option) any later version.                          #
#                                                                          #
# This program is distributed in the hope that it will be useful,          #
# but WITHOUT ANY WARRANTY; without even the implied warranty of           #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
# GNU Affero General Public License for more details.                      #
#                                                                          #
# You should have received a copy of the GNU Affero General Public License #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
############################################################################

# Test link (random.bin):
# http://egofiles.com/mOZfMI1WLZ6HBkGG/random.bin

import re

from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo
from module.plugins.ReCaptcha import ReCaptcha


class EgoFilesCom(SimpleHoster):
    __name__ = "EgoFilesCom"
    __type__ = "hoster"
    __pattern__ = r"https?://(www\.)?egofiles.com/(\w+)"
    __version__ = "0.11"
    __description__ = """Egofiles.com Download Hoster"""
    __author_name__ = ("stickell")
    __author_mail__ = ("<EMAIL>")

    FILE_INFO_PATTERN = r'<div class="down-file">\s+(?P<N>\S+)\s+<div class="file-properties">\s+(File size|Rozmiar): (?P<S>[\w.]+) (?P<U>\w+) \|'
    FILE_OFFLINE_PATTERN = r'(File size|Rozmiar): 0 KB'
    WAIT_TIME_PATTERN = r'For next free download you have to wait <strong>((?P<m>\d*)m)? ?((?P<s>\d+)s)?</strong>'
    DIRECT_LINK_PATTERN = r'<a href="(?P<link>[^"]+)">Download ></a>'
    RECAPTCHA_KEY = '<KEY>'

    def init(self):
        self.file_info = {}
        # Set English language
        self.load("https://egofiles.com/ajax/lang.php?lang=en", just_header=True)

    def process(self, pyfile):
        if self.premium and (not self.SH_CHECK_TRAFFIC or self.checkTrafficLeft()):
            self.handlePremium()
        else:
            self.handleFree()

    def handleFree(self):
        self.html = self.load(self.pyfile.url, decode=True)
        self.getFileInfo()

        # Wait time between free downloads
        if 'For next free download you have to wait' in self.html:
            m = re.search(self.WAIT_TIME_PATTERN, self.html).groupdict('0')
            waittime = int(m['m']) * 60 + int(m['s'])
            self.setWait(waittime, True)
            self.wait()

        downloadURL = ''
        recaptcha = ReCaptcha(self)
        for i in xrange(5):
            challenge, response = recaptcha.challenge(self.RECAPTCHA_KEY)
            post_data = {'recaptcha_challenge_field': challenge,
                         'recaptcha_response_field': response}
            self.html = self.load(self.pyfile.url, post=post_data, decode=True)
            m = re.search(self.DIRECT_LINK_PATTERN, self.html)
            if not m:
                self.logInfo('Wrong captcha')
                self.invalidCaptcha()
            elif hasattr(m, 'group'):
                downloadURL = m.group('link')
                self.correctCaptcha()
                break
            else:
                self.fail('Unknown error - Plugin may be out of date')

        if not downloadURL:
            self.fail("No Download url retrieved/all captcha attempts failed")

        self.download(downloadURL, disposition=True)

    def handlePremium(self):
        header = self.load(self.pyfile.url, just_header=True)
        if header.has_key('location'):
            self.logDebug('DIRECT LINK from header: ' + header['location'])
            self.download(header['location'])
        else:
            self.html = self.load(self.pyfile.url, decode=True)
            self.getFileInfo()
            m = re.search(r'<a href="(?P<link>[^"]+)">Download ></a>', self.html)
            if not m:
                self.parseError('Unable to detect direct download url')
            else:
                self.logDebug('DIRECT URL from html: ' + m.group('link'))
                self.download(m.group('link'), disposition=True)


getInfo = create_getInfo(EgoFilesCom)
{'fraction_non_alphanumeric': 0.14635403246585932, 'fraction_numerical': 0.0027054882762174697, 'mean_word_length': 2.356247297881539, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 37, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596106', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2269, 'n_words': 542}