# Path: core/logger.py
# def log_enable(active):
# def encode_log(message=""):
# def get_caller(message=None):
# def info(texto=""):
# def debug(texto=""):
# def error(texto=""):
# 
# Path: core/scrapertools.py
# def cache_page(url,post=None,headers=None,modo_cache=None, timeout=None):
# def cachePage(url,post=None,headers=None,modoCache=None, timeout=None):
# def downloadpage(url,post=None,headers=None, follow_redirects=True, timeout=None, header_to_get=None):
# def downloadpageWithResult(url,post=None,headers=None,follow_redirects=True, timeout=None, header_to_get=None):
# def downloadpageWithoutCookies(url):
# def downloadpageGzip(url):
# def getLocationHeaderFromResponse(url):
# def get_header_from_response(url, header_to_get="", post=None, headers=None, follow_redirects=False):
# def get_headers_from_response(url, post=None, headers=None, follow_redirects=False):
# def read_body_and_headers(url, post=None, headers=None, follow_redirects=False, timeout=None):
# def anti_cloudflare(url, headers=None, post=None):
# def printMatches(matches):
# def get_match(data,patron,index=0):
# def find_single_match(data,patron,index=0):
# def find_multiple_matches(text,pattern):
# def entityunescape(cadena):
# def unescape(text):
#     def fixup(m):
# def decodeHtmlentities(string):
#     def substitute_entity(match):
# def entitiesfix(string):
# def htmlclean(cadena):
# def slugify(title):
# def remove_htmltags(string):
# def remove_show_from_title(title,show):
# def getRandom(str):
# def unseo(cadena):
# def get_filename_from_url(url):
# def get_domain_from_url(url):
# def get_season_and_episode(title):
# def get_sha1(cadena):
# def get_md5(cadena):
# def internet(host="8.8.8.8", port=53, timeout=3):
# def wait_for_internet(wait=30, retry=5):
# 
# Path: platformcode/platformtools.py
# def dialog_ok(heading, line1, line2="", line3=""):
# def dialog_notification(heading, message, icon=0, time=5000, sound=True):
# def dialog_yesno(heading, line1, line2="", line3="", nolabel="No", yeslabel="Si", autoclose=""):
# def dialog_select(heading, _list):
# def dialog_progress(heading, line1, line2="", line3=""):
# def dialog_progress_bg(heading, message=""):
# def dialog_input(default="", heading="", hidden=False):
# def dialog_numeric(_type, heading, default=""):
# def itemlist_refresh():
# def itemlist_update(item):
# def render_items(itemlist, parentitem):
# def is_playing():
# def play_video(item):
# def show_channel_settings(list_controls=None, dict_values=None, caption="", callback=None, item=None,
#                           custom_button=None):
# def show_video_info(data, caption="", callback=None, item=None):


import os
import sys
import traceback
        import re
    import time
        import shutil
from core import logger
from core import scrapertools
from platformcode import platformtools
  from lib.sambatools import libsmb as samba
    top = encode(top)
    if top.lower().startswith("smb://"):
        for a, b, c in samba.walk(top, topdown, onerror):
            # list(b) es para que haga una copia del listado de directorios
            # si no da error cuando tiene que entrar recursivamente en directorios con caracteres especiales
            yield decode(a), decode(list(b)), decode(c)
    else:
        for a, b, c in os.walk(top, topdown, onerror):
            # list(b) es para que haga una copia del listado de directorios
            # si no da error cuando tiene que entrar recursivamente en directorios con caracteres especiales
            yield decode(a), decode(list(b)), decode(c)



def listdir(path):
    """
    Lista un directorio
    @param path: Directorio a listar, debe ser un str "UTF-8"
    @type path: str
    @rtype: str
    @return: contenido de un directorio
    """

    path = encode(path)
    try:
      if path.lower().startswith("smb://"):
          return decode(samba.listdir(path))
      else:
          return decode(os.listdir(path))
    except:

