def play(params,url,category):
    logger.info("[pelispekes.py] play")
    try:
        title = unicode( xbmc.getInfoLabel( "ListItem.Title" ), "utf-8" )
    except:
        title = urllib.unquote_plus( params.get("title") )
    thumbnail = urllib.unquote_plus( params.get("thumbnail") )
    plot = unicode( xbmc.getInfoLabel( "ListItem.Plot" ), "utf-8" )
    server = params.get("server")

    # Abre dialogo
    dialogWait = xbmcgui.DialogProgress()
    dialogWait.create( 'Accediendo al video...', title , plot )

    # Descarga la página del reproductor
    # http://pelispekes.com/modulos/player.php?url=dmlkZW8uYWsuZmFjZWJvb2suY29tL2Nmcy1hay1hc2gyLzMzMjM2LzY4NS8xMDU1NTcxNDYxNjI3MjNfMzQ5ODk=
    # http://pelispekes.com/modulos/embed/playerembed.php?url=dmlkZW8uYWsuZmFjZWJvb2suY29tL2Nmcy1hay1hc2gyLzMzMjM2LzY4NS8xMDU1NTcxNDYxNjI3MjNfMzQ5ODk=
    logger.info("[pelispekes.py] url="+url)
    
    ## --------------------------------------------------------------------------------------##
    #            Busca enlaces de videos para el servidor vkontakte.ru                        #
    ## --------------------------------------------------------------------------------------##
    #"http://vkontakte.ru/video_ext.php?oid=89710542&id=147003951&hash=28845bd3be717e11&hd=1
    
    
    if "vkontakteX.php" in url:
        data = scrapertools.cachePage(url)
        server = "Directo"
        '''
        var video_host = 'http://cs12916.vkontakte.ru/';
        var video_uid = '87155741';
        var video_vtag = 'fc697084d3';
        var video_no_flv = 1;
        var video_max_hd = '1'
        '''
        patronvideos = '<iframe src="(http://vk[^/]+/video_ext.php[^"]+)"'
        matches = re.compile(patronvideos,re.DOTALL).findall(data)
        if len(matches)>0:
            print " encontro VKontakte.ru :%s" %matches[0]
            url =     vk.geturl(matches[0])
            
    
    # Cierra dialogo
    dialogWait.close()
    del dialogWait

    if len(url)>0:
        
        logger.info("url="+url)
        xbmctools.playvideo(CHANNELNAME,server,url,category,title,thumbnail,plot)
    else:
        xbmctools.alertnodisponible()
def play(item):
    logger.info("[bancodeseries.py] play url="+item.url)
    itemlist = []
    # Busca enlaces de videos para el servidor vkontakte.ru
    #"http://vkontakte.ru/video_ext.php?oid=89710542&id=147003951&hash=28845bd3be717e11&hd=1
    if "vkontakteX.php" in item.url:
        '''
        var video_host = 'http://cs12916.vkontakte.ru/';
        var video_uid = '87155741';
        var video_vtag = 'fc697084d3';
        var video_no_flv = 1;
        var video_max_hd = '1'
        '''
        data = scrapertools.cachePage(item.url)
        patronvideos = '<iframe src="(http://vk[^/]+/video_ext.php[^"]+)"'
        matches = re.compile(patronvideos,re.DOTALL).findall(data)
        if len(matches)>0:
            #print " encontro VKontakte.ru :%s" %matches[0]
            item.server = "Directo"
            item.url = vk.geturl(matches[0])

    itemlist.append( item )
