示例#1
0
def getfilefromtitle(url, title):
    # Print in the log what you will discard
    logger.info("title=" + title)
    logger.info("url=" + url)
    plataforma = config.get_system_platform()
    logger.info("platform=" + plataforma)

    # filename = xbmc.makeLegalFilename(title + url[-4:])
    from core import scrapertools

    nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
    logger.info("filename= %s" % nombrefichero)
    if "videobb" in url or "videozer" in url or "putlocker" in url:
        nombrefichero = title + ".flv"
    if "videobam" in url:
        nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

    logger.info("filename= %s" % nombrefichero)

    nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("filename= %s" % nombrefichero)

    fullpath = filetools.join(config.get_setting("downloadpath"), nombrefichero)
    logger.info("fullpath= %s" % fullpath)

    if config.is_xbmc() and fullpath.startswith("special://"):
        import xbmc
        fullpath = xbmc.translatePath(fullpath)

    return fullpath
示例#2
0
def getfilefromtitle(url, title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    logger.info("url=" + url)
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = filetools.makeLegalFilename(title + url[-4:])
    from . import scrapertools

    nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
    logger.info("nombrefichero=%s" % nombrefichero)
    if "videobb" in url or "videozer" in url or "putlocker" in url:
        nombrefichero = title + ".flv"
    if "videobam" in url:
        nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

    logger.info("nombrefichero=%s" % nombrefichero)

    nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("nombrefichero=%s" % nombrefichero)

    fullpath = filetools.join(config.get_setting("downloadpath"),
                              nombrefichero)
    logger.info("fullpath=%s" % fullpath)

    return fullpath
示例#3
0
def isfile(path, silent=False, vfs=True):
    """
    Comprueba si la ruta es un fichero
    @param path: ruta
    @type path: str
    @rtype: bool
    @return: Retorna True si la ruta existe y es un archivo
    """
    from platformcode import config
    platform = config.get_system_platform()
    path = encode(path)
    try:
        if xbmc_vfs and vfs:
            if not scrapertools.find_single_match(
                    path, '(^\w+:\/\/)') and not ('windows' in platform
                                                  and len(path) > 260):
                return os.path.isfile(path)
            if path.endswith('/') or path.endswith('\\'):
                path = path[:-1]
            dirs, files = xbmcvfs.listdir(dirname(path))
            base_name = basename(path)
            for file in files:
                if base_name == file:
                    return True
            return False
        elif path.lower().startswith("smb://"):
            return samba.isfile(path)
        else:
            return os.path.isfile(path)
    except:
        logger.error("ERROR al comprobar el archivo: %s" % path)
        if not silent:
            logger.error(traceback.format_exc())
        return False
示例#4
0
def GetTitleFromFile(title):
    # Print in the log what you will discard
    logger.info("title= " + title)
    plataforma = config.get_system_platform()
    logger.info("plataform= " + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    nombrefichero = title
    return nombrefichero
示例#5
0
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    plataforma = config.get_system_platform()
    logger.info("plataform=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    nombrefichero = title
    return nombrefichero
示例#6
0
def init_version(json_data):

    try:
        ret = False
        if json_data.get('init_version'): return ret

        categoria = config.get_system_platform()

        kodi = config.get_platform(full_version=True)
        kodi = ',k%s' % str(kodi.get('num_version')).split('.')[0]

        assistant = ''
        if categoria == 'android':
            assistant = config.get_setting('assistant_binary', default=False)
            if assistant and assistant != True:
                assistant = ',%s' % assistant
            elif assistant == True:
                assistant = ''
                from core import servertools
                torrent_json = servertools.get_server_json('torrent').get(
                    'clients', [])
                for client_block in torrent_json:
                    for client, value in list(client_block.items()):
                        if client != 'id': continue
                        if xbmc.getCondVisibility('System.HasAddon("%s")' %
                                                  value):
                            assistant = ',AstOT'
                            if 'elementum' in value:
                                assistant = ',AstEL'
                                break
                    if assistant:
                        break
            else:
                assistant = ''
                if filetools.exists(
                        filetools.join(ADDON_USERDATA_PATH,
                                       'alfa-mobile-assistant.version')):
                    version = filetools.read(
                        filetools.join(
                            ADDON_USERDATA_PATH,
                            'alfa-mobile-assistant.version')).split('.')
                    if len(version) == 3:
                        assistant = ',Ast%s' % version[1]

        try:
            if not PY3: from lib import alfaresolver
            else: from lib import alfaresolver_py3 as alfaresolver
            threading.Thread(target=alfaresolver.frequency_count, args=(Item(), \
                        [ADDON_VERSION, categoria + kodi + assistant])).start()
            ret = True
        except:
            logger.error(traceback.format_exc())

    except:
        logger.error(traceback.format_exc())

    return ret
示例#7
0
def get_cl(resp, timeout=20, debug=False, extraPostDelay=15, retry=False, blacklist=True, retryIfTimeout=True, **kwargs):
    blacklist_clear = True
    if 'hideproxy' in resp.url or 'webproxy' in resp.url or kwargs.get('proxies'):
        blacklist_clear = False
        blacklist = False
    
    if timeout < 15: timeout = 20
    if timeout + extraPostDelay > 35: timeout = 20

    domain_full = urlparse.urlparse(resp.url).netloc
    domain = domain_full
    if blacklist and not retry: 
        blacklist_clear = check_blacklist(domain_full)
    
    if blacklist_clear:
        host = config.get_system_platform()[:1]
        
        freequent_data = [domain, 'CF2,0.0.0,0,%s0,NoApp' % host]
        
        check_assistant = alfa_assistant.open_alfa_assistant(getWebViewInfo=True, retry=retry)
        if not isinstance(check_assistant, dict) and retry:
            alfa_assistant.close_alfa_assistant()
            time.sleep(2)
            check_assistant = alfa_assistant.open_alfa_assistant(getWebViewInfo=True, retry=True)
            if not check_assistant:
                time.sleep(10)
                check_assistant = alfa_assistant.get_generic_call('getWebViewInfo', timeout=2, alfa_s=True)
            
        if check_assistant and isinstance(check_assistant, dict):

            if check_assistant.get('assistantLatestVersion') and check_assistant.get('assistantVersion'):
                installed_version = check_assistant['assistantVersion'].split('.')
                available_version = check_assistant['assistantLatestVersion'].split('.')
                newer = False
                for i, ver in enumerate(available_version):
                    if int(ver) > int(installed_version[i]):
                        newer = True
                        break
                    if int(ver) < int(installed_version[i]):
                        break
                if newer:
                    help_window.show_info('cf_2_02', wait=False)

            ua = get_ua(check_assistant)
            
            try:
                vers = int(scrapertools.find_single_match(ua, r"Android\s*(\d+)"))
            except:
                vers = 0

            wvbVersion = check_assistant.get('wvbVersion', '0.0.0').split('.')[0]
            if len(wvbVersion) > 3: wvbVersion = wvbVersion[:2]
            freequent_data[1] = 'CF2,%s,%s,%s%s,' % (check_assistant.get('assistantVersion', '0.0.0'), wvbVersion, host, vers)

            if vers:
                dan = {'User-Agent': ua}
                resp.headers.update(dict(dan))
                ua = None
            else:
                ua = httptools.get_user_agent()

            logger.debug("UserAgent: %s || Android Vrs: %s" % (ua, vers))

            jscode = get_jscode(1, 'KEYCODE_ENTER', 1)

            url_cf = scrapertools.find_single_match(resp.url, '(http.*\:\/\/(?:www\S*.)?\w+\.\w+(?:\.\w+)?)(?:\/)?') + '|cf_clearance'

            data_assistant = alfa_assistant.get_urls_by_page_finished(resp.url, timeout=timeout, getCookies=True, userAgent=ua,
                                                                        disableCache=True, debug=debug, jsCode=jscode,
                                                                        extraPostDelay=extraPostDelay, clearWebCache=True, 
                                                                        removeAllCookies=True, returnWhenCookieNameFound=url_cf,
                                                                        retryIfTimeout=retryIfTimeout
                                                                        )
            logger.debug("data assistant: %s" % data_assistant)

            domain_ = domain
            split_lst = domain.split(".")

            if len(split_lst) > 2:
                domain = domain.replace(split_lst[0], "")
            
            if not domain.startswith('.'):
                domain = "."+domain
            
            get_ua(data_assistant)

            if isinstance(data_assistant, dict) and data_assistant.get("cookies", None):

                logger.debug("Lista cookies: %s" % data_assistant.get("cookies", []))
                for cookie in data_assistant["cookies"]:
                    cookieslist = cookie.get("cookiesList", None)
                    val = scrapertools.find_single_match(cookieslist, 'cf_clearance=([A-z0-9_-]+)')
                    dom = cookie.get("urls", None)
                    logger.debug("dominios: %s" % dom[0])

                    if 'cf_clearance' in cookieslist and val:
                        
                        dict_cookie = {'domain': domain,
                                       'name': 'cf_clearance',
                                       'value': val}
                        if domain_ in dom[0]:
                            httptools.set_cookies(dict_cookie)
                            rin = {'Server': 'Alfa'}

                            resp.headers.update(dict(rin))
                            logger.debug("cf_clearence=%s" % val)
                            
                            if not retry:
                                freequent_data[1] += 'OK'
                            else:
                                freequent_data[1] += 'OK_R'
                            freequency(freequent_data)

                            return resp

                    else:
                        logger.error("No cf_clearance")
                else:
                    freequent_data[1] += 'NO-CFC'
            else:
                freequent_data[1] += 'ERR'
                logger.error("No Cookies o Error en conexión con Alfa Assistant")

            if not retry:
                config.set_setting('cf_assistant_ua', '')
                logger.debug("No se obtuvieron resultados, reintentando...")
                return get_cl(resp, timeout=timeout-5, extraPostDelay=extraPostDelay, \
                            retry=True, blacklist=True, retryIfTimeout=False, **kwargs)
        elif host == 'a':
            help_window.show_info('cf_2_01')
        
        freequency(freequent_data)
        
        if filetools.exists(PATH_BL):
            bl_data = jsontools.load(filetools.read(PATH_BL))
        else:
            bl_data = {}
        bl_data[domain_full] = time.time()
        filetools.write(PATH_BL, jsontools.dump(bl_data))

    msg = 'Detected a Cloudflare version 2 Captcha challenge,\
        This feature is not available in the opensource (free) version.'
    resp.status_code = msg
    
    raise CloudflareChallengeError(msg)
示例#8
0
def get_environment():
    """
    Devuelve las variables de entorno del OS, de Kodi y de Alfa más habituales,
    necesarias para el diagnóstico de fallos 
    """

    try:
        import base64
        import ast
        
        PLATFORM = config.get_system_platform()
        
        environment = config.get_platform(full_version=True)
        environment['num_version'] = str(environment['num_version'])
        environment['python_version'] = '%s (%s, %s)' % (str(platform.python_version()), \
                    str(sys.api_version), str(platform.python_implementation()))
        environment['os_release'] = str(platform.release())
        environment['prod_model'] = ''
        try:
            import multiprocessing
            environment['proc_num'] = ' (%sx)' % str(multiprocessing.cpu_count())
        except:
            environment['proc_num'] = ''
        
        if PLATFORM in ['windows', 'xbox']:
            environment['os_name'] = PLATFORM.capitalize()
            try:
                if platform.platform():
                    environment['os_release'] = str(platform.platform()).replace('Windows-', '')
                elif platform._syscmd_ver()[2]:
                    environment['os_release'] = str(platform._syscmd_ver()[2])
                
                command = ["wmic", "cpu", "get", "name"]
                p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=0x08000000)
                output_cmd, error_cmd = p.communicate()
                if PY3 and isinstance(output_cmd, bytes):
                    output_cmd = output_cmd.decode()
                output_cmd = re.sub(r'\n|\r|\s{2}', '', output_cmd)
                environment['prod_model'] = str(scrapertools.find_single_match(output_cmd, \
                                '\w+.*?(?i)(?:Intel\(R\))?(?:\s*Core\(TM\))\s*(.*?CPU.*?)\s*(?:\@|$)'))
            except:
                pass
        
        elif PLATFORM in ['android', 'atv2']:
            environment['os_name'] = PLATFORM.capitalize()
            try:
                for label_a in subprocess.check_output('getprop').split(FF):
                    if PY3 and isinstance(label_a, bytes):
                        label_a = label_a.decode()
                    if 'build.version.release' in label_a:
                        environment['os_release'] = str(scrapertools.find_single_match(label_a, ':\s*\[(.*?)\]$'))
                    if 'product.model' in label_a:
                        environment['prod_model'] = str(scrapertools.find_single_match(label_a, ':\s*\[(.*?)\]$'))
            except:
                try:
                    for label_a in filetools.read(os.environ['ANDROID_ROOT'] + '/build.prop').split():
                        if PY3 and isinstance(label_a, bytes):
                            label_a = label_a.decode()
                        if 'build.version.release' in label_a:
                            environment['os_release'] = str(scrapertools.find_single_match(label_a, '=(.*?)$'))
                        if 'product.model' in label_a:
                            environment['prod_model'] = str(scrapertools.find_single_match(label_a, '=(.*?)$'))
                except:
                    pass
            environment['prod_model'] += ' (%s)' % config.is_rooted(silent=True)
        
        elif PLATFORM in ['linux']:
            environment['os_name'] = PLATFORM.capitalize()
            try:
                for label_a in subprocess.check_output('hostnamectl').split(FF):
                    if PY3 and isinstance(label_a, bytes):
                        label_a = label_a.decode()
                    if 'Operating' in label_a:
                        environment['os_release'] = str(scrapertools.find_single_match(label_a, 'Operating\s*S\w+:\s*(.*?)\s*$'))
                        break
                        
                for label_a in subprocess.check_output(['cat', '/proc/cpuinfo']).split(FF):
                    if PY3 and isinstance(label_a, bytes):
                        label_a = label_a.decode()
                    if 'model name' in label_a:
                        environment['prod_model'] = str(scrapertools.find_single_match(label_a, \
                                'model.*?:\s*(?i)(?:Intel\(R\))?(?:\s*Core\(TM\))\s*(.*?CPU.*?)\s*(?:\@|$)'))
                        break
            except:
                pass

        elif PLATFORM in ['raspberry']:
            environment['os_name'] = 'RaspberryPi'
        
        else:
            environment['os_name'] = str(PLATFORM.capitalize())

        if not environment['os_release']: environment['os_release'] = str(platform.release())
        if environment['proc_num'] and environment['prod_model']: environment['prod_model'] += environment['proc_num']
        environment['machine'] = str(platform.machine())
        environment['architecture'] = str(sys.maxsize > 2 ** 32 and "64-bit" or "32-bit")
        environment['language'] = str(xbmc.getInfoLabel('System.Language'))

        environment['cpu_usage'] = str(xbmc.getInfoLabel('System.CpuUsage'))
        
        environment['mem_total'] = str(xbmc.getInfoLabel('System.Memory(total)')).replace('MB', '').replace('KB', '')
        environment['mem_free'] = str(xbmc.getInfoLabel('System.Memory(free)')).replace('MB', '').replace('KB', '')
        if not environment['mem_total'] or not environment['mem_free']:
            try:
                if environment['os_name'].lower() in ['windows', 'xbox']:
                    kernel32 = ctypes.windll.kernel32
                    c_ulong = ctypes.c_ulong
                    c_ulonglong = ctypes.c_ulonglong
                    class MEMORYSTATUS(ctypes.Structure):
                        _fields_ = [
                            ('dwLength', c_ulong),
                            ('dwMemoryLoad', c_ulong),
                            ('dwTotalPhys', c_ulonglong),
                            ('dwAvailPhys', c_ulonglong),
                            ('dwTotalPageFile', c_ulonglong),
                            ('dwAvailPageFile', c_ulonglong),
                            ('dwTotalVirtual', c_ulonglong),
                            ('dwAvailVirtual', c_ulonglong),
                            ('availExtendedVirtual', c_ulonglong)
                        ]
                 
                    memoryStatus = MEMORYSTATUS()
                    memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUS)
                    kernel32.GlobalMemoryStatus(ctypes.byref(memoryStatus))
                    environment['mem_total'] = str(old_div(int(memoryStatus.dwTotalPhys), (1024**2)))
                    environment['mem_free'] = str(old_div(int(memoryStatus.dwAvailPhys), (1024**2)))

                else:
                    with open('/proc/meminfo') as f:
                        meminfo = f.read()
                    environment['mem_total'] = str(old_div(int(re.search(r'MemTotal:\s+(\d+)', meminfo).groups()[0]), 1024))
                    environment['mem_free'] = str(old_div(int(re.search(r'MemAvailable:\s+(\d+)', meminfo).groups()[0]), 1024))
            except:
                environment['mem_total'] = ''
                environment['mem_free'] = ''
            
        try:
            environment['kodi_buffer'] = '20'
            environment['kodi_bmode'] = '0'
            environment['kodi_rfactor'] = '4.0'
            if filetools.exists(filetools.join("special://userdata", "advancedsettings.xml")):
                advancedsettings = filetools.read(filetools.join("special://userdata", 
                                "advancedsettings.xml")).split('\n')
                for label_a in advancedsettings:
                    if 'memorysize' in label_a:
                        environment['kodi_buffer'] = str(old_div(int(scrapertools.find_single_match
                                (label_a, '>(\d+)<\/')), 1024**2))
                    if 'buffermode' in label_a:
                        environment['kodi_bmode'] = str(scrapertools.find_single_match
                                (label_a, '>(\d+)<\/'))
                    if 'readfactor' in label_a:
                        environment['kodi_rfactor'] = str(scrapertools.find_single_match
                                (label_a, '>(.*?)<\/'))
        except:
            pass
        
        environment['userdata_path'] = str(config.get_data_path())
        environment['userdata_path_perm'] = filetools.file_info(environment['userdata_path'])
        if not environment['userdata_path_perm']: del environment['userdata_path_perm']
        try:
            if environment['os_name'].lower() in ['windows', 'xbox']:
                free_bytes = ctypes.c_ulonglong(0)
                ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(environment['userdata_path']), 
                                None, None, ctypes.pointer(free_bytes))
                environment['userdata_free'] = str(round(float(free_bytes.value) / (1024**3), 3))
            else:
                disk_space = os.statvfs(environment['userdata_path'])
                if not disk_space.f_frsize: disk_space.f_frsize = disk_space.f_frsize.f_bsize
                environment['userdata_free'] = str(round((float(disk_space.f_bavail) / \
                                (1024**3)) * float(disk_space.f_frsize), 3))
        except:
            environment['userdata_free'] = '?'
        
        if environment.get('userdata_path_perm', ''):
            environment['userdata_path'] = environment['userdata_path_perm']
            del environment['userdata_path_perm']
        environment['torrent_lang'] = '%s/%s' % (config.get_setting("channel_language", default="").upper(), \
                                config.get_setting("second_language", default="").upper())

        try:
            environment['videolab_series'] = '?'
            environment['videolab_episodios'] = '?'
            environment['videolab_pelis'] = '?'
            environment['videolab_path'] = str(config.get_videolibrary_path())
            environment['videolab_path_perm'] = filetools.file_info(environment['videolab_path'])
            if not environment['videolab_path_perm']:
                environment['videolab_path_perm'] = environment['videolab_path']
            if filetools.exists(filetools.join(environment['videolab_path'], \
                                config.get_setting("folder_tvshows"))):
                environment['videolab_series'] = str(len(filetools.listdir(filetools.join(environment['videolab_path'], \
                                config.get_setting("folder_tvshows")))))
                counter = 0
                for root, folders, files in filetools.walk(filetools.join(environment['videolab_path'], \
                                    config.get_setting("folder_tvshows"))):
                    for file in files:
                        if file.endswith('.strm'): counter += 1
                environment['videolab_episodios'] = str(counter)
            if filetools.exists(filetools.join(environment['videolab_path'], \
                                config.get_setting("folder_movies"))):
                environment['videolab_pelis'] = str(len(filetools.listdir(filetools.join(environment['videolab_path'], \
                                config.get_setting("folder_movies")))))
        except:
            pass
        try:
            video_updates = ['No', 'Inicio', 'Una vez', 'Inicio+Una vez', 'Dos veces al día']
            environment['videolab_update'] = str(video_updates[config.get_setting("update", "videolibrary")])
            if config.get_setting("videolibrary_backup_scan", "videolibrary", default=False):
                environment['videolab_update'] += ' (Solo SCAN)'
        except:
            environment['videolab_update'] = '?'
        try:
            if environment['os_name'].lower() in ['windows', 'xbox']:
                free_bytes = ctypes.c_ulonglong(0)
                ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(environment['videolab_path']), 
                                None, None, ctypes.pointer(free_bytes))
                environment['videolab_free'] = str(round(float(free_bytes.value) / (1024**3), 3))
            else:
                disk_space = os.statvfs(environment['videolab_path'])
                if not disk_space.f_frsize: disk_space.f_frsize = disk_space.f_frsize.f_bsize
                environment['videolab_free'] = str(round((float(disk_space.f_bavail) / \
                                (1024**3)) * float(disk_space.f_frsize), 3))
        except:
            environment['videolab_free'] = '?'

        torrent_paths = torrent_dirs()
        environment['torrent_list'] = []
        environment['torrentcli_option'] = ''
        environment['torrent_error'] = ''
        environment['torrentcli_rar'] = config.get_setting("mct_rar_unpack", server="torrent", default=True)
        environment['torrentcli_backgr'] = config.get_setting("mct_background_download", server="torrent", default=True)
        environment['torrentcli_lib_path'] = config.get_setting("libtorrent_path", server="torrent", default="")
        
        if environment['torrentcli_lib_path']:
            lib_path = 'Activo'
        else:
            lib_path = 'Inactivo'
        if config.get_setting("libtorrent_version", server="torrent", default=""):
            lib_path += '-%s' % config.get_setting("libtorrent_version", server="torrent", default="")
        environment['torrentcli_unrar'] = config.get_setting("unrar_path", server="torrent", default="")
        if environment['torrentcli_unrar']:
            unrar = config.get_setting("unrar_device", server="torrent", default="").capitalize()
        else:
            unrar = 'Inactivo'
        torrent_id = config.get_setting("torrent_client", server="torrent", default=0)
        environment['torrentcli_option'] = str(torrent_id)
        torrent_options = platformtools.torrent_client_installed()
        if lib_path != 'Inactivo':
            torrent_options = [': MCT'] + torrent_options
            torrent_options = [': BT'] + torrent_options
        environment['torrent_list'].append({'Torrent_opt': str(torrent_id), 'Libtorrent': lib_path, \
                                            'RAR_Auto': str(environment['torrentcli_rar']), \
                                            'RAR_backgr': str(environment['torrentcli_backgr']), \
                                            'UnRAR': unrar})
        environment['torrent_error'] = config.get_setting("libtorrent_error", server="torrent", default="")
        if environment['torrent_error']:
            environment['torrent_list'].append({'Libtorrent_error': environment['torrent_error']})

        for torrent_option in torrent_options:
            cliente = dict()
            cliente['D_load_Path'] = ''
            cliente['Libre'] = '?'
            cliente['Plug_in'] = scrapertools.find_single_match(torrent_option, ':\s*(\w+)')
            if cliente['Plug_in'] not in ['BT', 'MCT']: cliente['Plug_in'] = cliente['Plug_in'].capitalize()
            
            cliente['D_load_Path'] = torrent_paths[cliente['Plug_in'].upper()]
            cliente['D_load_Path_perm'] = filetools.file_info(cliente['D_load_Path'])
            cliente['Buffer'] = str(torrent_paths[cliente['Plug_in'].upper()+'_buffer'])
            cliente['Version'] = str(torrent_paths[cliente['Plug_in'].upper()+'_version'])
            if cliente['Plug_in'].upper() == 'TORREST':
                cliente['Buffer'] = str(int(int(torrent_paths[cliente['Plug_in'].upper()+'_buffer']) /(1024*1024)))
                bin_path = filetools.join('special://home', 'addons', 'plugin.video.torrest', 'resources', 'bin')
                if filetools.exists(bin_path):
                    cliente['Platform'] = str(filetools.listdir(bin_path)[0])
                else:
                    cliente['Platform'] = 'None'
                try:
                    __settings__ = xbmcaddon.Addon(id="plugin.video.torrest")
                    cliente['Platform'] += ': %s: %s:%s' % (str(__settings__.getSetting("service_enabled")), \
                                    str(__settings__.getSetting("service_ip")), str(__settings__.getSetting("port")))
                except:
                    pass
                #cliente['Options'] = str(filetools.read(filetools.join('special://masterprofile', \
                #                    'addon_data', 'plugin.video.torrest', 'settings.xml')))
            if torrent_paths.get(cliente['Plug_in'].upper()+'_memory_size', ''):
                cliente['Memoria'] = str(torrent_paths[cliente['Plug_in'].upper()+'_memory_size'])
            
            if cliente.get('D_load_Path', ''):
                try:
                    if environment['os_name'].lower() in ['windows', 'xbox']:
                        free_bytes = ctypes.c_ulonglong(0)
                        ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(cliente['D_load_Path']), 
                                    None, None, ctypes.pointer(free_bytes))
                        cliente['Libre'] = str(round(float(free_bytes.value) / \
                                    (1024**3), 3)).replace('.', ',')
                    else:
                        disk_space = os.statvfs(cliente['D_load_Path'])
                        if not disk_space.f_frsize: disk_space.f_frsize = disk_space.f_frsize.f_bsize
                        cliente['Libre'] = str(round((float(disk_space.f_bavail) / \
                                    (1024**3)) * float(disk_space.f_frsize), 3)).replace('.', ',')
                except:
                    pass
                if cliente.get('D_load_Path_perm', ''):
                    cliente['D_load_Path'] = cliente['D_load_Path_perm']
                    del cliente['D_load_Path_perm']
            environment['torrent_list'].append(cliente)

        environment['proxy_active'] = ''
        try:
            proxy_channel_bloqued_str = base64.b64decode(config.get_setting('proxy_channel_bloqued')).decode('utf-8')
            proxy_channel_bloqued = dict()
            proxy_channel_bloqued = ast.literal_eval(proxy_channel_bloqued_str)
            for channel_bloqued, proxy_active in list(proxy_channel_bloqued.items()):
                if proxy_active != 'OFF':
                    environment['proxy_active'] += channel_bloqued + ', '
        except:
            pass
        if not environment['proxy_active']: environment['proxy_active'] = 'OFF'
        environment['proxy_active'] = environment['proxy_active'].rstrip(', ')

        for root, folders, files in filetools.walk("special://logpath/"):
            for file in files:
                if file.lower() in ['kodi.log', 'jarvis.log', 'spmc.log', 'cemc.log', \
                                    'mygica.log', 'wonderbox.log', 'leiapp,log', \
                                    'leianmc.log', 'kodiapp.log', 'anmc.log', \
                                    'latin-anmc.log']:
                    environment['log_path'] = str(filetools.join(root, file))
                    break
            else:
                environment['log_path'] = ''
            break
        
        if environment.get('log_path', ''):
            environment['log_size_bytes'] = str(filetools.getsize(environment['log_path']))
            environment['log_size'] = str(round(float(environment['log_size_bytes']) / \
                                (1024*1024), 3))
        else:
            environment['log_size_bytes'] = ''
            environment['log_size'] = ''
        
        environment['debug'] = str(config.get_setting('debug'))
        environment['addon_version'] = '%s (Upd: %s h.)' % (str(config.get_addon_version(from_xml=True)), \
                                str(config.get_setting("addon_update_timer", default=12)).replace('0', 'No'))

        environment['assistant_version'] = str(None)
        if filetools.exists(filetools.join(config.get_data_path(), 'alfa-mobile-assistant.version')):
            environment['assistant_version'] = filetools.read(filetools.join(config.get_data_path(), 'alfa-mobile-assistant.version'))
        environment['assistant_version'] += '; Req: %s' % str(config.get_setting('assistant_binary', default=False))
        environment['assistant_cf_ua'] = str(config.get_setting('cf_assistant_ua', default=None))
        assistant_path = filetools.join(os.getenv('ANDROID_STORAGE'), 'emulated', '0', 'Android', 'data', 'com.alfa.alfamobileassistant')
        if PLATFORM in ['android', 'atv2'] and filetools.exists(assistant_path):
            environment['assistant_path'] = str(filetools.file_info(assistant_path))
    
    except:
        logger.error(traceback.format_exc())
        environment = {}
        environment['log_size'] = ''
        environment['cpu_usage'] = ''
        environment['python_version'] = ''
        environment['log_path'] = ''
        environment['userdata_free'] = ''
        environment['mem_total'] = ''
        environment['machine'] = ''
        environment['platform'] = ''
        environment['videolab_path'] = ''
        environment['num_version'] = ''
        environment['os_name'] = ''
        environment['video_db'] = ''
        environment['userdata_path'] = ''
        environment['log_size_bytes'] = ''
        environment['name_version'] = ''
        environment['language'] = ''
        environment['mem_free'] = ''
        environment['prod_model'] = ''
        environment['proxy_active'] = ''
        environment['architecture'] = ''
        environment['os_release'] = ''
        environment['videolab_free'] = ''
        environment['kodi_buffer'] = ''
        environment['kodi_bmode'] = ''
        environment['kodi_rfactor'] = ''
        environment['videolab_series'] = ''
        environment['videolab_episodios'] = ''
        environment['videolab_pelis'] = ''
        environment['videolab_update'] = ''
        environment['videolab_path_perm'] = ''
        environment['debug'] = ''
        environment['addon_version'] = ''
        environment['torrent_list'] = []
        environment['torrent_lang'] = ''
        environment['torrentcli_option'] = ''
        environment['torrentcli_rar'] = ''
        environment['torrentcli_lib_path'] = ''
        environment['torrentcli_unrar'] = ''
        environment['torrent_error'] = ''
        environment['assistant_version'] = ''
        environment['assistant_cf_ua'] = ''
        
    return environment