# Path: core/logger.py
# def log_enable(active):
# def encode_log(message=""):
# def get_caller(message=None):
# def info(texto=""):
# def debug(texto=""):
# def error(texto=""):
# 
# Path: core/scrapertools.py
# def cache_page(url,post=None,headers=None,modo_cache=None, timeout=None):
# def cachePage(url,post=None,headers=None,modoCache=None, timeout=None):
# def downloadpage(url,post=None,headers=None, follow_redirects=True, timeout=None, header_to_get=None):
# def downloadpageWithResult(url,post=None,headers=None,follow_redirects=True, timeout=None, header_to_get=None):
# def downloadpageWithoutCookies(url):
# def downloadpageGzip(url):
# def getLocationHeaderFromResponse(url):
# def get_header_from_response(url, header_to_get="", post=None, headers=None, follow_redirects=False):
# def get_headers_from_response(url, post=None, headers=None, follow_redirects=False):
# def read_body_and_headers(url, post=None, headers=None, follow_redirects=False, timeout=None):
# def anti_cloudflare(url, headers=None, post=None):
# def printMatches(matches):
# def get_match(data,patron,index=0):
# def find_single_match(data,patron,index=0):
# def find_multiple_matches(text,pattern):
# def entityunescape(cadena):
# def unescape(text):
#     def fixup(m):
# def decodeHtmlentities(string):
#     def substitute_entity(match):
# def entitiesfix(string):
# def htmlclean(cadena):
# def slugify(title):
# def remove_htmltags(string):
# def remove_show_from_title(title,show):
# def getRandom(str):
# def unseo(cadena):
# def get_filename_from_url(url):
# def get_domain_from_url(url):
# def get_season_and_episode(title):
# def get_sha1(cadena):
# def get_md5(cadena):
# def internet(host="8.8.8.8", port=53, timeout=3):
# def wait_for_internet(wait=30, retry=5):
# 
# Path: platformcode/platformtools.py
# def dialog_ok(heading, line1, line2="", line3=""):
# def dialog_notification(heading, message, icon=0, time=5000, sound=True):
# def dialog_yesno(heading, line1, line2="", line3="", nolabel="No", yeslabel="Si", autoclose=""):
# def dialog_select(heading, _list):
# def dialog_progress(heading, line1, line2="", line3=""):
# def dialog_progress_bg(heading, message=""):
# def dialog_input(default="", heading="", hidden=False):
# def dialog_numeric(_type, heading, default=""):
# def itemlist_refresh():
# def itemlist_update(item):
# def render_items(itemlist, parentitem):
# def is_playing():
# def play_video(item):
# def show_channel_settings(list_controls=None, dict_values=None, caption="", callback=None, item=None,
#                           custom_button=None):
# def show_video_info(data, caption="", callback=None, item=None):


# Path: core/filetools.py
import os
import sys
import traceback
        import re
    import time
        import shutil
from core import logger
from core import scrapertools
from platformcode import platformtools
  from lib.sambatools import libsmb as samba

    top = encode(top)
    if top.lower().startswith("smb://"):
        for a, b, c in samba.walk(top, topdown, onerror):
            # list(b) es para que haga una copia del listado de directorios
            # si no da error cuando tiene que entrar recursivamente en directorios con caracteres especiales
            yield decode(a), decode(list(b)), decode(c)
    else:
        for a, b, c in os.walk(top, topdown, onerror):
            # list(b) es para que haga una copia del listado de directorios
            # si no da error cuando tiene que entrar recursivamente en directorios con caracteres especiales
            yield decode(a), decode(list(b)), decode(c)



def listdir(path):
    """
    Lista un directorio
    @param path: Directorio a listar, debe ser un str "UTF-8"
    @type path: str
    @rtype: str
    @return: contenido de un directorio
    """

    path = encode(path)
    try:
      if path.lower().startswith("smb://"):
          return decode(samba.listdir(path))
      else:
          return decode(os.listdir(path))
    except:

        logger.error("ERROR al leer el directorio: %s" %(path))