def detail(params,url,category):
    logger.info("[peliculasonlineflv.py] detail")

    
    thumbnail = urllib.unquote_plus( params.get("thumbnail") )
    plot = urllib.unquote_plus( params.get("plot") )
    url1 = url
    # Descarga la página
    data = scrapertools.cachePage(url)
    try:
        title = re.compile("<title>(.+?)</title>").findall(data)[0]
    except:
        title = urllib.unquote_plus( params.get("title") )
    #logger.info(data)
    patron = 'src="(http://wwwpeliculasonlineflvorghost.blogspot.com.+?)"'
    matches = re.compile(patron,re.DOTALL).findall(data)
    if len(matches)>0:
        data = scrapertools.cachePage(matches[0])
        patron = 'src="(http://wwwpeliculasonlineflvorghost.blogspot.com.+?)"'
        matches = re.compile(patron,re.DOTALL).findall(data)
        if len(matches)>0:
            data = data + scrapertools.cachePage(matches[0])

    # ------------------------------------------------------------------------------------
    # Busca los enlaces a los videos
    # ------------------------------------------------------------------------------------
    listavideos = servertools.findvideos(data)
    
    for video in listavideos:
        videotitle = video[0]
        
        if "myspacecdn" or "facebook" in video[1]:
            continue
        
        url = video[1].replace("&amp;","&")
        server = video[2]
        xbmctools.addnewvideo( CHANNELNAME , "play" , category , server , title.strip() + " - " + videotitle , url , thumbnail , plot )
    # ------------------------------------------------------------------------------------
    ## --------------------------------------------------------------------------------------##
    #               Busca enlaces a videos .flv o (.mp4 dentro de un xml)                     #
    ## --------------------------------------------------------------------------------------##
    patronvideos = 'file=(http\:\/\/[^\&]+)\&'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    print patronvideos
    c = 0
    if len(matches)>0:
        print matches
        for match in matches:
            subtitle = "[FLV-Directo]"
            if ("xml" in matches[0]):
                data2 = scrapertools.cachePage(matches[0])
                logger.info("data2="+data2)
                patronvideos  = '<track>.*?'
                patronvideos += '<creator>([^<]+)</creator>[^<]+'
                patronvideos += '<location>([^<]+)</location>[^<]+'
                patronvideos += '</track>'
                matches2 = re.compile(patronvideos,re.DOTALL).findall(data2)
                scrapertools.printMatches(matches2)

                for match2 in matches2:
                    if ".mp4" in match2[1]:
                        subtitle = "[MP4-Directo]"
                    scrapedtitle = '%s (%s) - %s' %(title,match2[0].strip(),subtitle)
                    scrapedurl = match2[1].strip()
                    scrapedthumbnail = thumbnail
                    scrapedplot = plot
                    if (DEBUG): logger.info("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]")

                    # Añade al listado de XBMC
                    xbmctools.addnewvideo( CHANNELNAME , "play" , category , "Directo" , scrapedtitle, scrapedurl , scrapedthumbnail, scrapedplot )
            else:
                
                c +=1    
                xbmctools.addnewvideo( CHANNELNAME , "play" , category , "Directo" , title + " - Parte %d/%d " %(c,len(matches))+subtitle, match , thumbnail , plot )
    
    
    patronvideos = 'src="(http://vk[^/]+/video_ext.php[^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    long = len(matches)
    
    
    if long>0:
        for match in matches:
            #print " encontro VKontakte.ru :%s" %match[0]
            scrapedurl =     vk.geturl(match.replace("&amp;","&"))
            scrapedtitle = title
            server = "Directo"
            
            
            xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - [VKServer]" , scrapedurl , thumbnail, plot )
            
    
    patronvideos = 'http://www.yaflix.com/.+?key=([^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    
    
    
    if len(matches)>0:
        
        for match in matches:
            link = "http://www.yaflix.com/nuevo/playlist.php?key=" + match
            data2 = scrapertools.cachePage(link)
            #print " encontro yaflix :%s" %match[0]
            patron = "<file>([^<]+)</file>"
            matcheslink = re.compile(patron,re.DOTALL).findall(data2)
            if len (matcheslink)>0:
                scrapedurl =     matcheslink[0]
            else:scrapedurl = ""
            scrapedtitle = title
            server = "Directo"
            
            
            xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - [YAFLIX]" , scrapedurl , thumbnail, plot )
                
    patronvideos = 'http://www.videoinet.ru/incs/incplaylist.html\?lkn=([^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    print data
    
    
    
    if len(matches)>0:
        
        
        scrapedurl = "http://fileserver2.videoinet.ru//get/" + matches[0] + ".flv"
 
        scrapedtitle = title
        server = "Directo"
        
        xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - [videoinet]" , scrapedurl , thumbnail, plot )
    
    # Label (top-right)...
    xbmcplugin.setPluginCategory( handle=pluginhandle, category=category )
        
    # Disable sorting...
    xbmcplugin.addSortMethod( handle=pluginhandle, sortMethod=xbmcplugin.SORT_METHOD_NONE )

    # End of directory...
    xbmcplugin.endOfDirectory( handle=pluginhandle, succeeded=True )
