Advertisement
Guest User

italiafilm

a guest
Aug 24th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.26 KB | None | 0 0
  1. # -*- coding: iso-8859-1 -*-
  2. # ------------------------------------------------------------
  3. # streamondemand.- XBMC Plugin
  4. # Canal para italiafilm
  5. # http://blog.tvalacarta.info/plugin-xbmc/streamondemand.
  6. # ------------------------------------------------------------
  7. import re
  8. import urlparse
  9.  
  10. from core import config
  11. from core import logger
  12. from core import scrapertools
  13. from core.item import Item
  14. from core.tmdb import infoSod
  15. from servers import servertools
  16.  
  17. __channel__ = "italiafilm"
  18. __category__ = "F,S,A"
  19. __type__ = "generic"
  20. __title__ = "Italia-Film.co"
  21. __language__ = "IT"
  22.  
  23. DEBUG = config.get_setting("debug")
  24.  
  25. host = "http://www.italia-film.co"
  26.  
  27. headers = [
  28.     ['User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0'],
  29.     ['Accept-Encoding', 'gzip, deflate']
  30. ]
  31.  
  32.  
  33. def isGeneric():
  34.     return True
  35.  
  36.  
  37. def mainlist(item):
  38.     logger.info("[italiafilm.py] mainlist")
  39.     itemlist = [Item(channel=__channel__,
  40.                      title="[COLOR azure]Film - Novita'[/COLOR]",
  41.                      action="peliculas",
  42.                      url="%s/category/category/film-streaming-2016/" % host,
  43.                      thumbnail="http://orig03.deviantart.net/6889/f/2014/079/7/b/movies_and_popcorn_folder_icon_by_matheusgrilo-d7ay4tw.png"),
  44.                 Item(channel=__channel__,
  45.                      title="[COLOR azure]Film HD[/COLOR]",
  46.                      action="peliculas",
  47.                      url="%s/category/film-hd/" % host,
  48.                      thumbnail="http://i.imgur.com/3ED6lOP.png"),
  49.                 Item(channel=__channel__,
  50.                      title="[COLOR azure]Anime e Cartoon[/COLOR]",
  51.                      action="peliculas",
  52.                      url="%s/category/anime-e-cartoon/" % host,
  53.                      thumbnail="http://orig09.deviantart.net/df5a/f/2014/169/2/a/fist_of_the_north_star_folder_icon_by_minacsky_saya-d7mq8c8.png"),
  54.                 Item(channel=__channel__,
  55.                      title="[COLOR yellow]Cerca...[/COLOR]",
  56.                      action="search",
  57.                      thumbnail="http://dc467.4shared.com/img/fEbJqOum/s7/13feaf0c8c0/Search"),
  58.                 Item(channel=__channel__,
  59.                      title="[COLOR azure]Serie TV[/COLOR]",
  60.                      action="peliculas_tv",
  61.                      extra="serie",
  62.                      url="%s/category/telefilm/" % host,
  63.                      thumbnail="http://xbmc-repo-ackbarr.googlecode.com/svn/trunk/dev/skin.cirrus%20extended%20v2/extras/moviegenres/New%20TV%20Shows.png"),
  64.                  Item(channel=__channel__,
  65.                       title="[COLOR azure]Ultime serie TV[/COLOR]",
  66.                       action="pel_tv",
  67.                       extra="serie",
  68.                       url="%s/ultimi-telefilm-streaming/" % host,
  69.                       thumbnail="http://xbmc-repo-ackbarr.googlecode.com/svn/trunk/dev/skin.cirrus%20extended%20v2/extras/moviegenres/All%20Movies%20by%20Genre.png"),
  70.                       Item(channel=__channel__,
  71.                       title="[COLOR azure]Ultimi anime inseriti[/COLOR]",
  72.                       action="anime",
  73.                       extra="serie",
  74.                       url="%s/ultimi-telefilm-streaming/" % host,
  75.                       thumbnail="http://xbmc-repo-ackbarr.googlecode.com/svn/trunk/dev/skin.cirrus%20extended%20v2/extras/moviegenres/All%20Movies%20by%20Genre.png"),  
  76.                  Item(channel=__channel__,
  77.                       title="[COLOR yellow]Cerca Serie TV...[/COLOR]",
  78.                       action="search",
  79.                       extra="serie",
  80.                       thumbnail="http://dc467.4shared.com/img/fEbJqOum/s7/13feaf0c8c0/Search")]
  81.     return itemlist
  82.  
  83.  
  84. def categorias(item):
  85.     logger.info("[italiafilm.py] categorias")
  86.     itemlist = []
  87.  
  88.     data = scrapertools.cache_page(item.url)
  89.     data = scrapertools.find_single_match(data, '<a href=".">Categorie</a>(.*?)</div>')
  90.  
  91.     patron = '<li[^>]+><a href="([^"]+)">([^<]+)</a></li>'
  92.     matches = re.compile(patron, re.DOTALL).findall(data)
  93.     scrapertools.printMatches(matches)
  94.  
  95.     for url, title in matches:
  96.         scrapedtitle = title
  97.         scrapedurl = urlparse.urljoin(item.url, url)
  98.         scrapedplot = ""
  99.         scrapedthumbnail = ""
  100.         if DEBUG: logger.info(
  101.             "title=[" + scrapedtitle + "], url=[" + scrapedurl + "], thumbnail=[" + scrapedthumbnail + "]")
  102.         itemlist.append(
  103.             Item(channel=__channel__,
  104.                  action='peliculas',
  105.                  title="[COLOR azure]" + scrapedtitle + "[/COLOR]",
  106.                  url=scrapedurl,
  107.                  thumbnail=scrapedthumbnail,
  108.                  plot=scrapedplot,
  109.                  folder=True))
  110.  
  111.     return itemlist
  112.  
  113.  
  114. def search(item, texto):
  115.     logger.info("[italiafilm.py] search " + texto)
  116.  
  117.     try:
  118.         if item.extra == "serie":
  119.             item.url = host + "/?s=" + texto
  120.             return peliculas_tv(item)
  121.         else:
  122.             item.url = host + "/?s=" + texto
  123.             return peliculas(item)
  124.     # Se captura la excepcion, para no interrumpir al buscador global si un canal falla
  125.     except:
  126.         import sys
  127.         for line in sys.exc_info():
  128.             logger.error("%s" % line)
  129.         return []
  130.  
  131.  
  132. def peliculas(item):
  133.     logger.info("[italiafilm.py] peliculas")
  134.     itemlist = []
  135.  
  136.     data = scrapertools.cache_page(item.url)
  137.     patron = '<article(.*?)</article>'
  138.     matches = re.compile(patron, re.DOTALL).findall(data)
  139.  
  140.     for match in matches:
  141.         title = scrapertools.find_single_match(match, '<h3[^<]+<a href="[^"]+"[^<]+>([^<]+)</a>')
  142.         title = title.replace("Streaming", "")
  143.         title = scrapertools.decodeHtmlentities(title).strip()
  144.         url = scrapertools.find_single_match(match, '<h3[^<]+<a href="([^"]+)"')
  145.         plot = ""
  146.         thumbnail = scrapertools.find_single_match(match, 'data-echo="([^"]+)"')
  147.  
  148.         if (DEBUG): logger.info("title=[" + title + "], url=[" + url + "], thumbnail=[" + thumbnail + "]")
  149.  
  150.         itemlist.append(infoSod(
  151.             Item(channel=__channel__,
  152.                  action='episodios' if item.extra == 'serie' else 'findvideos',
  153.                  fulltitle=title,
  154.                  show=title,
  155.                  title="[COLOR azure]" + title + "[/COLOR]",
  156.                  url=url,
  157.                  thumbnail=thumbnail,
  158.                  plot=plot,
  159.                  viewmode="movie_with_plot",
  160.                  folder=True), tipo='movie'))
  161.  
  162.     # Siguiente
  163.     try:
  164.         pagina_siguiente = scrapertools.get_match(data, '<a class="next page-numbers" href="([^"]+)"')
  165.         itemlist.append(
  166.             Item(channel=__channel__,
  167.                  action="HomePage",
  168.                  title="[COLOR yellow]Torna Home[/COLOR]",
  169.                  folder=True)),
  170.         itemlist.append(
  171.             Item(channel=__channel__,
  172.                  action="peliculas",
  173.                  extra=item.extra,
  174.                  title="[COLOR orange]Successivo >> [/COLOR]",
  175.                  url=pagina_siguiente,
  176.                  thumbnail="http://2.bp.blogspot.com/-fE9tzwmjaeQ/UcM2apxDtjI/AAAAAAAAeeg/WKSGM2TADLM/s1600/pager+old.png",
  177.                  folder=True))
  178.     except:
  179.         pass
  180.  
  181.     return itemlist
  182.  
  183.  
  184. def peliculas_tv(item):
  185.     logger.info("[italiafilm.py] peliculas")
  186.     itemlist = []
  187.  
  188.     data = scrapertools.cache_page(item.url)
  189.     patron = '<article(.*?)</article>'
  190.     matches = re.compile(patron, re.DOTALL).findall(data)
  191.  
  192.     for match in matches:
  193.         title = scrapertools.find_single_match(match, '<h3[^<]+<a href="[^"]+"[^<]+>([^<]+)</a>')
  194.         title = title.replace("Streaming", "")
  195.         title = scrapertools.decodeHtmlentities(title).strip()
  196.         url = scrapertools.find_single_match(match, '<h3[^<]+<a href="([^"]+)"')
  197.         plot = ""
  198.         thumbnail = scrapertools.find_single_match(match, 'data-echo="([^"]+)"')
  199.  
  200.         if (DEBUG): logger.info("title=[" + title + "], url=[" + url + "], thumbnail=[" + thumbnail + "]")
  201.  
  202.         itemlist.append(infoSod(
  203.             Item(channel=__channel__,
  204.                  action='episodios' if item.extra == 'serie' else 'findvideos',
  205.                  fulltitle=title,
  206.                  show=title,
  207.                  title="[COLOR azure]" + title + "[/COLOR]",
  208.                  url=url,
  209.                  thumbnail=thumbnail,
  210.                  plot=plot,
  211.                  viewmode="movie_with_plot",
  212.                  folder=True), tipo='tv'))
  213.  
  214.     # Siguiente
  215.     try:
  216.         pagina_siguiente = scrapertools.get_match(data, '<a class="next page-numbers" href="([^"]+)"')
  217.         itemlist.append(
  218.             Item(channel=__channel__,
  219.                  action="HomePage",
  220.                  title="[COLOR yellow]Torna Home[/COLOR]",
  221.                  folder=True)),
  222.         itemlist.append(
  223.             Item(channel=__channel__,
  224.                  action="peliculas_tv",
  225.                  extra=item.extra,
  226.                  title="[COLOR orange]Successivo >> [/COLOR]",
  227.                  url=pagina_siguiente,
  228.                  thumbnail="http://2.bp.blogspot.com/-fE9tzwmjaeQ/UcM2apxDtjI/AAAAAAAAeeg/WKSGM2TADLM/s1600/pager+old.png",
  229.                  folder=True))
  230.     except:
  231.         pass
  232.  
  233.     return itemlist
  234.  
  235. def pel_tv(item):
  236.     logger.info("[italiafilm.py] pel_tv")
  237.     itemlist = []
  238.  
  239.     data = scrapertools.cache_page(item.url)
  240.     patron = '<li class="cat_7(.*?)</li>'
  241.     matches = re.compile(patron, re.DOTALL).findall(data)
  242.  
  243.     for match in matches:
  244.         title = scrapertools.find_single_match(match, '<span class="tvseries_name">(.*?)</span>')
  245.         t = scrapertools.find_single_match(match, '</i>(.*?)</a>')
  246.         t = scrapertools.decodeHtmlentities(t).strip()
  247.         title = title.replace("Streaming", "")
  248.         title = scrapertools.decodeHtmlentities(title).strip()
  249.         title = title + " - " + t
  250.         url = scrapertools.find_single_match(match, '<a href="([^"]+)"')
  251.         plot = ""
  252.         thumbnail = scrapertools.find_single_match(match, 'data-echo="([^"]+)"')
  253.  
  254.         if (DEBUG): logger.info("title=[" + title + "], url=[" + url + "], thumbnail=[" + thumbnail + "]")
  255.  
  256.         itemlist.append(infoSod(
  257.             Item(channel=__channel__,
  258.                  action='episodios' if item.extra == 'serie' else 'findvideos',
  259.                  fulltitle=title,
  260.                  show=title,
  261.                  title="[COLOR azure]" + title + "[/COLOR]",
  262.                  url=url,
  263.                  thumbnail=thumbnail,
  264.                  plot=plot,
  265.                  viewmode="movie_with_plot",
  266.                  folder=True), tipo='tv'))
  267.  
  268.     # Siguiente
  269.     try:
  270.         pagina_siguiente = scrapertools.get_match(data, '<a class="next page-numbers" href="([^"]+)"')
  271.         itemlist.append(
  272.             Item(channel=__channel__,
  273.                  action="HomePage",
  274.                  title="[COLOR yellow]Torna Home[/COLOR]",
  275.                  folder=True)),
  276.         itemlist.append(
  277.             Item(channel=__channel__,
  278.                  action="pel_tv",
  279.                  extra=item.extra,
  280.                  title="[COLOR orange]Successivo >> [/COLOR]",
  281.                  url=pagina_siguiente,
  282.                  thumbnail="http://2.bp.blogspot.com/-fE9tzwmjaeQ/UcM2apxDtjI/AAAAAAAAeeg/WKSGM2TADLM/s1600/pager+old.png",
  283.                  folder=True))
  284.     except:
  285.         pass
  286.  
  287.     return itemlist
  288.  
  289. def anime(item):
  290.     logger.info("[italiafilm.py] anime")
  291.     itemlist = []
  292.  
  293.     data = scrapertools.cache_page(item.url)
  294.     patron = '<li class="cat_19(.*?)</li>'
  295.     matches = re.compile(patron, re.DOTALL).findall(data)
  296.  
  297.     for match in matches:
  298.         title = scrapertools.find_single_match(match, '<span class="tvseries_name">(.*?)</span>')
  299.         t = scrapertools.find_single_match(match, '</i>(.*?)</a>')
  300.         t = scrapertools.decodeHtmlentities(t).strip()
  301.         title = title.replace("Streaming", "")
  302.         title = scrapertools.decodeHtmlentities(title).strip()
  303.         title = title + " - " + t
  304.         url = scrapertools.find_single_match(match, '<a href="([^"]+)"')
  305.         plot = ""
  306.         thumbnail = scrapertools.find_single_match(match, 'data-echo="([^"]+)"')
  307.  
  308.         if (DEBUG): logger.info("title=[" + title + "], url=[" + url + "], thumbnail=[" + thumbnail + "]")
  309.  
  310.         itemlist.append(infoSod(
  311.             Item(channel=__channel__,
  312.                  action='episodios' if item.extra == 'serie' else 'findvideos',
  313.                  fulltitle=title,
  314.                  show=title,
  315.                  title="[COLOR azure]" + title + "[/COLOR]",
  316.                  url=url,
  317.                  thumbnail=thumbnail,
  318.                  plot=plot,
  319.                  viewmode="movie_with_plot",
  320.                  folder=True), tipo='tv'))
  321.  
  322.     # Siguiente
  323.     try:
  324.         pagina_siguiente = scrapertools.get_match(data, '<a class="next page-numbers" href="([^"]+)"')
  325.         itemlist.append(
  326.             Item(channel=__channel__,
  327.                  action="HomePage",
  328.                  title="[COLOR yellow]Torna Home[/COLOR]",
  329.                  folder=True)),
  330.         itemlist.append(
  331.             Item(channel=__channel__,
  332.                  action="anime",
  333.                  extra=item.extra,
  334.                  title="[COLOR orange]Successivo >> [/COLOR]",
  335.                  url=pagina_siguiente,
  336.                  thumbnail="http://2.bp.blogspot.com/-fE9tzwmjaeQ/UcM2apxDtjI/AAAAAAAAeeg/WKSGM2TADLM/s1600/pager+old.png",
  337.                  folder=True))
  338.     except:
  339.         pass
  340.  
  341.     return itemlist
  342.  
  343. def HomePage(item):
  344.     import xbmc
  345.     xbmc.executebuiltin("ReplaceWindow(10024,plugin://plugin.video.streamondemand)")
  346.  
  347.  
  348. def episodios(item):
  349.     def load_episodios(html, item, itemlist, lang_title):
  350.         for data in scrapertools.decodeHtmlentities(html).splitlines():
  351.             # Extrae las entradas
  352.             end = data.find('<a ')
  353.             if end > 0:
  354.                 scrapedtitle = re.sub(r'<[^>]*>', '', data[:end]).strip()
  355.             else:
  356.                 scrapedtitle = ''
  357.             if scrapedtitle == '':
  358.                 patron = '<a\s*href="[^"]+"\s*target="_blank">([^<]+)</a>'
  359.                 scrapedtitle = scrapertools.find_single_match(data, patron).strip()
  360.             title = scrapertools.find_single_match(scrapedtitle, '\d+[^\d]+\d+')
  361.             if title == '':
  362.                 title = scrapedtitle
  363.             if title != '':
  364.                 itemlist.append(
  365.                     Item(channel=__channel__,
  366.                          action="findvid_serie",
  367.                          title=title + " (" + lang_title + ")",
  368.                          url=item.url,
  369.                          thumbnail=item.thumbnail,
  370.                          extra=data,
  371.                          fulltitle=item.fulltitle,
  372.                          show=item.show))
  373.  
  374.     logger.info("[italiafilm.py] episodios")
  375.  
  376.     itemlist = []
  377.  
  378.     # Descarga la pagina
  379.     data = scrapertools.cache_page(item.url)
  380.  
  381.     start = data.find('id="pd_rating_holder')
  382.     end = data.find('id="linkcorrotto-show"', start)
  383.  
  384.     data = data[start:end]
  385.  
  386.     lang_titles = []
  387.     starts = []
  388.     patron = r"STAGION[I|E](.*?ITA)?"
  389.     matches = re.compile(patron, re.IGNORECASE).finditer(data)
  390.     for match in matches:
  391.         season_title = match.group()
  392.         # if season_title != '':
  393.         lang_titles.append('SUB ITA' if 'SUB' in season_title.upper() else 'ITA')
  394.         starts.append(match.end())
  395.  
  396.     i = 1
  397.     len_lang_titles = len(lang_titles)
  398.  
  399.     while i <= len_lang_titles:
  400.         inizio = starts[i - 1]
  401.         fine = starts[i] if i < len_lang_titles else -1
  402.  
  403.         html = data[inizio:fine]
  404.         lang_title = lang_titles[i - 1]
  405.  
  406.         load_episodios(html, item, itemlist, lang_title)
  407.  
  408.         i += 1
  409.  
  410.     if len(itemlist) == 0:
  411.         load_episodios(data, item, itemlist, 'ITA')
  412.  
  413.     if config.get_library_support() and len(itemlist) != 0:
  414.         itemlist.append(
  415.             Item(channel=__channel__,
  416.                  title=item.title,
  417.                  url=item.url,
  418.                  action="add_serie_to_library",
  419.                  extra="episodios",
  420.                  show=item.show))
  421.         itemlist.append(
  422.             Item(channel=item.channel,
  423.                  title="Scarica tutti gli episodi della serie",
  424.                  url=item.url,
  425.                  action="download_all_episodes",
  426.                  extra="episodios",
  427.                  show=item.show))
  428.  
  429.     return itemlist
  430.  
  431.  
  432. def findvideos(item):
  433.     logger.info("[italiafilm.py] findvideos")
  434.  
  435.     # Descarga la pagina
  436.     data = scrapertools.cache_page(item.url)
  437.  
  438.     itemlist = servertools.find_video_items(data=data)
  439.  
  440.     patron = '<iframe style="border: 0;" src="([^"]+)" width="[^"]*" height="[^"]*" scrolling="[^"]*" allowfullscreen="[^"]*"></iframe>'
  441.     url = scrapertools.find_single_match(data, patron)
  442.     if url:
  443.         headers.append(['Referer', item.url])
  444.         data = scrapertools.cache_page(url, headers=headers)
  445.         html = []
  446.         for num in scrapertools.find_multiple_matches(data, 'id="mlink_(\d+)"'):
  447.             html.append(scrapertools.cache_page(url + '?host=%s' % num, headers=headers))
  448.  
  449.         itemlist.extend(servertools.find_video_items(data=''.join(html)))
  450.  
  451.     for videoitem in itemlist:
  452.         videoitem.title = item.title + videoitem.title
  453.         videoitem.fulltitle = item.fulltitle
  454.         videoitem.thumbnail = item.thumbnail
  455.         videoitem.show = item.show
  456.         videoitem.plot = item.plot
  457.         videoitem.channel = __channel__
  458.  
  459.     return itemlist
  460.  
  461.  
  462. def findvid_serie(item):
  463.     logger.info("[italiafilm.py] findvideos")
  464.  
  465.     # Descarga la pagina
  466.     data = item.extra
  467.  
  468.     html = [data]
  469.  
  470.     headers.append(['Referer', item.url])
  471.     for url in scrapertools.find_multiple_matches(data, r'href="(http://hdlink\.[^?]+?)\?'):
  472.         for num in scrapertools.find_multiple_matches(scrapertools.cache_page(url, headers=headers), 'id="mlink_(\d+)"'):
  473.             html.append(scrapertools.cache_page(url + '?host=%s' % num, headers=headers))
  474.  
  475.     itemlist = servertools.find_video_items(data=''.join(html))
  476.     for videoitem in itemlist:
  477.         videoitem.title = item.title + videoitem.title
  478.         videoitem.fulltitle = item.fulltitle
  479.         videoitem.thumbnail = item.thumbnail
  480.         videoitem.show = item.show
  481.         videoitem.plot = item.plot
  482.         videoitem.channel = __channel__
  483.  
  484.     return itemlist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement