Advertisement
jackox

video.television.xml

Oct 23rd, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 52.57 KB | None | 0 0
  1. <files>
  2.     <version>0.0.2</version>
  3.     <file>
  4.         <name>addon.xml</name>
  5.         <path>lib/</path>
  6.         <path>/</path>
  7.         <content>
  8. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  9. <addon id="plugin.video.television2"
  10.    name="Television2"
  11.    version="0.0.2"
  12.    provider-name="Jackox">
  13.   <requires>
  14.     <import addon="xbmc.python" version="2.1.0"/>
  15.   </requires>
  16.   <extension point="xbmc.python.pluginsource" library="default.py">
  17.     <provides>video</provides>
  18.   </extension>
  19.   <extension point="xbmc.addon.metadata">
  20.     <summary lang="en">Television</summary>
  21.     <description lang="en">Canales de televisión en tu media center</description>
  22.     <summary lang="es">Television</summary>
  23.     <description lang="es">Canales de televisión en tu media center</description>
  24.     <platform>all</platform>
  25.     <assets>
  26.         <icon>media/icon.png</icon>
  27.         <fanart>media/fanart.jpg</fanart>
  28.     </assets>
  29.   </extension>
  30. </addon>
  31.         </content>
  32.     </file>
  33.     <file>
  34.         <name>run.py</name>
  35.         <path>lib/</path>
  36.         <content>
  37. # -*- coding: utf-8 -*-
  38.  
  39. import os
  40. import sys
  41. import xbmc
  42. import xbmcaddon
  43. import sqlite3
  44. from sqlite3 import Error
  45. import plugintools
  46.  
  47. # Entry point
  48. def inicia():
  49.     # Get params
  50.     params = plugintools.get_params()
  51.     if params.get("action") is None:
  52.         #presenta menu inicial
  53.         list(params)
  54.     else:
  55.         action = params.get("action")
  56.         exec action+"(params)"
  57.     plugintools.close_item_list()
  58.  
  59. # Main menu
  60. def list(params):
  61.     plugintools.set_view(plugintools.THUMBNAIL)
  62.  
  63.     database = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('path'))+'/db/local.db'
  64.     conn = create_connection(database)
  65.     cur = conn.cursor()
  66.     try:
  67.         #data = plugintools.read('https://pastebin.com/raw/qT05ajcq')
  68.         data = plugintools.read('http://localhost/www/media/lista.xml')
  69.     except:
  70.         plugintools.log('No fue posible conectarse con el archivo xml')
  71.         return
  72.     pattern = '<canal>(.*?)</canal>'
  73.     canales = plugintools.find_multiple_matches(data,pattern)
  74.     i=0
  75.     matcanales=[]
  76.     #plugintools.log(data)
  77.     for cadcanal in canales:
  78.         id        = plugintools.find_single_match( cadcanal , '<id>(.*?)</id>')
  79.         titulo    = plugintools.find_single_match( cadcanal , '<titulo>(.*?)</titulo>')
  80.         url       = plugintools.find_single_match( cadcanal , '<url>(.*?)</url>')
  81.         thumbnail = plugintools.find_single_match( cadcanal , '<thumbnail>(.*?)</thumbnail>')
  82.         fanart    = plugintools.find_single_match( cadcanal , '<fanart>(.*?)</fanart>')
  83.         cur.execute('SELECT * FROM visitas WHERE id=' + str(id))
  84.         id_exists = cur.fetchone()
  85.         if id_exists:
  86.             nvisitas = id_exists[1]
  87.         else:
  88.             nvisitas = 0
  89.  
  90.         matcanales.append([])
  91.         matcanales[i].append(id)
  92.         matcanales[i].append(titulo)
  93.         matcanales[i].append(url)
  94.         matcanales[i].append(thumbnail)
  95.         matcanales[i].append(fanart)
  96.         matcanales[i].append(nvisitas)
  97.         i=i+1
  98.     #matcanales.sort(key = lambda x : x[5])
  99.     sorted(matcanales,key=lambda x: x[5])
  100.  
  101.     for j in range(0, i-1):
  102.         id          = matcanales[j][0]
  103.         titulo      = matcanales[j][1]
  104.         url         = matcanales[j][2]
  105.         thumbnail   = matcanales[j][3]
  106.         fanart      = matcanales[j][4]
  107.         nvisitas    = matcanales[j][5]
  108.         cad         = str(id)+"-"+str(nvisitas)
  109.         if titulo<>'':
  110.             plugintools.add_item( action='play', title=titulo, plot=cad, url=url, thumbnail=thumbnail, fanart=fanart, isPlayable=True, folder=False)
  111.  
  112.     cur.close()
  113.     conn.close()
  114.  
  115. def play(params):
  116.     plugintools.play_resolved_url( params.get("url") )
  117.     cad = params.get("plot")
  118.     x = cad.split("-")
  119.     Id       = x[0]
  120.     nVisitas = int(x[1])
  121.     nVisitas = nVisitas + 1
  122.     cVisitas = str(nVisitas)
  123.     database = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('path'))+'/db/local.db'
  124.     conn = create_connection(database)
  125.     cur = conn.cursor()
  126.     if nVisitas == 1:
  127.         sql="INSERT INTO visitas (id,visitas) VALUES("+Id+","+cVisitas+")"
  128.     else:
  129.         sql="UPDATE visitas SET visitas="+cVisitas+" WHERE id="+Id
  130.     cur.execute(sql)
  131.     conn.commit()
  132.     cur.close()
  133.     conn.close()
  134.  
  135. def create_connection(db_file):
  136.     try:
  137.         conn = sqlite3.connect(db_file)
  138.         return conn
  139.     except Error as e:
  140.         plugintools.log('Error al conectarse a la base de datos, '+e)
  141.         return None
  142.         </content>
  143.     </file>
  144.     <file>
  145.         <name>__init__.py</name>
  146.         <path>lib/</path>
  147.         <content>
  148.         </content>
  149.     </file>
  150.     <file>
  151.         <name>plugintools.py</name>
  152.         <path>lib/</path>
  153.         <content>
  154. # -*- coding: utf-8 -*-
  155. #---------------------------------------------------------------------------
  156. # Plugin Tools v1.0.8
  157. #---------------------------------------------------------------------------
  158. # Changelog:
  159. # 1.0.4
  160. # - Added get_temp_path, get_runtime_path, get_data_path
  161. # - Added get_setting, set_setting, open_settings_dialog and get_localized_string
  162. # - Added keyboard_input
  163. # - Added message
  164. # 1.0.5
  165. # - Added read_body_and_headers for advanced http handling
  166. # - Added show_picture for picture addons support
  167. # - Added optional parameters "title" and "hidden" to keyboard_input
  168. # 1.0.6
  169. # - Added fanart, show, episode and infolabels to add_item
  170. # 1.0.7
  171. # - Added set_view function
  172. # 1.0.8
  173. # - Added selector
  174. #---------------------------------------------------------------------------
  175.  
  176. import xbmc
  177. import xbmcplugin
  178. import xbmcaddon
  179. import xbmcgui
  180.  
  181. import urllib
  182. import urllib2
  183. import re
  184. import sys
  185. import os
  186. import time
  187. import socket
  188. from StringIO import StringIO
  189. import gzip
  190.  
  191. module_log_enabled = False
  192. http_debug_log_enabled = False
  193.  
  194. LIST = "list"
  195. THUMBNAIL = "thumbnail"
  196. MOVIES = "movies"
  197. TV_SHOWS = "tvshows"
  198. SEASONS = "seasons"
  199. EPISODES = "episodes"
  200. MUSIC = "music"
  201. TV = "tvchannels"
  202. OTHER = "other"
  203. BIGLIST = "biglist"
  204.  
  205.  
  206.  
  207. home = xbmc.translatePath(os.path.join('special://home/addons/plugin.video.arenapremium/', ''))
  208. art = xbmc.translatePath(os.path.join('special://home/addons/plugin.video.arenapremium/art', ''))
  209. cbx_pages = xbmc.translatePath(os.path.join('special://home/userdata/adon_data/plugin.video.arenapremium/art/cbx', ''))
  210. playlists = xbmc.translatePath(os.path.join('special://home/userdata/addon_data/plugin.video.arenapremium/playlists', ''))
  211. tmp = xbmc.translatePath(os.path.join('special://home/userdata/addon_data/plugin.video.arenapremium/tmp', ''))
  212.  
  213. addonName           = xbmcaddon.Addon().getAddonInfo("name")
  214. addonVersion        = xbmcaddon.Addon().getAddonInfo("version")
  215. addonId             = xbmcaddon.Addon().getAddonInfo("id")
  216. addonPath           = xbmcaddon.Addon().getAddonInfo("path")
  217.  
  218.  
  219. # Note: content: files, songs, artists, albums, movies, tvshows, episodes, musicvideos
  220. # Skin Confluence
  221. # List = 50, Full list = 51, Thumb = 500, Poster = 501, Posterwrap = 508, Info del medio 1 = 503, Info del medio 2 = 504, Info del medio 3 = 515, Ancho = 505, Music Info = 511, AddoninfoList = 550, AddonThumbList = 551, LiveTV = 560
  222. # Suggested view codes for each type from different skins (initial list thanks to xbmcswift2 library)
  223.  
  224. ALL_VIEW_CODES = {
  225.     'list': {
  226.         'skin.confluence': 50, # List
  227.         'skin.aeon.nox': 50, # List
  228.         'skin.droid': 50, # List
  229.         'skin.quartz': 50, # List
  230.         'skin.re-touched': 50, # List
  231.         'skin.titan': 50,
  232.     },
  233.     'thumbnail': {
  234.         'skin.confluence': 500, # Thumbnail
  235.         'skin.aeon.nox': 500, # Wall
  236.         'skin.droid': 51, # Big icons
  237.         'skin.quartz': 51, # Big icons
  238.         'skin.re-touched': 500, #Thumbnail
  239.         'skin.titan': 511, #Thumbs
  240.     },
  241.     'movies': {
  242.         'skin.confluence': 508,  # Media info 3 (515), Movies (508)      
  243.         'skin.aeon.nox': 500, # Wall
  244.         'skin.droid': 51, # Big icons
  245.         'skin.quartz': 52, # Media info
  246.         'skin.re-touched': 500, #Thumbnail
  247.         'skin.neon': 588, # Multiplex
  248.         'skin.titan': 52, #HorizontalPanel
  249.     },
  250.     'tvshows': {
  251.         'skin.confluence': 515, # Thumbnail 515, # Media Info 3
  252.         'skin.aeon.nox': 500, # Wall
  253.         'skin.droid': 51, # Big icons
  254.         'skin.quartz': 52, # Media info
  255.         'skin.re-touched': 500, #Thumbnail
  256.         'skin.neon': 57, # Panel Landscape
  257.         'skin.titan': 512, #ThumbsDetails      
  258.     },
  259.     'seasons': {
  260.         'skin.confluence': 50, # List
  261.         'skin.aeon.nox': 50, # List
  262.         'skin.droid': 50, # List
  263.         'skin.quartz': 52, # Media info
  264.         'skin.re-touched': 50, # List
  265.         'skin.titan': 50, # 53_PanelDetails
  266.  
  267.     },
  268.     'episodes': {
  269.         'skin.confluence': 504, # Media Info
  270.         'skin.aeon.nox': 518, # Infopanel
  271.         'skin.droid': 50, # List
  272.         'skin.quartz': 52, # Media info
  273.         'skin.re-touched': 550, # Wide
  274.         'skin.titan': 514, #PosterShift
  275.     },
  276.     'biglist': {
  277.         'skin.confluence': 51, # Big list
  278.         'skin.aeon.nox': 518, # NO DEFINIDO. BUSCAR CÓDIGO!
  279.         'skin.droid': 50, # NO DEFINIDO. BUSCAR CÓDIGO!
  280.         'skin.quartz': 52, # NO DEFINIDO. BUSCAR CÓDIGO!
  281.         'skin.re-touched': 550, # NO DEFINIDO. BUSCAR CÓDIGO!
  282.         'skin.titan': 514, # NO DEFINIDO. BUSCAR CÓDIGO!
  283.     },    
  284. }
  285.  
  286.  
  287. # Write something on XBMC log
  288. def log(message):
  289.     xbmc.log(message)
  290.  
  291. # Write this module messages on XBMC log
  292. def _log(message):
  293.     if module_log_enabled:
  294.         xbmc.log("plugintools."+message)
  295.  
  296. # Parse XBMC params - based on script.module.parsedom addon    
  297. def get_params():
  298.     _log("get_params")
  299.    
  300.     param_string = sys.argv[2]
  301.    
  302.     _log("get_params "+str(param_string))
  303.    
  304.     commands = {}
  305.  
  306.     if param_string:
  307.         split_commands = param_string[param_string.find('?') + 1:].split('&')
  308.    
  309.        for command in split_commands:
  310.            _log("get_params command="+str(command))
  311.            if len(command) > 0:
  312.                if "=" in command:
  313.                    split_command = command.split('=')
  314.                    key = split_command[0]
  315.                    value = urllib.unquote_plus(split_command[1])
  316.                    commands[key] = value
  317.                else:
  318.                    commands[command] = ""
  319.    
  320.    _log("get_params "+repr(commands))
  321.    return commands
  322.  
  323. # Fetch text content from an URL
  324. def read(url):
  325.    _log("read "+url)
  326.  
  327.    f = urllib2.urlopen(url)
  328.    data = f.read()
  329.    f.close()
  330.    
  331.    return data
  332.  
  333. def read_body_and_headers(url, post=None, headers=[], follow_redirects=False, timeout=None):
  334.    _log("read_body_and_headers "+url)
  335.  
  336.    if post is not None:
  337.        _log("read_body_and_headers post="+post)
  338.  
  339.    if len(headers)==0:
  340.        headers.append(["User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/20100101 Firefox/18.0"])
  341.  
  342.     # Start cookie lib
  343.     ficherocookies = os.path.join( get_data_path(), 'cookies.dat' )
  344.     _log("read_body_and_headers cookies_file="+ficherocookies)
  345.  
  346.     cj = None
  347.     ClientCookie = None
  348.     cookielib = None
  349.  
  350.     # Let's see if cookielib is available
  351.     try:
  352.         _log("read_body_and_headers importing cookielib")
  353.         import cookielib
  354.     except ImportError:
  355.         _log("read_body_and_headers cookielib no disponible")
  356.         # If importing cookielib fails
  357.         # let's try ClientCookie
  358.         try:
  359.             _log("read_body_and_headers importing ClientCookie")
  360.             import ClientCookie
  361.         except ImportError:
  362.             _log("read_body_and_headers ClientCookie not available")
  363.             # ClientCookie isn't available either
  364.             urlopen = urllib2.urlopen
  365.             Request = urllib2.Request
  366.         else:
  367.             _log("read_body_and_headers ClientCookie available")
  368.             # imported ClientCookie
  369.             urlopen = ClientCookie.urlopen
  370.             Request = ClientCookie.Request
  371.             cj = ClientCookie.MozillaCookieJar()
  372.  
  373.     else:
  374.         _log("read_body_and_headers cookielib available")
  375.         # importing cookielib worked
  376.         urlopen = urllib2.urlopen
  377.         Request = urllib2.Request
  378.         cj = cookielib.MozillaCookieJar()
  379.         # This is a subclass of FileCookieJar
  380.         # that has useful load and save methods
  381.  
  382.     if cj is not None:
  383.     # we successfully imported
  384.     # one of the two cookie handling modules
  385.         _log("read_body_and_headers Cookies enabled")
  386.  
  387.         if os.path.isfile(ficherocookies):
  388.             _log("read_body_and_headers Reading cookie file")
  389.             # if we have a cookie file already saved
  390.             # then load the cookies into the Cookie Jar
  391.             try:
  392.                 cj.load(ficherocookies)
  393.             except:
  394.                 _log("read_body_and_headers Wrong cookie file, deleting...")
  395.                 os.remove(ficherocookies)
  396.  
  397.         # Now we need to get our Cookie Jar
  398.         # installed in the opener;
  399.         # for fetching URLs
  400.         if cookielib is not None:
  401.             _log("read_body_and_headers opener using urllib2 (cookielib)")
  402.             # if we use cookielib
  403.             # then we get the HTTPCookieProcessor
  404.             # and install the opener in urllib2
  405.             if not follow_redirects:
  406.                 opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=http_debug_log_enabled),urllib2.HTTPCookieProcessor(cj),NoRedirectHandler())
  407.             else:
  408.                 opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=http_debug_log_enabled),urllib2.HTTPCookieProcessor(cj))
  409.             urllib2.install_opener(opener)
  410.  
  411.         else:
  412.             _log("read_body_and_headers opener using ClientCookie")
  413.             # if we use ClientCookie
  414.             # then we get the HTTPCookieProcessor
  415.             # and install the opener in ClientCookie
  416.             opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cj))
  417.             ClientCookie.install_opener(opener)
  418.  
  419.     # -------------------------------------------------
  420.     # Cookies instaladas, lanza la petición
  421.     # -------------------------------------------------
  422.  
  423.     # Contador
  424.     inicio = time.clock()
  425.  
  426.     # Diccionario para las cabeceras
  427.     txheaders = {}
  428.  
  429.     # Construye el request
  430.     if post is None:
  431.         _log("read_body_and_headers GET request")
  432.     else:
  433.         _log("read_body_and_headers POST request")
  434.    
  435.     # Añade las cabeceras
  436.     _log("read_body_and_headers ---------------------------")
  437.     for header in headers:
  438.         _log("read_body_and_headers header %s=%s" % (str(header[0]),str(header[1])) )
  439.         txheaders[header[0]]=header[1]
  440.     _log("read_body_and_headers ---------------------------")
  441.  
  442.     req = Request(url, post, txheaders)
  443.     if timeout is None:
  444.         handle=urlopen(req)
  445.     else:        
  446.         #Disponible en python 2.6 en adelante --> handle = urlopen(req, timeout=timeout)
  447.         #Para todas las versiones:
  448.         try:
  449.             import socket
  450.             deftimeout = socket.getdefaulttimeout()
  451.             socket.setdefaulttimeout(timeout)
  452.             handle=urlopen(req)            
  453.             socket.setdefaulttimeout(deftimeout)
  454.         except:
  455.             import sys
  456.             for line in sys.exc_info():
  457.                 handle=urlopen(req)            
  458.                 _log( "%s" % line )
  459.    
  460.     # Actualiza el almacén de cookies
  461.     cj.save(ficherocookies)
  462.  
  463.     # Lee los datos y cierra
  464.     if handle.info().get('Content-Encoding') == 'gzip':
  465.         buf = StringIO( handle.read())
  466.         f = gzip.GzipFile(fileobj=buf)
  467.         data = f.read()
  468.     else:
  469.         data=handle.read()
  470.  
  471.     info = handle.info()
  472.     _log("read_body_and_headers Response")
  473.  
  474.     returnheaders=[]
  475.     _log("read_body_and_headers ---------------------------")
  476.     for header in info:
  477.         _log("read_body_and_headers "+header+"="+info[header])
  478.         returnheaders.append([header,info[header]])
  479.     handle.close()
  480.     _log("read_body_and_headers ---------------------------")
  481.  
  482.     '''
  483.     # Lanza la petición
  484.     try:
  485.         response = urllib2.urlopen(req)
  486.     # Si falla la repite sustituyendo caracteres especiales
  487.     except:
  488.         req = urllib2.Request(url.replace(" ","%20"))
  489.    
  490.         # Añade las cabeceras
  491.         for header in headers:
  492.             req.add_header(header[0],header[1])
  493.  
  494.         response = urllib2.urlopen(req)
  495.     '''
  496.    
  497.     # Tiempo transcurrido
  498.     fin = time.clock()
  499.     _log("read_body_and_headers Downloaded in %d seconds " % (fin-inicio+1))
  500.     _log("read_body_and_headers body="+data)
  501.    
  502.     return data,returnheaders
  503.  
  504. class NoRedirectHandler(urllib2.HTTPRedirectHandler):
  505.     def http_error_302(self, req, fp, code, msg, headers):
  506.         infourl = urllib.addinfourl(fp, headers, req.get_full_url())
  507.         infourl.status = code
  508.         infourl.code = code
  509.         return infourl
  510.     http_error_300 = http_error_302
  511.     http_error_301 = http_error_302
  512.     http_error_303 = http_error_302
  513.     http_error_307 = http_error_302
  514.  
  515. # Parse string and extracts multiple matches using regular expressions
  516. def find_multiple_matches(text,pattern):
  517.     _log("find_multiple_matches pattern="+pattern)
  518.    
  519.     matches = re.findall(pattern,text,re.DOTALL)
  520.  
  521.     return matches
  522.    
  523. def find_multiple_matches_multi(text,pattern):
  524.     _log("find_multiple_matches pattern="+pattern)
  525.    
  526.     matches = re.findall(pattern,text, re.MULTILINE)
  527.  
  528.     return matches 
  529.    
  530. def find_multiple_matches_multi_multi(text,pattern):
  531.     _log("find_multiple_matches pattern="+pattern)
  532.    
  533.     matches = re.findall(pattern,text, re.MULTILINE|re.DOTALL)
  534.  
  535.     return matches
  536.  
  537. import htmlentitydefs
  538. import re
  539.  
  540. pattern = re.compile("&(\w+?);")
  541.  
  542. def html_entity_decode_char(m, defs=htmlentitydefs.entitydefs):
  543.     try:
  544.         return defs[m.group(1)]
  545.     except KeyError:
  546.         return m.group(0)
  547.  
  548. def html_entity_decode(string):
  549.     return pattern.sub(html_entity_decode_char, string)
  550.    
  551. # Parse string and extracts first match as a string
  552. def find_single_match(text,pattern):
  553.     _log("find_single_match pattern="+pattern)
  554.  
  555.     result = ""
  556.     try:    
  557.         matches = re.findall(pattern,text, flags=re.DOTALL)
  558.         result = matches[0]
  559.     except:
  560.         result = ""
  561.  
  562.     return result
  563.  
  564. def add_item( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", pager="", info_labels = "", isPlayable = False , folder=True ):
  565.     #_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] pager=["+pager+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  566.  
  567.     listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  568.     if info_labels is None:
  569.         info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  570.     else:
  571.         #listitem.setInfo( "type", MOVIES )
  572.         listitem.setInfo( "video", info_labels )        
  573.  
  574.     if fanart!="":
  575.         listitem.setProperty('fanart_image',fanart)
  576.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  577.    
  578.     if url.startswith("plugin://"):
  579.         itemurl = url
  580.         listitem.setProperty('IsPlayable', 'false')
  581.         xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=folder)
  582.         xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
  583.     elif isPlayable:
  584.         listitem.setProperty("Video", "true")
  585.         listitem.setProperty('IsPlayable', 'true')
  586.         itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&&fanart=%s&plot=%s&extra=%s&page=%s&pager=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ), urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ), urllib.quote_plus( pager) )
  587.        xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=folder)
  588.    else:
  589.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&pager=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ), urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ), urllib.quote_plus( pager))
  590.        xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=folder)
  591.  
  592.  
  593. def addPeli( action="" , title="" , plot="" , photoa="", photob="", photoc="", photod="", url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", imdb="", info_labels = None, isPlayable = False , folder=True ):
  594.    #xbmc.log("addPeli action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] photoa=["+photoa+"] photob=["+photob+"] photoc=["+photoc+"] photod=["+photod+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  595.    
  596.    contexto = []
  597.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  598.    if info_labels is None:
  599.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  600.    listitem.setInfo( "type", MOVIES )
  601.    listitem.setInfo( "video", info_labels )
  602.    xbmcplugin.setContent( int(sys.argv[1]) ,"movies" )
  603.    
  604.    # Fotogramas de película (Fanart view)
  605.    if photoa!="":
  606.        listitem.setProperty('photoa',photoa)
  607.    if photob!="":
  608.        listitem.setProperty('photob',photob)
  609.    if photoc!="":
  610.        listitem.setProperty('photoc',photoc)
  611.    if photod!="":
  612.        listitem.setProperty('photod',photod)
  613.  
  614.    
  615.        
  616.    if fanart!="":
  617.        listitem.setProperty('fanart_image',fanart)
  618.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  619.    else:
  620.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  621.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  622.  
  623.    if isPlayable:
  624.        listitem.setProperty("Video", "True")
  625.        listitem.setProperty('IsPlayable', 'True')
  626.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )
  627.        contexto.append(('Ver trailer en [COLOR red]You[/COLOR][COLOR white]tube[/COLOR]', '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s' % (sys.argv[0], 'trailer0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  628.        contexto.append(('Crear [COLOR lightyellow][B]Wiki[/B]peli[/COLOR]', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'filmaff0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  629.        contexto.append(('[COLOR white]Información [B]extendida[/B][/COLOR]', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&imdb=%s)' % (sys.argv[0], 'extendedinfo' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ), urllib.quote_plus(imdb))))        
  630.        #contexto.append(('Buscar torrent [COLOR lightyellow][I](BUM+)[/I][/COLOR]', '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s' % (sys.argv[0], 'bum0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  631.        listitem.addContextMenuItems(contexto, replaceItems=True)
  632.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=False)
  633.        print 'sys.argv',sys.argv
  634.    
  635.    else:
  636.        listitem.setProperty("Video", "True")
  637.        listitem.setProperty('IsPlayable', 'False')
  638.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )        
  639.        contexto.append(('Ver trailer en [COLOR red]You[/COLOR][COLOR white]tube[/COLOR]', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'trailer0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  640.        contexto.append(('Crear [COLOR lightyellow][B]Wiki[/B]peli[/COLOR]', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'filmaff0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  641.        contexto.append(('[COLOR white]Información [B]extendida[/B][/COLOR]', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&imdb=%s)' % (sys.argv[0], 'extendedinfo' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ), urllib.quote_plus(imdb))))        
  642.        #contexto.append(('Buscar torrent [COLOR lightyellow][I](BUM+)[/I][/COLOR]', '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s' % (sys.argv[0], 'bum0' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  643.        listitem.addContextMenuItems(contexto, replaceItems=True)
  644.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=True)
  645.  
  646.  
  647. def addShow( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", info_labels = None, isPlayable = False , folder=False ):
  648.    #_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  649.    
  650.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  651.    if info_labels is None:
  652.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  653.    listitem.setInfo( "type", TV_SHOWS )
  654.    listitem.setInfo( "video", info_labels )
  655.    xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
  656.        
  657.    if fanart!="":
  658.        listitem.setProperty('fanart_image',fanart)
  659.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  660.    else:
  661.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  662.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  663.  
  664.    if isPlayable:
  665.        listitem.setProperty("Video", "True")
  666.        listitem.setProperty('IsPlayable', 'True')
  667.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )
  668.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=False)  
  669.    else:
  670.        listitem.setProperty('IsPlayable', 'False')
  671.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )        
  672.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=False)
  673.  
  674.  
  675. def addPic( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", info_labels = None, isPlayable = False , folder=True ):
  676.    _log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  677.    
  678.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  679.    if info_labels is None:
  680.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  681.    listitem.setInfo( "type", "pictures" )
  682.    listitem.setInfo( "pictures", info_labels )
  683.    xbmcplugin.setContent( int(sys.argv[1]) ,"pictures" )
  684.        
  685.    if fanart!="":
  686.        listitem.setProperty('fanart_image',fanart)
  687.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  688.    else:
  689.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  690.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  691.  
  692.    if isPlayable:
  693.        listitem.setProperty("Video", "True")
  694.        listitem.setProperty('IsPlayable', 'True')
  695.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )
  696.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=True)  
  697.    else:
  698.        listitem.setProperty('IsPlayable', 'False')
  699.        itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )        
  700.        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=True)
  701.        
  702.  
  703. def addDir( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", ext="", page="", info_labels = None, isPlayable = False , folder=True ):
  704.    #_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] ext=["+ext+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  705.    
  706.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  707.    if info_labels is None:
  708.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  709.    listitem.setInfo( "type", "other" )
  710.    listitem.setInfo( "video", info_labels )
  711.    xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
  712.        
  713.    if fanart!="":
  714.        listitem.setProperty('fanart_image',fanart)
  715.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  716.    else:
  717.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  718.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  719.  
  720.    listitem.setProperty('IsPlayable', 'False')
  721.    itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&ext=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( str(ext) ) , urllib.quote_plus( str(page) ) , get_setting("movies_id") )
  722.    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=True)
  723.  
  724.  
  725. def addScraper1( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , vistos="", novistos="", extra="", page="", info_labels = None, isPlayable = False , folder=True ):
  726.    #_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  727.    
  728.    contexto = []
  729.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  730.    if info_labels is None:
  731.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  732.    listitem.setInfo( "type", "other" )
  733.    listitem.setInfo( "video", info_labels )
  734.    xbmcplugin.setContent( int(sys.argv[1]) ,"movies" )
  735.  
  736.    if vistos != "":
  737.        listitem.setProperty('WatchedEpisodes',vistos)
  738.  
  739.    if novistos != "":
  740.        listitem.setProperty('UnwatchedEpisodes',novistos)        
  741.        
  742.    if fanart!="":
  743.        listitem.setProperty('fanart_image',fanart)
  744.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  745.    else:
  746.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  747.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  748.  
  749.    listitem.setProperty('IsPlayable', 'False')    
  750.    contexto.append(('Eliminar entrada', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'scraperx_supr' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  751.    contexto.append(('Eliminar TODA la lista', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'scraperx_delfile' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  752.    contexto.append(('Recargar lista', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'scraperx_reload' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  753.    contexto.append(('Exportar lista', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'scraperx_export' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))            
  754.    itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )
  755.    listitem.addContextMenuItems(contexto, replaceItems=True)            
  756.    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=True)
  757.  
  758. def addScraper2( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", info_labels = None, isPlayable = False , folder=True ):
  759.    #_log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  760.    
  761.    contexto = []
  762.    listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  763.    if info_labels is None:
  764.        info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  765.    listitem.setInfo( "type", "other" )
  766.    listitem.setInfo( "video", info_labels )
  767.    xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
  768.        
  769.    if fanart!="":
  770.        listitem.setProperty('fanart_image',fanart)
  771.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  772.    else:
  773.        listitem.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  774.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)
  775.  
  776.    listitem.setProperty('IsPlayable', 'False')
  777.    contexto.append(('Agregar a mi lista', 'XBMC.RunPlugin(%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s)' % (sys.argv[0], 'scraper_create_list' , urllib.quote_plus(title) , urllib.quote_plus(url), urllib.quote_plus(thumbnail), urllib.quote_plus(fanart) , urllib.quote_plus(plot) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))))
  778.    itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s&view=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ) , get_setting("movies_id") )
  779.    listitem.addContextMenuItems(contexto, replaceItems=True)            
  780.    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=itemurl, listitem=listitem, isFolder=False)
  781.    
  782.  
  783. def runAddon( action="" , title="" , plot="" , url="" , thumbnail="" , fanart="" , show="" , episode="" , extra="", page="", info_labels = None, isPlayable = False , folder=True ):
  784.    _log("add_item action=["+action+"] title=["+title+"] url=["+url+"] thumbnail=["+thumbnail+"] fanart=["+fanart+"] show=["+show+"] episode=["+episode+"] extra=["+extra+"] page=["+page+"] isPlayable=["+str(isPlayable)+"] folder=["+str(folder)+"]")
  785.  
  786.    liz = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
  787.    if info_labels is None: info_labels = { "Title" : title, "FileName" : title, "Plot" : plot }
  788.    else: liz.setInfo( "video", info_labels )
  789.  
  790.    if fanart!="":
  791.        liz.setProperty('fanart_image',fanart)
  792.         xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)   
  793.    else:
  794.        liz.setProperty('fanart_image', "%s/fanart.jpg" % addonPath)
  795.        xbmcplugin.setPluginFanart(int(sys.argv[1]), fanart)  
  796.  
  797.    if url.startswith("plugin://"):
  798.        if url.endswith("cfg&mode=1") == True:
  799.            print 'catcher Sportsdevil'
  800.            itemurl = url            
  801.            liz.setProperty('IsPlayable', 'true')
  802.            xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=liz, isFolder=False)      
  803.        elif url.find("plugin.video.live.streamspro") >= 0:
  804.            print 'Vídeo LiveStreamsPro'
  805.            liz.setProperty("Video", "False")
  806.            liz.setProperty('IsPlayable', 'False')  
  807.            xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=url, listitem=liz, isFolder=False )
  808.        elif url.startswith("plugin://plugin.video.dailymotion_com"):
  809.            itemurl = url
  810.            liz.setProperty('IsPlayable', 'True')
  811.            xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=liz, isFolder=False)            
  812.        else:
  813.            print 'Vídeo Youtube/Dailymotion'
  814.            liz.setProperty("Video", "True")
  815.            liz.setProperty('IsPlayable', 'False')  
  816.            itemurl = '%s?action=%s&title=%s&url=%s&thumbnail=%s&fanart=%s&plot=%s&extra=%s&page=%s' % ( sys.argv[ 0 ] , action , urllib.quote_plus( title ) , urllib.quote_plus(url) , urllib.quote_plus( thumbnail ) , urllib.quote_plus( fanart ) , urllib.quote_plus( plot ) , urllib.quote_plus( extra ) , urllib.quote_plus( page ))
  817.            xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=itemurl, listitem=liz, isFolder=False )            
  818.                        
  819.  
  820.    # plugin://plugin.video.live.streamspro/?url=plugin://plugin.video.SportsDevil/?mode=1&amp;item=catcher%3dstreams%26url=http://verdirectotv.com/tv/documentales/discovery.html%26referer=http://verdirectotv.com/&amp;mode=12&quot;)
  821.  
  822.  
  823. def close_item_list():
  824.     _log("close_item_list")
  825.  
  826.     xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
  827.  
  828. def play_resolved_url(url):
  829.     #_log("play_resolved_url ["+url+"]")
  830.  
  831.     listitem = xbmcgui.ListItem(path=url)
  832.     listitem.setProperty('IsPlayable', 'true')
  833.     return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
  834.  
  835. def direct_play(url):
  836.     _log("direct_play ["+url+"]")
  837.  
  838.     title = ""
  839.  
  840.     try:
  841.         xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", path=url)
  842.     except:
  843.         xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", )
  844.     xlistitem.setInfo( "video", { "Title": title } )
  845.  
  846.     playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
  847.     playlist.clear()
  848.     playlist.add( url, xlistitem )
  849.  
  850.     player_type = xbmc.PLAYER_CORE_AUTO
  851.     xbmcPlayer = xbmc.Player( player_type )
  852.     xbmcPlayer.play(playlist)
  853.  
  854. def show_picture(url):
  855.  
  856.     local_folder = os.path.join(get_data_path(),"images")
  857.     if not os.path.exists(local_folder):
  858.         try:
  859.             os.mkdir(local_folder)
  860.         except:
  861.             pass
  862.     local_file = os.path.join(local_folder,"temp.jpg")
  863.  
  864.     # Download picture
  865.     urllib.urlretrieve(url, local_file)
  866.    
  867.     # Show picture
  868.     xbmc.executebuiltin( "SlideShow("+local_folder+")" )
  869.  
  870. def get_temp_path():
  871.     _log("get_temp_path")
  872.  
  873.     dev = xbmc.translatePath( "special://temp/" )
  874.     _log("get_temp_path ->'"+str(dev)+"'")
  875.  
  876.     return dev
  877.  
  878. def get_runtime_path():
  879.     _log("get_runtime_path")
  880.  
  881.     dev = xbmc.translatePath( __settings__.getAddonInfo('Path') )
  882.     _log("get_runtime_path ->'"+str(dev)+"'")
  883.  
  884.     return dev
  885.  
  886. def get_data_path():
  887.     _log("get_data_path")
  888.  
  889.     dev = xbmc.translatePath( __settings__.getAddonInfo('Profile') )
  890.    
  891.     # Parche para XBMC4XBOX
  892.     if not os.path.exists(dev):
  893.         os.makedirs(dev)
  894.  
  895.     _log("get_data_path ->'"+str(dev)+"'")
  896.  
  897.     return dev
  898.  
  899. def get_setting(name):
  900.     _log("get_setting name='"+name+"'")
  901.  
  902.     dev = __settings__.getSetting( name )
  903.  
  904.     _log("get_setting ->'"+str(dev)+"'")
  905.  
  906.     return dev
  907.  
  908. def set_setting(name,value):
  909.     #_log("set_setting name='"+name+"','"+value+"'")
  910.  
  911.     __settings__.setSetting( name,value )
  912.  
  913. def open_settings_dialog():
  914.     _log("open_settings_dialog")
  915.  
  916.     __settings__.openSettings()
  917.  
  918. def get_localized_string(code):
  919.     _log("get_localized_string code="+str(code))
  920.  
  921.     dev = __language__(code)
  922.     print dev
  923.  
  924.     try:
  925.         dev = dev.encode("utf-8")
  926.     #data=body.encode("iso-8859-16")
  927.     #data=unicode(body.decode("utf-8"),"iso-8859-16")
  928.     #s = stripped.encode("iso 8859-16")
  929.     #s = unicode( s, "iso-8859-16" )
  930.     except:
  931.         pass
  932.  
  933.     _log("get_localized_string ->'"+dev+"'")
  934.  
  935.     return dev
  936.  
  937. def keyboard_input(default_text="", title="", hidden=False):
  938.     _log("keyboard_input default_text='"+default_text+"'")
  939.  
  940.     keyboard = xbmc.Keyboard(default_text,title,hidden)
  941.     keyboard.doModal()
  942.    
  943.     if (keyboard.isConfirmed()):
  944.         tecleado = keyboard.getText()
  945.     else:
  946.         tecleado = ""
  947.  
  948.     _log("keyboard_input ->'"+tecleado+"'")
  949.  
  950.     return tecleado
  951.  
  952.  
  953. def message(text1, text2="", text3=""):
  954.     _log("message text1='"+text1+"', text2='"+text2+"', text3='"+text3+"'")
  955.  
  956.     if text3=="":
  957.         xbmcgui.Dialog().ok( text1 , text2 )
  958.     elif text2=="":
  959.         xbmcgui.Dialog().ok( "" , text1 )
  960.     else:
  961.         xbmcgui.Dialog().ok( text1 , text2 , text3 )
  962.  
  963. def message_yes_no(text1, text2="", text3=""):
  964.     _log("message_yes_no text1='"+text1+"', text2='"+text2+"', text3='"+text3+"'")
  965.  
  966.     if text3=="":
  967.         yes_pressed = xbmcgui.Dialog().yesno( text1 , text2 )
  968.     elif text2=="":
  969.         yes_pressed = xbmcgui.Dialog().yesno( "" , text1 )
  970.     else:
  971.         yes_pressed = xbmcgui.Dialog().yesno( text1 , text2 , text3 )
  972.  
  973.     return yes_pressed
  974.  
  975. def selector(option_list,title="Select one"):
  976.     _log("selector title='"+title+"', options="+repr(option_list))
  977.  
  978.     dia = xbmcgui.Dialog()
  979.     selection = dia.select(title,option_list)
  980.     return selection
  981.  
  982. def set_view(view_mode, view_code=0):
  983.     _log("set_view view_mode='"+view_mode+"', view_code="+str(view_code))
  984.  
  985.     # Set the content for extended library views if needed
  986.     if view_mode==MOVIES:
  987.         _log("set_view content is movies")
  988.         xbmcplugin.setContent( int(sys.argv[1]) ,"movies" )
  989.     elif view_mode==TV_SHOWS:
  990.         _log("set_view content is tvshows")
  991.         xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
  992.     elif view_mode==SEASONS:
  993.         _log("set_view content is seasons")
  994.         xbmcplugin.setContent( int(sys.argv[1]) ,"seasons" )
  995.     elif view_mode==EPISODES:
  996.         _log("set_view content is episodes")
  997.         xbmcplugin.setContent( int(sys.argv[1]) ,"episodes" )
  998.     elif view_mode==TV:
  999.         _log("set_view content is channels")
  1000.         xbmcplugin.setContent( int(sys.argv[1]) ,"channels" )
  1001.     elif view_mode==MUSIC:
  1002.         _log("set_view content is music")
  1003.         xbmcplugin.setContent( int(sys.argv[1]) ,"music" )
  1004.     elif view_mode==BIGLIST:
  1005.         _log("set_view content is biglist")
  1006.         xbmcplugin.setContent( int(sys.argv[1]) ,"biglist" )        
  1007.      
  1008.  
  1009.     # Reads skin name
  1010.     skin_name = xbmc.getSkinDir()
  1011.     _log("set_view skin_name='"+skin_name+"'")
  1012.  
  1013.     try:
  1014.         if view_code==0:
  1015.             _log("set_view view mode is "+view_mode)
  1016.             view_codes = ALL_VIEW_CODES.get(view_mode)
  1017.             view_code = view_codes.get(skin_name)
  1018.             _log("set_view view code for "+view_mode+" in "+skin_name+" is "+str(view_code))
  1019.             xbmc.executebuiltin("Container.SetViewMode("+str(view_code)+")")
  1020.         else:
  1021.             _log("set_view view code forced to "+str(view_code))
  1022.             xbmc.executebuiltin("Container.SetViewMode("+str(view_code)+")")
  1023.     except:
  1024.         _log("Unable to find view code for view mode "+str(view_mode)+" and skin "+skin_name)
  1025.  
  1026. f = open( os.path.join( os.path.dirname(__file__) , "addon.xml") )
  1027. data = f.read()
  1028. f.close()
  1029.  
  1030. addon_id = find_single_match(data,'id="([^"]+)"')
  1031. if addon_id=="":
  1032.     addon_id = find_single_match(data,"id='([^']+)'")
  1033.  
  1034. __settings__ = xbmcaddon.Addon(id=addon_id)
  1035. __language__ = __settings__.getLocalizedString
  1036.  
  1037.  
  1038. def setview(view):
  1039.     xbmc.log("Ajustando modo de vista: "+view)
  1040.  
  1041.     if get_setting("unblockview") == "true":
  1042.         xbmc.executebuiltin("Container.SetViewMode("+view+")")
  1043.  
  1044. def setcontents(contents):
  1045.     xbmc.log("Ajustando contenidos: "+contents)
  1046.  
  1047.     if contents == "movies" or contents == "peliculas":
  1048.         xbmc.log("Contenidos: MOVIES")
  1049.         xbmcplugin.setContent(int(sys.argv[1]), "movies")
  1050.         view = get_setting("movies_id")
  1051.         xbmc.log("Modo de vista: "+view)
  1052.         xbmc.executebuiltin("Container.SetViewMode("+view+")")        
  1053.     elif contents == "series":
  1054.         xbmc.log("Contenidos: SERIES")
  1055.         xbmcplugin.setContent(int(sys.argv[1]), "episodes")
  1056.         view = get_setting("series_id")
  1057.         xbmc.log("Modo de vista: "+view)
  1058.         xbmc.executebuiltin("Container.SetViewMode("+view+")")        
  1059.     elif contents == "music":
  1060.         xbmc.log("Contenidos: MUSIC")
  1061.         xbmcplugin.setContent(int(sys.argv[1]), "musicvideos")
  1062.         view = get_setting("music_id")
  1063.         xbmc.log("Modo de vista: "+view)
  1064.         xbmc.executebuiltin("Container.SetViewMode("+view+")")
  1065.     elif contents == "tvshows":
  1066.         xbmc.log("Contenidos: CHANNELS")
  1067.         xbmcplugin.setContent(int(sys.argv[1]), "tvshows")
  1068.         view = get_setting("channels_id")
  1069.         xbmc.log("Modo de vista: "+view)
  1070.         xbmc.executebuiltin("Container.SetViewMode("+view+")")
  1071.     elif contents == "files":
  1072.         xbmc.log("Contenidos: FILES")
  1073.         xbmcplugin.setContent(int(sys.argv[1]), "files")
  1074.         view = get_setting("files_id")
  1075.         xbmc.log("Modo de vista: "+view)
  1076.         xbmc.executebuiltin("Container.SetViewMode("+view+")")
  1077.     else:
  1078.         xbmc.log("Contenidos: DEFAULT")
  1079.         xbmcplugin.setContent(int(sys.argv[1]), "files")
  1080.         view = get_setting("default_view")
  1081.         xbmc.log("Modo de vista: "+view)
  1082.         xbmc.executebuiltin("Container.SetViewMode("+view+")")        
  1083.  
  1084.      
  1085. def parseDOM(html, name=u"", attrs={}, ret=False):
  1086.     # Copyright (C) 2010-2011 Tobias Ussing And Henrik Mosgaard Jensen
  1087.  
  1088.     if isinstance(html, str):
  1089.         try:
  1090.             html = [html.decode("utf-8")] # Replace with chardet thingy
  1091.         except:
  1092.             html = [html]
  1093.     elif isinstance(html, unicode):
  1094.         html = [html]
  1095.     elif not isinstance(html, list):
  1096.         return u""
  1097.  
  1098.     if not name.strip():
  1099.         return u""
  1100.  
  1101.     ret_lst = []
  1102.     for item in html:
  1103.         temp_item = re.compile('(<[^>]*?\n[^>]*?>)').findall(item)
  1104.         for match in temp_item:
  1105.             item = item.replace(match, match.replace("\n", " "))
  1106.  
  1107.         lst = []
  1108.         for key in attrs:
  1109.             lst2 = re.compile('(<' + name + '[^>]*?(?:' + key + '=[\'"]' + attrs[key] + '[\'"].*?>))', re.M | re.S).findall(item)
  1110.             if len(lst2) == 0 and attrs[key].find(" ") == -1:  # Try matching without quotation marks
  1111.                 lst2 = re.compile('(<' + name + '[^>]*?(?:' + key + '=' + attrs[key] + '.*?>))', re.M | re.S).findall(item)
  1112.  
  1113.             if len(lst) == 0:
  1114.                 lst = lst2
  1115.                 lst2 = []
  1116.             else:
  1117.                 test = range(len(lst))
  1118.                 test.reverse()
  1119.                 for i in test:  # Delete anything missing from the next list.
  1120.                     if not lst[i] in lst2:
  1121.                         del(lst[i])
  1122.  
  1123.         if len(lst) == 0 and attrs == {}:
  1124.             lst = re.compile('(<' + name + '>)', re.M | re.S).findall(item)
  1125.             if len(lst) == 0:
  1126.                 lst = re.compile('(<' + name + ' .*?>)', re.M | re.S).findall(item)
  1127.  
  1128.         if isinstance(ret, str):
  1129.             lst2 = []
  1130.             for match in lst:
  1131.                 attr_lst = re.compile('<' + name + '.*?' + ret + '=([\'"].[^>]*?[\'"])>', re.M | re.S).findall(match)
  1132.                 if len(attr_lst) == 0:
  1133.                     attr_lst = re.compile('<' + name + '.*?' + ret + '=(.[^>]*?)>', re.M | re.S).findall(match)
  1134.                 for tmp in attr_lst:
  1135.                     cont_char = tmp[0]
  1136.                     if cont_char in "'\"":
  1137.                         # Limit down to next variable.
  1138.                         if tmp.find('=' + cont_char, tmp.find(cont_char, 1)) > -1:
  1139.                             tmp = tmp[:tmp.find('=' + cont_char, tmp.find(cont_char, 1))]
  1140.  
  1141.                         # Limit to the last quotation mark
  1142.                         if tmp.rfind(cont_char, 1) > -1:
  1143.                             tmp = tmp[1:tmp.rfind(cont_char)]
  1144.                     else:
  1145.                         if tmp.find(" ") > 0:
  1146.                             tmp = tmp[:tmp.find(" ")]
  1147.                         elif tmp.find("/") > 0:
  1148.                             tmp = tmp[:tmp.find("/")]
  1149.                         elif tmp.find(">") > 0:
  1150.                             tmp = tmp[:tmp.find(">")]
  1151.  
  1152.                     lst2.append(tmp.strip())
  1153.             lst = lst2
  1154.         else:
  1155.             lst2 = []
  1156.             for match in lst:
  1157.                 endstr = u"</" + name
  1158.                start = item.find(match)
  1159.                end = item.find(endstr, start)
  1160.                pos = item.find("<" + name, start + 1 )
  1161.                while pos < end and pos != -1:
  1162.                    tend = item.find(endstr, end + len(endstr))
  1163.                    if tend != -1:
  1164.                        end = tend
  1165.                    pos = item.find("<" + name, pos + 1)
  1166.                if start == -1 and end == -1:
  1167.                    temp = u""
  1168.                elif start > -1 and end > -1:
  1169.                     temp = item[start + len(match):end]
  1170.                 elif end > -1:
  1171.                     temp = item[:end]
  1172.                 elif start > -1:
  1173.                     temp = item[start + len(match):]
  1174.  
  1175.                 if ret:
  1176.                     endstr = item[end:item.find(">", item.find(endstr)) + 1]
  1177.                     temp = match + temp + endstr
  1178.  
  1179.                 item = item[item.find(temp, item.find(match)) + len(temp):]
  1180.                 lst2.append(temp)
  1181.             lst = lst2
  1182.         ret_lst += lst
  1183.  
  1184.     return ret_lst
  1185.         </content>
  1186.     </file>
  1187. </files>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement