Página 1 de 1

Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 05:57
por zanzibar1982
Come potete vedere dall'orario, non ci ho dormito tornato da lavoro.

Il lavoro estenuante di dentaku65 sul canale in oggetto ricalca il mio iniziale,

e come il mio incappa nello stesso errore: mandare alla ricerca il nome del regista/attore.

Questo porta ad una ricerca spesso incompleta o errata nei risultati offerti dai siti,

per cui l'unica cosa da fare è trovare un sito che ospiti il database più vasto possibile

di informazioni circa registi ed attori/attrici, con tanto di filmografia, dal quale estrarre

una lista di titoli che permetta all'utente di scegliere direttamente quale film cercare.

Questo velocizzerebbe anche la funzione di per sè, non dovendo l'utente attendere la ricerca

dei titoli disponibili fatta in base al nome.

Quindi ho deciso di postare qui il lavoro appena fatto con http://www.ibs.it/ che offre tra i siti che

mi sono stati proposti, il database più ampio, nonchè una distinzione dei titoli per genere.

So che c'è molta strada da fare per arrivare alla perfezione di questa funzione,

ma non si può dire che non ne valga la pena.

Il problema principale resta la mia inesperienza, quindi sono qui a mettere "il palo" per segnare

fin dove sono arrivato.

Ma cominciamo allegando lo script del canale:

Código: Seleccionar todo

# -*- coding: utf-8 -*-
#------------------------------------------------------------
# streamondemand - XBMC Plugin
# Ricerca "Biblioteca"
# http://www.mimediacenter.info/foro/viewforum.php?f=36
#------------------------------------------------------------
import urlparse,urllib2,urllib,re
import os, sys
import time

from core import logger
from core import config
from core import scrapertools
from core.item import Item
from servers import servertools

__channel__ = "bibliotecaregisti"
__category__ = "F"
__type__ = "generic"
__title__ = "Bibliotecaregisti"
__language__ = "IT"

host = "http://www.ibs.it"

DEBUG = config.get_setting("debug")

def isGeneric():
    return True

def mainlist(item):
    logger.info("streamondemand.biblioteca mainlist")
    itemlist = []
    itemlist.append( Item(channel=__channel__, title="[COLOR azure]Indice Registi [A-Z][/COLOR]", action="cat_lettera", url="http://www.ibs.it/dvd/lista+registi.html", thumbnail="http://cinema.clubefl.gr/wp-content/themes/director-theme/images/logo.png"))
    itemlist.append( Item(channel=__channel__, title="[COLOR azure]Indice Attori/Attrici [A-Z][/COLOR]", action="cat_lettera", url="http://www.ibs.it/dvd-film/lista-attori.html", thumbnail="http://cinema.clubefl.gr/wp-content/themes/director-theme/images/logo.png"))
    #itemlist.append( Item(channel=__channel__, title="[COLOR azure]Film per Attori/Attrici[/COLOR]", action="cat_attori", url="http://altadefinizione.co/attori/", thumbnail="http://repository-butchabay.googlecode.com/svn/branches/eden/skin.cirrus.extended.v2/extras/moviegenres/All%20Movies%20by%20Actor.png"))
    itemlist.append( Item(channel=__channel__, title="[COLOR azure]Elenco Film [A-Z][/COLOR]", action="categorias", url="http://www.darkstream.tv/", thumbnail="http://repository-butchabay.googlecode.com/svn/branches/eden/skin.cirrus.extended.v2/extras/moviegenres/Movies%20A-Z.png"))
    #itemlist.append( Item(channel=__channel__, title="[COLOR yellow]Cerca...[/COLOR]", action="search", thumbnail="http://dc467.4shared.com/img/fEbJqOum/s7/13feaf0c8c0/Search"))

    return itemlist

def cat_lettera(item):
    logger.info("streamondemand.biblioteca cat_registi_A")
    itemlist = []

    data = scrapertools.cache_page(item.url)
    logger.info(data)

    # Narrow search by selecting only the combo
    bloque = scrapertools.get_match(data, '<span style="font-size:16pt;">A</span>(.*?)</TD></TR></TBODY></TABLE></center><p><p>')
    
    # Extrae las entradas (carpetas)
    patron = '<a href="(.*?)" style="text-decoration:none;font-size:9pt;">(.*?)</a>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    scrapertools.printMatches(matches)

    for scrapedurl, scrapedtitle in matches:
        url = host + scrapedurl
        itemlist.append( Item(channel=__channel__, action="cat_ruolo", title= scrapedtitle, url=url, folder=True) )

    return itemlist