def listmirrors(params,url,category):
    logger.info("[pelispekes.py] listmirrors")

    title = unicode( xbmc.getInfoLabel( "ListItem.Title" ), "utf-8" )
    
    thumbnail = urllib.unquote_plus( params.get("thumbnail") )
    plot = unicode( xbmc.getInfoLabel( "ListItem.Plot" ), "utf-8" )
    

    # Descarga la página de detalle
    # http://pelispekes.com/sorority-row/
    data = scrapertools.cachePage(url)
    #logger.info(data)
    
    # Extrae el argumento
    patron = '<div class="sinopsis">.*?<li>(.*?)</li>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    if len(matches)>0:
        plot = matches[0]

    
    

    patron = '<div class="page-navigation">(.*?)</table>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    scrapertools.printMatches(matches)
    scrapedtitle = title
    scrapedthumbnail = thumbnail
    scrapedplot = plot
    
    if len(matches)>0:
        data = matches[0]
        patron  = '<a href="([^"]+)"[^>]+>([^<]+)</a>'
        matches = re.compile(patron,re.DOTALL).findall(data)
        scrapertools.printMatches(matches)
        
        for match in matches:
            
            
            
            if match[0].endswith(".html"):
                if "/vk/" in match[0]:  #http://pelispekes.com/vk/11223192/674072850/ml3mp2pm9v00nmp2/predators-online.html
                    patron = "http\:\/\/pelispekes.com\/vk\/([^\/]+)\/([^\/]+)\/([^\/]+)\/[^\.]+\.html"
                    matchesvk = re.compile(patron).findall(match[0])
                    scrapedurl = "http://pelispekes.com/modulos/embed/vkontakteX.php?oid=%s&id=%s&hash=%s" %(matchesvk[0][0],matchesvk[0][1],matchesvk[0][2])
                    server = "Directo"
                    xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - %s [VK]" %match[1] , scrapedurl , scrapedthumbnail, scrapedplot )
                              
            
            
                patron   = "http://pelispekes.com/([^/]+)/([^/]+)/[^\.]+.html"    #http://pelispekes.com/playlist/6917/el-equipo-a-online.html
                matches2 = re.compile(patron,re.DOTALL).findall(match[0])
                                
                if matches2[0][0] == "playlist":
                    xmlurl = "http://pelispekes.com/xml/%s.xml" %matches2[0][1]
                    xmldata = scrapertools.cachePage(xmlurl)
                    logger.info("xmldata="+xmldata)
                    patronvideos  = '<track>[^<]+'
                    patronvideos += '<creator>([^<]+)</creator>[^<]+'
                    patronvideos += '<location>([^<]+)</location>.*?'
                    patronvideos += '</track>'
                    matchesxml = re.compile(patronvideos,re.DOTALL).findall(xmldata)
                    scrapertools.printMatches(matchesxml)
                    for xmlmatch in matchesxml:
                        scrapedurl = xmlmatch[1]
                        #xbmctools.addnewvideo( CHANNELNAME , "play" , category , server , (title.strip() + " (%d) " + videotitle) % j , url , thumbnail , plot )
                        server = "Directo"
                        xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - %s [Directo]" %xmlmatch[0] , scrapedurl , scrapedthumbnail, scrapedplot )
                elif matches2[0][0] == "flash":
                    scrapedurl = matches2[0][1]
                    server = "Megavideo"
                    scrapedtitle = scrapedtitle+" - %s" %match[1]
                    scrapedtitle = scrapedtitle.replace("&ntilde;","ñ")
                    xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle , scrapedurl , scrapedthumbnail, scrapedplot )
            elif "vk.php" in match[0]:
                scrapedurl = "http://pelispekes.com/modulos/vkontakteX.php?%s" %match[0].split("?")[1]
                server = "Directo"
                xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - %s [VK]" %match[1] , scrapedurl , scrapedthumbnail, scrapedplot )
    
    patronvideos = '<iframe src="(http://vk[^/]+/video_ext.php[^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    if len(matches)>0:
        print " encontro VKontakte.ru :%s" %matches[0]
        scrapedurl =     vk.geturl(matches[0])    
        server = "Directo"
        xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - [VK]" , scrapedurl , scrapedthumbnail, scrapedplot )

    patronvideos = '<iframe src="(http://pelispekes.com/modulos/vkontakteX.php[^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    if len(matches)>0:
        print " encontro VKontakte.ru :%s" %matches[0]
        #scrapedtitle = scrapedtitle.replace("\xf3","ñ")
        scrapedurl =     matches[0]    
        server = "Directo"
        xbmctools.addnewvideo( CHANNELNAME , "play" , category ,server, scrapedtitle+" - [VK]" , scrapedurl , scrapedthumbnail, scrapedplot )    
    # ------------------------------------------------------------------------------------
    # Busca los enlaces a los videos en los servidores habilitados
    # ------------------------------------------------------------------------------------
    listavideos = servertools.findvideos(data)

    for video in listavideos:
        
        videotitle = video[0]
        url = video[1]
        server = video[2]
        from core import downloadtools
        scrapedplot = downloadtools.limpia_nombre_excepto_1(scrapedplot)
        xbmctools.addnewvideo( CHANNELNAME , "play" , category , server , scrapedtitle + " - " + videotitle , url , scrapedthumbnail , scrapedplot )
        
    # Cierra el directorio
    xbmcplugin.setPluginCategory( handle=pluginhandle, category=category )
    xbmcplugin.addSortMethod( handle=pluginhandle, sortMethod=xbmcplugin.SORT_METHOD_NONE )
    xbmcplugin.endOfDirectory( handle=pluginhandle, succeeded=True )
