# -*- coding: iso-8859-1 -*- #------------------------------------------------------------ # pelisalacarta - XBMC Plugin # Canal para cinegratis # http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/ #------------------------------------------------------------ import urlparse,urllib2,urllib,re import os import sys import xbmc import xbmcgui import xbmcplugin import scrapertools import megavideo import servertools import binascii import xbmctools CHANNELNAME = "cinegratis" # Esto permite su ejecución en modo emulado try: pluginhandle = int( sys.argv[ 1 ] ) except: pluginhandle = "" # Traza el inicio del canal xbmc.output("[cinegratis.py] init") DEBUG = True def mainlist(params,url,category): xbmc.output("[cinegratis.py] mainlist") # Añade al listado de XBMC xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , "Películas - Novedades" ,"http://www.cinegratis.net/index.php?module=peliculas","","") xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , "Películas - Estrenos" ,"http://www.cinegratis.net/index.php?module=estrenos","","") xbmctools.addnewfolder( CHANNELNAME , "peliscat" , category , "Películas - Lista por categorías" ,"http://www.cinegratis.net/index.php?module=generos","","") xbmctools.addnewfolder( CHANNELNAME , "pelisalfa" , category , "Películas - Lista alfabética" ,"","","") xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , "Películas - Alojadas en Veoh" ,"http://www.cinegratis.net/index.php?module=servers&varserver=veoh","","") xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , "Películas - Alojadas en Megavideo","http://www.cinegratis.net/index.php?module=servers&varserver=megavideo","","") xbmctools.addnewfolder( CHANNELNAME , "listseries" , category , "Series - Novedades" ,"http://www.cinegratis.net/index.php?module=series","","") xbmctools.addnewfolder( CHANNELNAME , "listsimple" , category , "Series - Todas" ,"http://www.cinegratis.net/index.php?module=serieslist","","") xbmctools.addnewfolder( CHANNELNAME , "listseries" , category , "Dibujos - Novedades" ,"http://www.cinegratis.net/index.php?module=anime","","") xbmctools.addnewfolder( CHANNELNAME , "listsimple" , category , "Dibujos - Todos" ,"http://www.cinegratis.net/index.php?module=animelist","","") xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , "Documentales - Novedades" ,"http://www.cinegratis.net/index.php?module=documentales","","") xbmctools.addnewfolder( CHANNELNAME , "listsimple" , category , "Documentales - Todos" ,"http://www.cinegratis.net/index.php?module=documentaleslist","","") xbmctools.addnewfolder( CHANNELNAME , "deportes" , category , "Deportes" ,"","","") xbmctools.addnewfolder( CHANNELNAME , "search" , category , "Buscar" ,"","","") if xbmcplugin.getSetting("singlechannel")=="true": xbmctools.addSingleChannelOptions(params,url,category) # Label (top-right)... xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category=category ) # Disable sorting... xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) # End of directory... xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) def pelisalfa(params, url, category): xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "0-9","http://www.cinegratis.net/index.php?module=peliculaslist&init=","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "A","http://www.cinegratis.net/index.php?module=peliculaslist&init=a","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "B","http://www.cinegratis.net/index.php?module=peliculaslist&init=b","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "C","http://www.cinegratis.net/index.php?module=peliculaslist&init=c","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "D","http://www.cinegratis.net/index.php?module=peliculaslist&init=d","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "E","http://www.cinegratis.net/index.php?module=peliculaslist&init=e","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "F","http://www.cinegratis.net/index.php?module=peliculaslist&init=f","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "G","http://www.cinegratis.net/index.php?module=peliculaslist&init=g","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "H","http://www.cinegratis.net/index.php?module=peliculaslist&init=h","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "I","http://www.cinegratis.net/index.php?module=peliculaslist&init=i","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "J","http://www.cinegratis.net/index.php?module=peliculaslist&init=j","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "K","http://www.cinegratis.net/index.php?module=peliculaslist&init=k","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "L","http://www.cinegratis.net/index.php?module=peliculaslist&init=l","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "M","http://www.cinegratis.net/index.php?module=peliculaslist&init=m","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "N","http://www.cinegratis.net/index.php?module=peliculaslist&init=n","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "O","http://www.cinegratis.net/index.php?module=peliculaslist&init=o","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "P","http://www.cinegratis.net/index.php?module=peliculaslist&init=p","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Q","http://www.cinegratis.net/index.php?module=peliculaslist&init=q","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "R","http://www.cinegratis.net/index.php?module=peliculaslist&init=r","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "S","http://www.cinegratis.net/index.php?module=peliculaslist&init=s","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "T","http://www.cinegratis.net/index.php?module=peliculaslist&init=t","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "U","http://www.cinegratis.net/index.php?module=peliculaslist&init=u","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "V","http://www.cinegratis.net/index.php?module=peliculaslist&init=v","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "W","http://www.cinegratis.net/index.php?module=peliculaslist&init=w","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "X","http://www.cinegratis.net/index.php?module=peliculaslist&init=x","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Y","http://www.cinegratis.net/index.php?module=peliculaslist&init=y","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Z","http://www.cinegratis.net/index.php?module=peliculaslist&init=z","","") # Label (top-right)... xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category=category ) # Disable sorting... xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) # End of directory... xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) def deportes(params, url, category): xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Fórmula 1","http://www.cinegratis.net/index.php?module=deporte&cat=Formula-1","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "NBA","http://www.cinegratis.net/index.php?module=deporte&cat=NBA","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Moto GP","http://www.cinegratis.net/deporte.php?cat=MotoGP","","") xbmctools.addnewfolder( CHANNELNAME ,"listsimple", category , "Fútbol","http://www.cinegratis.net/index.php?module=deporte&cat=Futbol","","") # Label (top-right)... xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category=category ) # Disable sorting... xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) # End of directory... xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) def search(params,url,category): xbmc.output("[cinegratis.py] search") keyboard = xbmc.Keyboard('') keyboard.doModal() if (keyboard.isConfirmed()): tecleado = keyboard.getText() if len(tecleado)>0: #convert to HTML tecleado = tecleado.replace(" ", "+") searchUrl = "http://www.cinegratis.net/index.php?module=search&title="+tecleado listsimple(params,searchUrl,category) def peliscat(params,url,category): xbmc.output("[cinegratis.py] peliscat") xbmctools.addnewfolder( CHANNELNAME , "listsimple" , category , "Versión original" ,"http://www.cinegratis.net/index.php?module=search&title=subtitulado","","") xbmctools.addnewfolder( CHANNELNAME , "listsimple" , category , "Versión latina" ,"http://www.cinegratis.net/index.php?module=search&title=latino","","") # Descarga la página data = scrapertools.cachePage(url) # Extrae las entradas (carpetas) patronvideos = "" matches = re.compile(patronvideos,re.DOTALL).findall(data) scrapertools.printMatches(matches) for match in matches: # Atributos patron2 = "index.php.*?\&cat\=([A-Za-z\-]+)" matches2 = re.compile(patron2,re.DOTALL).findall(match[0]) scrapertools.printMatches(matches2) scrapedtitle = matches2[0] scrapedurl = urlparse.urljoin(url,match[0]) scrapedthumbnail = urlparse.urljoin(url,match[1]) scrapedplot = "" if (DEBUG): xbmc.output("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]") # Añade al listado de XBMC xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , scrapedtitle , scrapedurl , scrapedthumbnail, scrapedplot ) # 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 listsimple(params,url,category): xbmc.output("[cinegratis.py] listsimple") # Descarga la página data = scrapertools.cachePage(url) # Extrae las entradas (carpetas) patronvideos = "]*>(.*?)" matches = re.compile(patronvideos,re.DOTALL).findall(data) scrapertools.printMatches(matches) for match in matches: # Atributos scrapedtitle = match[1] scrapedtitle = scrapedtitle.replace("","") scrapedtitle = scrapedtitle.replace("","") scrapedurl = urlparse.urljoin(url,match[0]) scrapedthumbnail = "" scrapedplot = "" if (DEBUG): xbmc.output("title=["+scrapedtitle+"], url=["+scrapedurl+"], thumbnail=["+scrapedthumbnail+"]") # Añade al listado de XBMC xbmctools.addnewfolder( CHANNELNAME , "detail" , category , scrapedtitle , scrapedurl , scrapedthumbnail, scrapedplot ) # 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 listvideos(params,url,category): xbmc.output("[cinegratis.py] listvideos") if url=="": url = "http://www.cinegratis.net/index.php?module=peliculas" # Descarga la página data = scrapertools.cachePage(url) #xbmc.output(data) # Extrae las entradas (carpetas) patronvideos = "([^<]+)\(Visto.*?" patronvideos += "
(.*?)
.*?" patronvideos += "0: scrapedtitle = "Página siguiente" scrapedurl = urlparse.urljoin(url,matches[0]) scrapedthumbnail = "" scrapedplot = "" xbmctools.addnewfolder( CHANNELNAME , "listvideos" , category , scrapedtitle , scrapedurl , scrapedthumbnail, scrapedplot ) # 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 listseries(params,url,category): xbmc.output("[cinegratis.py] listvideos") if url=="": url = "http://www.cinegratis.net/index.php?module=peliculas" # Descarga la página data = scrapertools.cachePage(url) #xbmc.output(data) # Extrae las entradas (carpetas) patronvideos = "]+>]+>([^<]+)<.*?" patronvideos += "
(.*?)
.*?" patronvideos += "0: scrapedtitle = "Página siguiente" scrapedurl = urlparse.urljoin(url,matches[0]) scrapedthumbnail = "" scrapedplot = "" xbmctools.addnewfolder( CHANNELNAME , "listseries" , category , scrapedtitle , scrapedurl , scrapedthumbnail, scrapedplot ) # 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 detail(params,url,category): xbmc.output("[cinegratis.py] detail") title = urllib.unquote_plus( params.get("title") ) thumbnail = urllib.unquote_plus( params.get("thumbnail") ) plot = urllib.unquote_plus( params.get("plot") ) # Descarga la página data = scrapertools.cachePage(url) #xbmc.output(data) # ------------------------------------------------------------------------------------ # Busca los enlaces a los videos # ------------------------------------------------------------------------------------ listavideos = servertools.findvideos(data) for video in listavideos: videotitle = video[0] url = video[1] server = video[2] xbmctools.addnewvideo( CHANNELNAME , "play" , category , server , title.strip() + " - " + videotitle , url , 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 play(params,url,category): xbmc.output("[cinegratis.py] play") title = unicode( xbmc.getInfoLabel( "ListItem.Title" ), "utf-8" ) thumbnail = urllib.unquote_plus( params.get("thumbnail") ) plot = unicode( xbmc.getInfoLabel( "ListItem.Plot" ), "utf-8" ) server = params["server"] xbmctools.playvideo(CHANNELNAME,server,url,category,title,thumbnail,plot)