def cat_ruolo(item):
    logger.info("streamondemand.biblioteca cat_registi_A")
    itemlist = []

    data = scrapertools.cache_page(item.url)
    logger.info(data)

    # Narrow search by selecting only the combo
    bloque = scrapertools.get_match(data, '<td bgColor=#ffffff width="33%"><table width="100%"><tr><td bgcolor="eeeee4">(.*?)</font></td></tr></table></td>')
    
    # Extrae las entradas (carpetas)
    patron = '<a href="(.*?)">(.*?)</a>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    scrapertools.printMatches(matches)

    for scrapedurl, scrapedtitle in matches:
        url = host + scrapedurl
        itemlist.append( Item(channel=__channel__, action="cat_filmografia", title= scrapedtitle, url=url, folder=True) )

    return itemlist

def cat_filmografia(item):
    logger.info("streamondemand.biblioteca cat_registi_A")
    itemlist = []

    data = scrapertools.cache_page(item.url)
    logger.info(data)
    
    # Extrae las entradas (carpetas)
    patron = '<td width="90" valign="middle" height="120"><a href=".*?<img alt="(.*?)" border="0" src="(.*?)"></a></td>'
    matches = re.compile(patron,re.DOTALL).findall(data)
    scrapertools.printMatches(matches)

    for scrapedtitle, scrapedthumbnail in matches:
        titolo = scrapedtitle.replace(" ","+")
        itemlist.append( Item(channel=__channel__, action="do_search", extra=titolo, title= scrapedtitle , thumbnail=scrapedthumbnail, folder=True) )

    return itemlist

def do_search(item):
    logger.info("streamondemand.channels.bibliotecaregisti do_search")

    tecleado = item.extra
    mostra = tecleado.replace("+"," ")

    itemlist = []

    import os
    import glob
    import imp

    master_exclude_data_file = os.path.join( config.get_runtime_path() , "resources", "biblioteca.txt")
    logger.info("streamondemand.channels.buscador master_exclude_data_file="+master_exclude_data_file)

    exclude_data_file = os.path.join( config.get_data_path() , "biblioteca.txt")
    logger.info("streamondemand.channels.buscador exclude_data_file="+exclude_data_file)

    channels_path = os.path.join( config.get_runtime_path() , "channels" , '*.py' )
    logger.info("streamondemand.channels.buscador channels_path="+channels_path)

    excluir=""

    if os.path.exists(master_exclude_data_file):
        logger.info("streamondemand.channels.buscador Encontrado fichero exclusiones")

        fileexclude = open(master_exclude_data_file,"r")
        excluir= fileexclude.read()
        fileexclude.close()
    else:
        logger.info("streamondemand.channels.buscador No encontrado fichero exclusiones")
        excluir = "seriesly\nbuscador\ntengourl\n__init__"

    if config.is_xbmc():
        show_dialog = True

    try:
        import xbmcgui
        progreso = xbmcgui.DialogProgressBG()
        progreso.create("Ricerca di "+ mostra.title())
    except:
        show_dialog = False

    channel_files = glob.glob(channels_path)
    number_of_channels = len(channel_files)

    for index, infile in enumerate(channel_files):
        percentage = index*100/number_of_channels

        basename = os.path.basename(infile)
        basename_without_extension = basename[:-3]
        
        if basename_without_extension not in excluir:

            if show_dialog:
                progreso.update(percentage, ' Sto cercando "' + mostra+ '"')

            logger.info("streamondemand.channels.buscador Tentativo di ricerca su " + basename_without_extension + " per "+ mostra)
            try:

                # http://docs.python.org/library/imp.html?highlight=imp#module-imp
                obj = imp.load_source(basename_without_extension, infile)
                logger.info("streamondemand.channels.buscador cargado " + basename_without_extension + " de "+ infile)
                channel_result_itemlist = obj.search( Item() , tecleado)
                for item in channel_result_itemlist:
                    item.title = scrapertools.decodeHtmlentities( item.title )
                    item.title = item.title + " [COLOR orange]su[/COLOR] [COLOR green]" + basename_without_extension + "[/COLOR]"
                    item.viewmode = "list"

                itemlist.extend( channel_result_itemlist )
            except:
                import traceback
                logger.error( traceback.format_exc() )

        else:
            logger.info("streamondemand.channels.buscador do_search_results, Escluso il server " + basename_without_extension)

    itemlist = sorted(itemlist, key=lambda Item: Item.title) 

    if show_dialog:
        progreso.close()

    return itemlist
