def mainlist(params,url,category):
    logger.info("[configuracion.py] mainlist")
    
    # Verifica ruta de descargas
    downloadtools.getDownloadPath()
    downloadtools.getDownloadListPath()

    config.open_settings( )
def MakePlaylistFromList(Listdata,title="default"):
    logger.info("[%s.py] MakePlaylistFromList" %CHANNELNAME)
    
    if title== ("default" or ""):
        nombrefichero = FULL_FILENAME_PATH
    else:
        nombrefichero = os.path.join( downloadtools.getDownloadPath(),title + ".pls")
    
    if len(Listdata)>0:
        playlistFile = open(nombrefichero,"w")
        playlistFile.write("[playlist]\n")
        playlistFile.write("\n")
        c = 0        
        for match in Listdata:
            c += 1
            playlistFile.write("File%d=%s\n"  %(c,match[1]))
            playlistFile.write("Title%d=%s\n" %(c,match[0]))
            playlistFile.write("\n")
            
        playlistFile.write("NumberOfEntries=%d\n" %c)
        playlistFile.write("Version=2\n")
        playlistFile.flush();
        playlistFile.close()    
        return nombrefichero
    else:
        return ""
def MakePlaylistFromXML(xmlurl,title="default"):
    logger.info("[%s.py] MakePlaylistFromXML" %CHANNELNAME)
    
    if title== ("default" or ""):
        nombrefichero = FULL_FILENAME_PATH_XML
    else:
        nombrefichero = os.path.join( downloadtools.getDownloadPath(),title + ".pls")
    xmldata = scrapertools.cachePage(xmlurl)
    patron = '<title>([^<]+)</title>.*?<location>([^<]+)</location>'
    matches = re.compile(patron,re.DOTALL).findall(xmldata)
    if len(matches)>0:
        playlistFile = open(nombrefichero,"w")
        playlistFile.write("[playlist]\n")
        playlistFile.write("\n")
        c = 0        
        for match in matches:
            c += 1
            playlistFile.write("File%d=%s\n"  %(c,match[1]))
            playlistFile.write("Title%d=%s\n" %(c,match[0]))
            playlistFile.write("\n")
            
        playlistFile.write("NumberOfEntries=%d\n" %c)
        playlistFile.write("Version=2\n")
        playlistFile.flush();
        playlistFile.close()    
        return nombrefichero
    else:
        return ""
def creartag(params,url,category):
    nombrefichero = os.path.join( downloadtools.getDownloadPath(), "sonolatino_category.txt")
    data = scrapertools.cachePage(url)
    patron = '<ul id="ul_categories">(.*?)</ul>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    if len(matches)>0:
        patron = '<li><a href="([^"]+)">([^<]+)</a></li>'
        matches2 = re.compile(patron,re.DOTALL).findall(matches[0])
        if len(matches2)>0:
            filetag = open(nombrefichero,"w")
            
            for match in matches2:
                filetag.write('xbmctools.addnewfolder(CHANNELNAME , "listatipoVideo" , category , "%s","%s","","")\n' %(match[1],match[0]))
                
            filetag.flush();
            filetag.close()            
            print "Lista tag creada correctamente"
        else:
            print "no encontro ningun tag"
    xbmcplugin.endOfDirectory( handle=pluginhandle, succeeded=True )
    from core import scrapertools
    from core.item import Item
    from core import xbmctools
    from core import downloadtools
    from servers import servertools
except:
    # En Plex Media server lo anterior no funciona...
    from Code.core import logger
    from Code.core import config
    from Code.core import scrapertools
    from Code.core.item import Item


CHANNELNAME = "asiateam"
DEBUG = True
SUB_PATH = xbmc.translatePath( os.path.join( downloadtools.getDownloadPath() , 'Subtitulos\AsiaTeam' ) )
if not os.path.exists(SUB_PATH):
    os.mkdir(SUB_PATH)

SUBTEMP_PATH = xbmc.translatePath( os.path.join( config.get_data_path() , 'subtitulo.srt' ) )

def isGeneric():
    return True

def mainlist(item):
    logger.info("[asiateam.py] mainlist")

    itemlist = []
    itemlist.append( Item(channel=CHANNELNAME, title="Películas", action="peliculas", url="http://www.asia-team.net/foros/forumdisplay.php?f=119"))
    itemlist.append( Item(channel=CHANNELNAME, title="Series", action="series", url="http://www.asia-team.net/foros/forumdisplay.php?f=44"))	
from xml.dom import minidom
from xml.dom import EMPTY_NAMESPACE

from core import scrapertools
from core import config
from core import logger
from core import xbmctools
from core.item import Item
from core import downloadtools
from servers import vk
from servers import servertools

CHANNELNAME = "pelisflv"
ATOM_NS = 'http://www.w3.org/2005/Atom'
PLAYLIST_FILENAME_TEMP = "video_playlist.temp.pls"
FULL_FILENAME_PATH = os.path.join( downloadtools.getDownloadPath(), PLAYLIST_FILENAME_TEMP )


# Esto permite su ejecuci�n en modo emulado
try:
    pluginhandle = int( sys.argv[ 1 ] )
except:
    pluginhandle = ""

# Traza el inicio del canal
logger.info("[pelisflv.py] init")

DEBUG = True

def mainlist(params,url,category):
    logger.info("[pelisflv.py] mainlist")