示例#9
0
def get_source(url,
               resp,
               timeout=5,
               debug=False,
               extraPostDelay=5,
               retry=False,
               blacklist=True,
               headers=None,
               retryIfTimeout=True,
               cache=False,
               clearWebCache=False,
               mute=True,
               alfa_s=False,
               elapsed=0,
               **kwargs):
    blacklist_clear = True
    data = ''
    source = False
    if not elapsed: elapsed = time.time()
    elapsed_max = 40
    expiration = config.get_setting('cf_assistant_bl_expiration',
                                    default=30) * 60
    expiration_final = 0
    security_error_blackout = (5 * 60) - expiration

    if debug: alfa_s = False

    if not resp:
        resp = {'status_code': 429, 'headers': {}}
        resp = type('HTTPResponse', (), resp)

    if not alfa_s: logger.debug("ERROR de descarga: %s" % resp.status_code)

    opt = kwargs.get('opt', {})

    domain_full = urlparse.urlparse(url).netloc
    domain = domain_full
    pcb = base64.b64decode(
        config.get_setting('proxy_channel_bloqued')).decode('utf-8')
    if 'hideproxy' in url or 'webproxy' in url or 'hidester' in url or '__cpo=' in url  \
                          or httptools.TEST_ON_AIR or domain in pcb:
        blacklist_clear = False
        blacklist = False

    if timeout + extraPostDelay > 35: timeout = 20

    if blacklist and not retry:
        blacklist_clear = check_blacklist(domain_full)

    host = config.get_system_platform()[:1]
    freequent_data = [domain, 'Cha,0.0.0,0,%s0,BlakL' % host]
    if blacklist_clear:
        freequent_data = [domain, 'Cha,0.0.0,0,%s0,App' % host]
        if not retry:
            freequent_data[1] += 'KO'
        else:
            freequent_data[1] += 'KO_R'

        check_assistant = alfa_assistant.open_alfa_assistant(
            getWebViewInfo=True, retry=True, assistantLatestVersion=False)
        if not isinstance(check_assistant, dict) and not retry:
            alfa_assistant.close_alfa_assistant()
            time.sleep(2)
            check_assistant = alfa_assistant.open_alfa_assistant(
                getWebViewInfo=True, retry=True, assistantLatestVersion=False)
            logger.debug("Reintento en acceder al Assistant: %s - %s" \
                         % ('OK' if isinstance(check_assistant, dict) else 'ERROR', time.time() - elapsed))

        if check_assistant and isinstance(check_assistant, dict):

            if check_assistant.get(
                    'assistantLatestVersion') and check_assistant.get(
                        'assistantVersion'):
                installed_version = check_assistant['assistantVersion'].split(
                    '.')
                available_version = check_assistant[
                    'assistantLatestVersion'].split('.')
                newer = False
                for i, ver in enumerate(available_version):
                    if int(ver) > int(installed_version[i]):
                        newer = True
                        break
                    if int(ver) < int(installed_version[i]):
                        break
                if newer:
                    help_window.show_info('cf_2_02', wait=False)

            ua = get_ua(check_assistant)

            try:
                vers = int(
                    scrapertools.find_single_match(ua, r"Android\s*(\d+)"))
            except:
                vers = 0

            wvbVersion = check_assistant.get('wvbVersion',
                                             '0.0.0').split('.')[0]
            if len(wvbVersion) > 3: wvbVersion = wvbVersion[:2]
            freequent_data[1] = 'Cha,%s,%s,%s%s,' % (check_assistant.get(
                'assistantVersion', '0.0.0'), wvbVersion, host, vers)
            if not retry:
                freequent_data[1] += 'Src'
            else:
                freequent_data[1] += 'Src_R'

            if vers:
                dan = {'User-Agent': ua}
                resp.headers.update(dict(dan))
                ua = None
            else:
                ua = httptools.get_user_agent()

            if not alfa_s:
                logger.debug("UserAgent: %s || Android Vrs: %s" % (ua, vers))

            jscode = None

            url_cf = scrapertools.find_single_match(
                url, '(http.*\:\/\/(?:www\S*.)?\w+\.\w+(?:\.\w+)?)(?:\/)?'
            ) + '|cf_clearance'

            data_assistant = alfa_assistant.get_source_by_page_finished(
                url,
                timeout=timeout,
                getCookies=True,
                userAgent=ua,
                disableCache=cache,
                debug=debug,
                jsCode=jscode,
                extraPostDelay=extraPostDelay,
                clearWebCache=clearWebCache,
                removeAllCookies=True,
                returnWhenCookieNameFound=url_cf,
                retryIfTimeout=retryIfTimeout,
                useAdvancedWebView=True,
                headers=headers,
                mute=mute,
                alfa_s=alfa_s)
            if not alfa_s: logger.debug("data assistant: %s" % data_assistant)

            if isinstance(data_assistant, dict) and data_assistant.get('htmlSources', []) \
                                                and data_assistant['htmlSources'][0].get('source', ''):
                try:
                    data = base64.b64decode(data_assistant['htmlSources'][0]
                                            ['source']).decode('utf-8')
                    source = True
                except:
                    pass

                if source and 'accessing a cross-origin frame' in data:
                    source = False
                    retry = True
                    expiration_final = security_error_blackout
                    freequent_data[1] = 'Cha,%s,%s,%s%s,' % (
                        check_assistant.get('assistantVersion',
                                            '0.0.0'), wvbVersion, host, vers)
                    freequent_data[1] += 'KO_SecE'
                    logger.error('Error SEGURIDAD: %s - %s' %
                                 (expiration_final, data[:100]))

                if source:
                    freequent_data[1] = 'Cha,%s,%s,%s%s,' % (
                        check_assistant.get('assistantVersion',
                                            '0.0.0'), wvbVersion, host, vers)
                    if not retry:
                        freequent_data[1] += 'OK'
                    else:
                        freequent_data[1] += 'OK_R'

            if not source and not retry:
                config.set_setting('cf_assistant_ua', '')
                logger.debug("No se obtuvieron resultados, reintentando...")
                timeout = -1 if timeout < 0 else timeout * 2
                extraPostDelay = -1 if extraPostDelay < 0 else extraPostDelay * 2
                return get_source(url,
                                  resp,
                                  timeout=timeout,
                                  debug=debug,
                                  extraPostDelay=extraPostDelay,
                                  retry=True,
                                  blacklist=blacklist,
                                  retryIfTimeout=retryIfTimeout,
                                  cache=cache,
                                  clearWebCache=clearWebCache,
                                  alfa_s=False,
                                  headers=headers,
                                  mute=mute,
                                  elapsed=elapsed,
                                  **kwargs)

            domain_ = domain
            split_lst = domain.split(".")

            if len(split_lst) > 2:
                domain = domain.replace(split_lst[0], "")

            if not domain.startswith('.'):
                domain = "." + domain

            get_ua(data_assistant)

            if isinstance(data_assistant, dict) and data_assistant.get(
                    "cookies", None):

                if not alfa_s:
                    logger.debug("Lista cookies: %s" %
                                 data_assistant.get("cookies", []))
                for cookie in data_assistant["cookies"]:
                    cookieslist = cookie.get("cookiesList", None)
                    val = scrapertools.find_single_match(
                        cookieslist, 'cf_clearance=([A-z0-9_\-\.]+)')
                    #val = scrapertools.find_single_match(cookieslist, 'cf_clearance=([^;]+)')
                    dom = cookie.get("urls", None)
                    if not alfa_s: logger.debug("dominios: %s" % dom[0])

                    if 'cf_clearance' in cookieslist and val:

                        dict_cookie = {
                            'domain': domain,
                            'name': 'cf_clearance',
                            'value': val
                        }
                        if domain_ in dom[0]:
                            httptools.set_cookies(dict_cookie)
                            rin = {'Server': 'Alfa'}

                            resp.headers.update(dict(rin))
                            freequent_data[1] += 'C'
                            if not alfa_s:
                                logger.debug("cf_clearence=%s" % val)

        elif host == 'a':
            help_window.show_info('cf_2_01')

    freequency(freequent_data)

    if blacklist_clear and (not source or time.time() - elapsed > elapsed_max):
        if filetools.exists(PATH_BL):
            bl_data = jsontools.load(filetools.read(PATH_BL))
        else:
            bl_data = {}
        if time.time() - elapsed > elapsed_max:
            bl_data[domain_full] = time.time() + elapsed_max * 10 * 60
        else:
            bl_data[domain_full] = time.time() + expiration_final
        if not debug and not httptools.TEST_ON_AIR:
            filetools.write(PATH_BL, jsontools.dump(bl_data))
    if not source:
        resp.status_code = 429
    else:
        resp.status_code = 200

    return data, resp