Dunque.

Per poter testare lo script basta copiarlo e sostituirlo a ciò che è contenuto nel canale edito da dentaku, "bibliotecaregisti.py".

Propongo di ritornare al nome "biblioteca.py", dato che col sistema che ho applicato, con lo stesso

lavoro si ottengono le liste alfabetiche di registi, attori e attrici, e volendo anche per genere.

Primo problema: la lettera "A" non appare nella lista. Ciò è dovuto al fatto che la prima pagina dell'ordine alfabetico sul sito

è la stessa lettera "A", ed è esclusa dall'alfabeto nell'html. Provate a cercare "q=B", "q=C" in questo html

http://www.ibs.it/dvd-film/lista-registi.html e vi renderete conto. Aprendo una qualsiasi pagina relativa ad una lettera

diversa dalla "A", ovviamente questa sarà presente. Io non ho abbastanza competenze per creare una lista

da B a Z che abbia in testa la lettera A estratta da un'altra pagina.

Secondo problema: per qualche motivo a me ignoto, cercando di accedere alla lettera "B" si ha un errore.

Le altre lettere invece "funzionano".

Terzo problema: i risultati che si ottengono per ogni lettera dalla "C" in poi. Credo siano evidenti i numerosi

campi estratti erroneamente.

Dato che sul sito stesso e per ogni lettera nell'html artisti ed attori sono riportati in due modi diversi,

ho trovato due espressioni per estrarli. Il problema è che ogni espressione esclude i risultati dell'altra.

Ed io non sono capace di estrarre un'unica lista composta da due espressioni diverse.

L'espressione che ho usato nel canale di cui sopra è:

Código: Seleccionar todo

patron = '<a href="(.*?)">(.*?)</a>'
l'alternativa invece sarebbe:

Código: Seleccionar todo

<a rel="nofollow" href="(.*?)">(.*?)</a>
Per quale motivo abbia dovuto usare la prima anzichè la seconda espressione?

Per i registi/attori estraibili nel 1° modo, la visualizzazione delle opere è fatta così:
http://www.ibs.it/dvd-film/regista/david-lynch.html

Invece per i secondi, così:
http://www.ibs.it/dvd-film/d'angelo-nin ... 9605_.html

Quindi ancora, mi ritrovo di fronte al fatto di non essere capace di unire in una sola lista il risultato

di due patron. Ho quindi optato per il patron legato a registi ed attori più prolifici.

Andrebbe fatto quello che DrZ3r0 fece con il canale di cb01, facendo in modo

che se "peliculasrobalo" fallisce, allora "peliculas" subentra.

Giunti alla lista dei titoli, il resto è facile.

Si dovrebbe togliere dalla lista di canali da escludere dalla ricerca cineblog01,

poichè indirizzato col titolo esatto fornisce buoni risultati.

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 09:27
por robalo
Hola zanzibar. Me has mandado un mensaje privado con un enlace a este hilo como único contenido y aquí estoy.
No consigo entender el propósito del script como canal y el porqué de llamarlo librería. ¿No es ibs.it una web de ventas de DVDs?
Tampoco consigo entender el propósito de usar altadefinizione.co en un canal que se llame librería.

De todas formas si existen diferenciás en los datos al que se le tienen que hacer el scraped de un mismo contenido, lo que yo intentaría sería, intentar igualar los datos para usar un sólo patrón.

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 12:07
por DrZ3r0
Ciao,
visto che l'alfabeto non cambia, invece di leggerlo dalla pagine lo metterei cabalto: cioè aggiungere a mano gli item da A a Z con i link http://www.ibs.it/dvd/ser/serreg.asp?q=A fino a http://www.ibs.it/dvd/ser/serreg.asp?q=Z. La stessa cosa per gli attori.

