El motivo de no usar dict en extra es simple, no lo acepta. Para cosas sencillas soluciones sencillas. El que no entienda lo que hace y como se usa split tampoco entenderá lo que son dicts.
para cosas simples split es lo más fácil, en el origen extra=texto y en el destino dict = item.extra.split como es el caso de los tres valores que muestras.
para un mazo gordo de datos, como es el caso de pepecine, split es una locura. O bien te lo curras haciendo scraped del texto que pasas en el atributo extra o el en destido el texto lo pasas a dict y queda más mono para el que lee el code
Te pego lo que hice cuando se inició el hilo de pepecine para poder hablar con fundamento y del que salió el esquema para la respuesta a la primera pregunta del hilo.
En episodios te he puesto unas líneas con print para que veas con claridad el tema del que se habla.
No espero respuestas de tipo esto no funciona, esto sí, esto me gusta, esto no me gusta, etc. Te lo paso para que puedas ver el conjunto que aunque no lo dices creo que el tema es por lo de pepecine
Código: Seleccionar todo
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# pelisalacarta - XBMC Plugin
# Canal para pepecine
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
#------------------------------------------------------------
import urlparse,urllib2,urllib,re
import os, sys
from core import logger
from core import config
from core import scrapertools
from core import jsontools
from core.item import Item
from servers import servertools
__channel__ = "pepecine"
__category__ = "F,S"
__type__ = "generic"
__title__ = "Pepecine"
__language__ = "ES"
host = "http://pepecine.com"
def isGeneric():
return True
def mainlist(item):
logger.info("[pepecine.py] mainlist")
itemlist = []
itemlist.append( Item( channel=__channel__, action="fichas", title="Películas", url=urlparse.urljoin(host,"peliculas-online"), extra="movie|1" ) )
itemlist.append( Item( channel=__channel__, action="fichas", title="Series", url=urlparse.urljoin(host,"series-online"), extra="series|1" ) )
return itemlist
def fichas(item):
logger.info("[pepecine.py] fichas")
itemlist = []
token = scrapertools.get_match(
scrapertools.cache_page(item.url),
"token: '([^']+)'"
)
## Fichas por páginas por contenedor. No es bueno meter muchas, puede causar error.
por_pagina = 20
pagina = int(item.extra.split('|')[1])
tipo = item.extra.split('|')[0]
path = "/titles/paginate?_token=%s&perPage=%s&page=%s&order=mc_num_of_votesDesc&type=%s&minRating=&maxRating=" % (token, por_pagina, pagina, tipo)
data = scrapertools.cache_page(urlparse.urljoin(host,path))
data_dict = jsontools.load_json(data)
id = 0
for ficha in data_dict['items']:
if id != ficha['id']:
title = ficha['title'] + \
" (" + \
verde%ficha['year'] + \
") (" + \
naranja%ficha['mc_user_score'] + \
") (" + \
azul%str(len(ficha['link'])) + \
" enlaces)"
url = str(ficha['id'])
plot = ficha['plot']
fanart = ficha['background']
thumbnail = ficha['poster']
fulltitle = ficha['title']
show = ficha['title']
## pasando de pijadas dict = literal string
extra = re.sub(
r".(u'episode': \d+), u'temp_id': [^,]+, (u'url': '[^']+'), (u'season': \d+), u'created_at': '[^']+', u'approved': \d+, u'updated_at': '[^']+', u'reports': \d+, (u'label': '[^']+'), u'type': '[^']+', u'id': \d+, u'negative_votes': \d+, (u'quality': '[^']+'), u'title_id': \d+, u'positive_votes': \d+.",
r'{\3, \1, \2, \4, \5}',
str(ficha['link'])
)
#extra = str(ficha['link'])
action = "findvideos"
if tipo == "series":
action = "episodios"
itemlist.append( Item( channel=__channel__, title=title, action=action, url=url, plot=plot, fanart=fanart, thumbnail=thumbnail, fulltitle=fulltitle, show=show, extra=extra) )
id = ficha['id']
if len(itemlist) == por_pagina and (por_pagina * pagina) < data_dict['totalItems']:
itemlist.append( Item( channel=__channel__, title=naranja % ">>Página siguiente", action="fichas", url=item.url, extra=tipo + "|" + str(pagina + 1)) )
return itemlist
def episodios(item):
logger.info("[pepecine.py] episodios")
print "## TEXT ##########################################"
print item.extra
print "## DICT ##########################################"
exec "extra_data = {u'links':" + item.extra + "}"
print extra_data['links']
print "##################################################"
itemlist = []
## pasando de pijadas dict = literal string
patron = "\{u'season': (\d+), u'episode': (\d+),"
enlaces = re.compile(patron,re.DOTALL).findall(item.extra)
s_e = set()
for season, episode in enlaces:
if ( str(season) + str(episode).zfill(2) ) not in s_e:
## pasando de pijadas dict = literal string
patron = "({u'season': " + season + ", u'episode': " + episode + ".*?})"
enlaces = re.compile(patron,re.DOTALL).findall(item.extra)
extra = ""
for link in enlaces:
extra+= link + "|"
extra = extra[:-1]
title = item.show + \
" - " + \
naranja%str(season) + \
"x" + \
naranja%str(episode).zfill(2) + \
" (" + \
azul%str(len(extra.split('|'))) + \
" enlaces)"
fulltitle = item.show + " - " + str(season) + "x" + str(episode).zfill(2)
itemlist.append( Item( channel=__channel__, title=title, action="findvideos", url=item.url, plot=item.plot, fanart=item.fanart, thumbnail=item.thumbnail, fulltitle=fulltitle, show=item.show, extra=extra) )
s_e.add( str(season) + str(episode).zfill(2) )
itemlist = sorted(itemlist, key=lambda item: item.title)
return itemlist
def findvideos(item):
logger.info("[pepecine.py] findvideos")
itemlist = []
## pasando de pijadas dict = literal string
patron = "'url': '([^']+)'.*?'label': '([^']+)'.*?'quality': '([^']+)'"
enlaces = re.compile(patron,re.DOTALL).findall(item.extra)
for url, lang, quality in enlaces:
title = "Ver en " + \
azul%servertools.get_server_from_url(url) + \
" (" + \
verde%quality + \
") (" + \
naranja%lang + \
")"
url = url
plot = item.plot
fanart = item.fanart
thumbnail = item.thumbnail
fulltitle = item.fulltitle
show = item.show
itemlist.append( Item( channel=__channel__, title=title, action="play", url=url, plot=plot, fanart=fanart, thumbnail=thumbnail, fulltitle=fulltitle, show=show, folder=False ) )
return itemlist
def play(item):
logger.info("[pepecine.py] play")
itemlist = servertools.find_video_items(data=item.url)
for videoitem in itemlist:
videoitem.title = item.show
videoitem.fulltitle = item.fulltitle
videoitem.thumbnail = item.thumbnail
videoitem.channel = __channel__
return itemlist
if config.is_xbmc():
azul = "[COLOR blue]%s[/COLOR]"
naranja = "[COLOR orange]%s[/COLOR]"
rojo = "[COLOR red]%s[/COLOR]"
verde = "[COLOR green]%s[/COLOR]"
else:
azul = '<span style="color: blue">%s</span>'
naranja = '<span style="color: orange">%s</span>'
rojo = '<span style="color: red">%s</span>'
verde = '<span style="color: green">%s</span>'