def detail(item):
    logger.info("[cineadicto.py] detail")

    title = item.title
    thumbnail = item.thumbnail
    plot = item.plot
    scrapedurl = ""
    url = item.url
    # Descarga la p�gina
    data = scrapertools.cachePage(url)
    #logger.info(data)
    patronvideos = 'name="Pelicula" src="([^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    if len(matches)>0:
        data = scrapertools.cachePage(matches[0])
    # Extrae el argumento
    patronarg = '</p><p>.*?<strong>([^<]+</strong> <strong>.*?)<p></p>'
    matches   = re.compile(patronarg,re.DOTALL).findall(data)
    if len(matches)>0:
        plot  = re.sub("<[^>]+>"," ",matches[0])
  
    # ------------------------------------------------------------------------------------
    # Busca los enlaces a los videos en los servidores habilitados
    # ------------------------------------------------------------------------------------

   
            
    ## --------------------------------------------------------------------------------------##
    #               Busca enlaces a videos .flv o (.mp4 dentro de un xml)                     #
    ## --------------------------------------------------------------------------------------##
    patronvideos = 'file=(http\:\/\/[^\&]+)\&'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    scrapertools.printMatches(matches)
    playWithSubt = "play"
    c = 0
    itemlist = []
    if len(matches)>0:
        for match in matches:
            subtitle = "[FLV-Directo]"
            c += 1
            if ("playlist" in match):
                data2 = scrapertools.cachePage(match)
                logger.info("data2="+data2)
                patronvideos  = '<track>.*?'
                patronvideos += '<title>([^<]+)</title>[^<]+'
                patronvideos += '<location>([^<]+)</location>(?:[^<]+'
                patronvideos += '<meta rel="type">video</meta>[^<]+|[^<]+'
                patronvideos += '<meta rel="captions">([^<]+)</meta>[^<]+)'
                patronvideos += '</track>'
                matches2 = re.compile(patronvideos,re.DOTALL).findall(data2)
                scrapertools.printMatches(matches)
                
                for match2 in matches2:
                    sub = ""
                    if match2[2].endswith(".xml"): # Subtitulos con formato xml son incompatibles con XBMC
                        sub = "[Subtitulo incompatible con xbmc]"
                        playWithSubt = "play"
                    if ".mp4" in match2[1]:
                        subtitle = "[MP4-Directo]"
                    scrapedtitle = '%s (castellano) - %s  %s' %(title,match2[0],subtitle)
                    
                    scrapedurl = match2[1].strip()
                    scrapedthumbnail = thumbnail
                    scrapedplot = plot
                    if ("cast.xml" or "mirror.xml") not in match:
                        scrapedtitle = '%s (V.O.S) - %s  %s %s' %(title,match2[0],subtitle,sub)
                        if not match2[2].endswith("cine-adicto2.srt") and (sub == ""): 
                            scrapedurl = scrapedurl + "|" + match2[2]
                            playWithSubt = "play2"
                            
                    if (DEBUG): logger.info("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]")
                            
                    # A�ade al listado de XBMC
                    itemlist.append( Item(channel=CHANNELNAME , action=playWithSubt  , title=scrapedtitle, url=scrapedurl , thumbnail=scrapedthumbnail, plot=scrapedplot, server= "Directo" , folder = False ))
                
            else:
                c +=1
                scrapedurl = match
                if match.endswith(".srt") and not (((c / 2) * 2 - c) == 0) :
                    scrapedurl = scrapedurl + "|" + match 
                    itemlist.append( Item(channel=CHANNELNAME , action="play2"  , server="Directo" , title=title + " (V.O.S) - "+subtitle, url=scrapedurl , thumbnail=thumbnail , plot=plot , folder=False))
                elif     match.endswith(".xml") and not (((c / 2) * 2 - c) == 0):
                    sub = "[Subtitulo incompatible con xbmc]"
                    itemlist.append( Item(channel=CHANNELNAME , action="play"  , server="Directo" , title=title + " (V.O) - %s %s" %(subtitle,sub), url=scrapedurl , thumbnail=thumbnail , plot=plot , folder=False ))
                elif not match.endswith("srt" or "xml") :
                    itemlist.append( Item(channel=CHANNELNAME , action="play"  , server="Directo" , title=title + " - [Directo]" , url=scrapedurl , thumbnail=thumbnail , plot=plot , folder=False ))
                
                print scrapedurl
    
    try:
        matches = url.split("/")
        url2 = "http://www.cine-adicto.com/tab/"+matches[3]
        data2 = scrapertools.cachePage(url2)
    
        
        listavideos = servertools.findvideos(data2)
        c = 0
        for video in listavideos:
            if "stagevu.com/embed" not in video[1]:
                videotitle = video[0]
                url = video[1]
                server = video[2]
                if "facebook" in url:
                    c += 1
                    itemlist.append( Item(channel=CHANNELNAME , action="play"   , server=server , title=title.strip() + " - Parte %d %s" %(c,videotitle) , url=url , thumbnail=thumbnail , plot=plot , folder=False))
                else:
                    itemlist.append( Item(channel=CHANNELNAME , action="play"   , server=server , title=title.strip() + " - " + videotitle , url=url , thumbnail=thumbnail , plot=plot , folder=False ))
    except:
        pass


    ## --------------------------------------------------------------------------------------##
    #            Busca enlaces de videos para el servidor vk.com                             #
    ## --------------------------------------------------------------------------------------##
    '''
    var video_host = '447.gt3.vkadre.ru';
    var video_uid = '0';
    var video_vtag = '2638f17ddd39-';
    var video_no_flv = 0;
    var video_max_hd = '0';
    var video_title = 'newCine.NET+-+neWG.Es+%7C+Chicken+Little';

    '''
    patronvideos = '<iframe src="(http://[^\/]+\/video_ext.php[^"]+)"'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    if len(matches)>0:
        print " encontro VK.COM :%s" %matches[0]
        videourl = vk.geturl(matches[0])
        itemlist.append( Item(channel=CHANNELNAME , action="play"  , server="Directo" , title=title + " - "+"[VK]", url=videourl , thumbnail=thumbnail , plot=plot , folder=False ))

    patronvideos = '(http://cine-adicto.com/(?:(?:vk|vb)|(?:mg|bb))?/[^\.]+.html)'
    matches = re.compile(patronvideos,re.DOTALL).findall(data)
    if len(matches)>0:
        for match in matches:
            
            listavideos = servertools.findvideos(scrapertools.cachePage(match))
            for video in listavideos:
                if "stagevu.com/embed" not in video[1]:
                    videotitle = video[0]
                    url = video[1]
                    server = video[2]
                if "facebook" in url:
                    c += 1
                    itemlist.append( Item(channel=CHANNELNAME , action="play"  , server=server , title=title.strip() + " - Parte %d %s" %(c,videotitle) , url=url , thumbnail=thumbnail , plot=plot , folder=False ))
                else:
                    itemlist.append( Item(channel=CHANNELNAME , action="play"  , server=server , title=title.strip() + " - " + videotitle , url=url , thumbnail=thumbnail , plot=plot , folder=False ))
 
    listavideos = servertools.findvideos(data)
    for video in listavideos:
        if "stagevu.com/embed" not in video[1]:
            videotitle = video[0]
            url = video[1]
            server = video[2]
            if "facebook" in url:
                c += 1
                itemlist.append( Item(channel=CHANNELNAME , action="play"  , server=server , title=title.strip() + " - Parte %d %s" %(c,videotitle) , url=url , thumbnail=thumbnail , plot=plot , folder=False ))
            else:
                itemlist.append( Item(channel=CHANNELNAME , action="play"  , server=server , title=title.strip() + " - " + videotitle , url=url , thumbnail=thumbnail , plot=plot ,folder=False ))
 
    return itemlist