Se attori e registri richiedono filtri diversi, fai due funzioni python distinte è inutile insistere a volerne fare solo una.

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 13:03
por DrZ3r0
Prova questo: http://pastebin.com/hTihAJiN
e fammi sapere se ti accomoda.

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 13:53
por dentaku65
DrZ3r0 escribió:Prova questo: http://pastebin.com/hTihAJiN
e fammi sapere se ti accomoda.
ho provato, ma il problema è che se scegli un artista arrivi fino alla lista dei suoi film e quindi fai una ricerca finale sul titolo del film e non una ricerca sul nome dell'artista...

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 16:04
por zanzibar1982
dentaku65 escribió:
DrZ3r0 escribió:Prova questo: http://pastebin.com/hTihAJiN
e fammi sapere se ti accomoda.
ho provato, ma il problema è che se scegli un artista arrivi fino alla lista dei suoi film e quindi fai una ricerca finale sul titolo del film e non una ricerca sul nome dell'artista...
@dentaku65 infatti è quello che cerco di fare. Effettuare cioè la ricerca sui canali per l'opera selezionata dalla lista
offerta dalla filmografia di ogni attore o regista, anzichè cercare i nomi di questi. Non so se mi spiego.
E' anche tutto più veloce così, no? Cioè prova a cercare qualsiasi film di David Lynch, ti trova tutto!
EDIT: ho preso il canale da lì, infatti ora è tutto okay. Thanks!

@robalo Hi master! :) Yes, I wanted you to check this too. You are right, ibs is not a streaming site.
But no, I'm not gone dumb that much. This actually makes some sense :D Please let me try to explain better.
I recommend you to check what I'm trying to say downloading the addon in my signature first.
That is what we're working on.
If you check the "Oggi in tv" option in main menù ("filmontv.py" channel) you'll easily
understand what we're trying to do: to scrape the list of actors and directors and their relative filmography from ibs site,
so that when user selects one of their movies, that "scrapedtitle" is sent to an adjusted "global search" engine
that looks for the movie on many sites. Just as an online "biblioteca" :)

"Oggi in tv" works scraping movie titles on comingsoon.it, a site that offers a detailed real time italian tv-guide,
for movies given on tv on date. So you can search a movie aired on tv in that exact moment
through the available channels. I hope I explained myself. The reason for that is because
a lot of people likes to see what's on tv NOW instead of searching for a movie or see the newest contents
offered by their favourite channel.

We're adjusting little by little the "anadir a la libreria de Kodi" option, and it has nothing to do with this post,
so don't get confused.

@DrZ3r0 Edito il messaggio, ti devo fare una statua :D
Grazie!

Resta da fixare il fatto che la visualizzazione delle opere per attori o artisti poco prolifici restituisce una blank list.
Mi auto-quoto:
Per i registi/attori estraibili nel 1° modo, la visualizzazione delle opere è fatta così:
http://www.ibs.it/dvd-film/regista/david-lynch.html

Invece per i secondi, così:
http://www.ibs.it/dvd-film/d'angelo-nin ... 9605_.html

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 16:13
por dentaku65
@zanzibar... prendi il canali biblioteca.py che ho messo su, c'e' un piccolo errore nel pastebin

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 27 Sep 2015, 16:20
por zanzibar1982
dentaku65 escribió:@zanzibar... prendi il canali biblioteca.py che ho messo su, c'e' un piccolo errore nel pastebin
Thanks, ho editato. ;)

Re: Stream On Demand - Canale Biblioteca - Direzione Genesis

Publicado: 28 Sep 2015, 12:37
por robalo
zanzibar1982 escribió:@robalo Hi master! :) Yes, I wanted you to check this too. You are right, ibs is not a streaming site.
But no, I'm not gone dumb that much. This actually makes some sense :D Please let me try to explain better.
I recommend you to check what I'm trying to say downloading the addon in my signature first.
That is what we're working on.
If you check the "Oggi in tv" option in main menù ("filmontv.py" channel) you'll easily
understand what we're trying to do: to scrape the list of actors and directors and their relative filmography from ibs site,
so that when user selects one of their movies, that "scrapedtitle" is sent to an adjusted "global search" engine
that looks for the movie on many sites. Just as an online "biblioteca" :)

"Oggi in tv" works scraping movie titles on comingsoon.it, a site that offers a detailed real time italian tv-guide,
for movies given on tv on date. So you can search a movie aired on tv in that exact moment
through the available channels. I hope I explained myself. The reason for that is because
a lot of people likes to see what's on tv NOW instead of searching for a movie or see the newest contents
offered by their favourite channel.

We're adjusting little by little the "anadir a la libreria de Kodi" option, and it has nothing to do with this post,
so don't get confused.
He etendido desde el primer momento lo que se quiere conseguir. Es bastante obvio que se intenta conseguir la filmografía de un actor concreto. Lo que confunde y no lo digo por mí, es "librería" y más aún unido al propósito de canal