示例#10
0
文件: updater.py 项目: lopezvg/addon
def check_dependencies(in_folder):
    """ Check is patch applies to current installed version
    Dependencies file is optional and named alfa_dependencies.json
    
    Optional paramenters:
    
    - patch_platforms: [list of patch-supportted platforms]
    - patch_python: python version i.e. Py2, Py3
    - patch_version_high: version number for patch to apply.  If patch_version_low param exists, it marks the highest version applicable
    - patch_version_low: marks the lowest version applicable for the patch.  It requires patch_version_high set
    
    Note:   version and sub-versions are separated by "." (slots).  Any version/sub-versions number can be a wild character "*"
            version/sub-versions slots number must be the same as the add-on to be patched
    
    """

    res = True
    dep_path = os.path.join(in_folder, ALFA_DEPENDENCIES)

    if not os.path.exists(dep_path):
        return res

    try:
        import xbmcaddon
        addon_name = os.path.split(in_folder)[1]
        __settings__ = xbmcaddon.Addon(id="{}".format(addon_name))
        addon_version = __settings__.getAddonInfo('version').split('.')
    except:
        return False

    try:
        with open(dep_path, "r") as f:
            dep_json = jsontools.load(f.read())

        if dep_json.get('patch_platforms', []):
            # Check for PLATFORM
            if config.get_system_platform() not in dep_json['patch_platforms']:
                return False

        if dep_json.get('patch_python',
                        '') and dep_json['patch_python'] in ['Py2', 'Py3']:
            # Check for PYTHON version
            if PY3 and dep_json['patch_python'] != 'Py3':
                return False
            if not PY3 and dep_json['patch_python'] == 'Py3':
                return False

        if dep_json.get('patch_version_high', []):
            # Check for Version or Vesion highest
            for x, ver in enumerate(addon_version):
                if dep_json['patch_version_high'].split(
                        '.')[x] == ver or dep_json['patch_version_high'].split(
                            '.')[x] == '*':
                    continue
                elif dep_json['patch_version_high'].split(
                        '.')[x] > ver and dep_json.get('patch_version_low',
                                                       []):
                    break
                elif dep_json['patch_version_high'].split('.')[x] > ver:
                    return False
                elif not dep_json.get('patch_version_low', []):
                    return res
                elif dep_json.get('patch_version_low', []):
                    break
            else:
                return res

            # Check for Version lowest
            if dep_json.get('patch_version_low', []):
                for x, ver in enumerate(addon_version):
                    if dep_json['patch_version_low'].split('.')[
                            x] == ver or dep_json['patch_version_low'].split(
                                '.')[x] == '*':
                        continue
                    elif dep_json['patch_version_low'].split('.')[x] > ver:
                        return False
                    return res

    except:
        logger.error(traceback.format_exc())

    return res
示例#11
0
#from builtins import str
from builtins import range
from past.utils import old_div
import sys
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int; basestring = str

import os
import re
import traceback

from core.scrapertools import find_single_match
from core.item import Item
from platformcode import logger, config

platform = config.get_system_platform()

if config.is_xbmc():
    KODI = True
    import xbmc
else:
    KODI = False

xbmc_vfs = True                                                 # False para desactivar XbmcVFS, True para activar
if xbmc_vfs:
    try:
        import xbmcvfs
        if not PY3:
            reload(sys)                                         ### Workoround Python 2
            sys.setdefaultencoding('utf-8')                     # xbmcvfs degrada el valor de defaultencoding.  Se reestablece
        xbmc_vfs = True