costaplus

ScambioFile_Transmission_new

May 8th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.31 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #------------------------------------------------------------
  3. # streamondemand.- XBMC Plugin
  4. # Canale Video Corsi Programmazione
  5. # by costaplus
  6. # http://www.mimediacenter.info/foro/viewforum.php?f=36.
  7. #------------------------------------------------------------
  8. import os
  9. import re
  10. import urllib2
  11. import urlparse
  12. import xbmc
  13. import xbmcgui
  14. from core import config
  15. from core import logger
  16. from core import scrapertools
  17. from core.item import Item
  18. from lib import transmissionrpc
  19.  
  20. __channel__ = "scambiofile3"
  21. __category__ = "D"
  22. __type__ = "generic"
  23. __title__ = "scambiofile (IT)"
  24. __language__ = "IT"
  25.  
  26. DEBUG = config.get_setting("debug")
  27.  
  28. site = "http://www.scambiofile.info"
  29.  
  30. local_folder = os.path.join(config.get_runtime_path(), "torrent")
  31.  
  32. ###############################################
  33. # Impostazioni personali attuali
  34. ###############################################
  35. Tran_host = "192.168.1.10"
  36. Tran_port = 9091
  37. #==============================================
  38. try:
  39.     Tran = transmissionrpc.Client(Tran_host,port=Tran_port,timeout=5)
  40.     Tran_stato = True
  41. except:
  42.     Tran_stato = False
  43. #==============================================
  44.  
  45.  
  46. def isGeneric():
  47.     return True
  48.  
  49. def mainlist(item):
  50.     logger.info("streamondemand.scambiofile mainlist")
  51.     itemlist = []
  52.  
  53.  
  54.     itemlist.append(Item(channel=__channel__, title="[COLOR azure]Genere[/COLOR]", action="genere",url="",thumbnail="http://xbmc-repo-ackbarr.googlecode.com/svn/trunk/dev/skin.cirrus%20extended%20v2/extras/moviegenres/All%20Movies%20by%20Genre.png"))
  55.     itemlist.append(Item(channel=__channel__, title="[COLOR azure]Formato[/COLOR]", action="formato", url="",thumbnail="http://i2.wp.com/incautoacquisto.com/wp-content/uploads/2009/03/incautovideo-460x325.jpg?resize=460%2C325"))
  56.     itemlist.append(Item(channel=__channel__, title="[COLOR azure]Film[/COLOR]", action="elenco",url=site+"/browse.php?cat=1",thumbnail="http://orig03.deviantart.net/6889/f/2014/079/7/b/movies_and_popcorn_folder_icon_by_matheusgrilo-d7ay4tw.png"))
  57.     itemlist.append(Item(channel=__channel__, title="[COLOR azure]Animazione[/COLOR]", action="elenco",url=site+"/browse.php?cat=13",thumbnail="http://orig03.deviantart.net/6889/f/2014/079/7/b/movies_and_popcorn_folder_icon_by_matheusgrilo-d7ay4tw.png"))
  58.     itemlist.append(Item(channel=__channel__, title="[COLOR azure]Serie TV[/COLOR]", action="elenco",url=site+"/browse.php?cat=14",thumbnail="http://orig03.deviantart.net/6889/f/2014/079/7/b/movies_and_popcorn_folder_icon_by_matheusgrilo-d7ay4tw.png"))
  59.     itemlist.append(Item(channel=__channel__, title="[COLOR yellow]Cerca...[/COLOR]", action="search",url=site+"/browse.php?search=",thumbnail="http://dc467.4shared.com/img/fEbJqOum/s7/13feaf0c8c0/Search"))
  60.     itemlist.append(Item(channel=__channel__, title="[COLOR orange]Elenco Torrent attivi n: %s[/COLOR]" % conta(), action="elenca_torrent",url="",thumbnail="https://raymii.org/s/inc/img/transmission.png"))
  61.  
  62.     return itemlist
  63.  
  64. def genere(item):
  65.     logger.info("streamondemand.scambiofile genere")
  66.     itemlist = []
  67.  
  68.     generi = ['azione','avventura','biografico','commedia','drammatico','erotico','fantascienza','horror','guerra','thriller','sentimentale']
  69.     for titolo in generi:
  70.         itemlist.append(Item(channel=__channel__, title="[COLOR azure]"+ titolo + "[/COLOR]", action="elenco", url=site+"/browse.php?tag="+titolo,thumbnail=item.thumbnail))
  71.  
  72.     return itemlist
  73.  
  74. def genere(item):
  75.     logger.info("streamondemand.scambiofile genere")
  76.     itemlist = []
  77.  
  78.     generi = ['azione','avventura','biografico','commedia','drammatico','erotico','fantascienza','horror','guerra','thriller','sentimentale']
  79.     for titolo in generi:
  80.         itemlist.append(Item(channel=__channel__, title="[COLOR azure]"+ titolo + "[/COLOR]", action="elenco", url=site+"/browse.php?tag="+titolo,thumbnail=item.thumbnail))
  81.     return itemlist
  82.  
  83.  
  84. def genere(item):
  85.     logger.info("streamondemand.scambiofile genere")
  86.     itemlist = []
  87.  
  88.     generi = ['azione','avventura','biografico','commedia','drammatico','erotico','fantascienza','horror','guerra','thriller','sentimentale']
  89.     for titolo in generi:
  90.         itemlist.append(Item(channel=__channel__, title="[COLOR azure]"+ titolo + "[/COLOR]", action="elenco", url=site+"/browse.php?tag="+titolo,thumbnail=item.thumbnail))
  91.     return itemlist
  92.  
  93. def formato(item):
  94.     logger.info("streamondemand.scambiofile genere")
  95.     itemlist = []
  96.     formati = ['720p', '1080p', 'm1080p', 'XviD', 'x264', 'x265', 'Subs', '3D']
  97.     for titolo in formati:
  98.         itemlist.append(Item(channel=__channel__, title="[COLOR azure]" + titolo + "[/COLOR]", action="elenco",url=site + "/browse.php?search=" + titolo,thumbnail=item.thumbnail))
  99.     return itemlist
  100.  
  101. def search(item,text):
  102.     logger.info("streamondemand.scambiofile cerca")
  103.     itemlist = []
  104.     item.url= "%s/browse.php?search=%s" % (site,text)
  105.     return elenco(item)
  106.  
  107. def elenco(item):
  108.     logger.info("streamondemand.scambiofile elenco")
  109.     itemlist = []
  110.     #xbmc.executebuiltin("Container.SetViewMode(500)")
  111.     data = scrapertools.cache_page(item.url)
  112.     patron = '<tr class=\'browse\'>.*?<img src=([^ ]+)[^;]+;.*?href=\'(.*?)\'[^>]+>(.*?)</a>'
  113.     matches = re.compile(patron, re.DOTALL).findall(data)
  114.     scrapertools.printMatches(matches)
  115.     #xbmc.log(data)
  116.     for scrapedthumbnail, scrapedurl, scrapedtitle in matches:
  117.         scrapedtitle = scrapertools.decodeHtmlentities(scrapedtitle)
  118.         title = scrapedtitle.split("(")[0]
  119.        
  120.         try:
  121.             plot, fanart, poster, extrameta = info(title)
  122.             itemlist.append( Item(channel=__channel__,action="dettaglio",fulltitle=scrapedtitle,show=scrapedtitle, title=scrapedtitle, url=site + scrapedurl,  thumbnail=scrapedthumbnail,plot=str(plot), extrameta=extrameta, fanart=fanart if fanart != "" else poster,folder=True))
  123.         except:
  124.             itemlist.append(Item(channel=__channel__, action="dettaglio", fulltitle=scrapedtitle, show=scrapedtitle,title=scrapedtitle,url=site + scrapedurl, thumbnail=scrapedthumbnail, plot="", folder=True))
  125.  
  126.     #Paginazione
  127.     patron = '<td class="highlight">.*?href="(.*?)"'
  128.     matches = re.compile(patron, re.DOTALL).findall(data)
  129.     scrapertools.printMatches(matches)
  130.     xbmc.log("qui %s" % matches)
  131.     if len(matches) > 0:
  132.         paginaurl = urlparse.urljoin(site, matches[0])
  133.         paginaurl = paginaurl.replace("amp;", "")
  134.         itemlist.append(Item(channel=__channel__, action="HomePage", title="[COLOR yellow]Torna Home[/COLOR]",folder=True))
  135.         itemlist.append(Item(channel=__channel__, action="elenco", title="[COLOR orange]Successivo>>[/COLOR]", url=paginaurl, thumbnail="http://2.bp.blogspot.com/-fE9tzwmjaeQ/UcM2apxDtjI/AAAAAAAAeeg/WKSGM2TADLM/s1600/pager+old.png",folder=True))
  136.     return itemlist
  137.  
  138. def dettaglio(item):
  139.     logger.info("streamondemand.scambiofile dettaglio")
  140.     itemlist = []
  141.     data = scrapertools.cache_page(item.url)
  142.  
  143.     patron = '<a class=\'.*?\' href="(.*?)" title=\'Torcache.net\'>.*?href="([^>]+)">'
  144.     matches = re.compile(patron, re.DOTALL).findall(data)
  145.     scrapertools.printMatches(matches)
  146.  
  147.     for scrapedTorrent, scrapedMagnet in matches:
  148.         xbmc.log("torrent:%s    magnet:%s" % (site + scrapedTorrent, scrapedMagnet))
  149.         itemlist.append(Item(channel=__channel__, action="scarica",server="torrent", title="[COLOR yellow] .torrent [/COLOR]"  + item.title, url=site+scrapedTorrent, thumbnail=item.thumbnail,plot=item.plot,extrameta=item.extrameta,fanart=item.fanart if item.fanart != "" else item.poster, folder=True))
  150.         itemlist.append(Item(channel=__channel__, action="add_transmission",server="torrent", title="[COLOR orange] .magnet [/COLOR]"+item.title, url=scrapedMagnet,thumbnail=item.thumbnail, plot=item.plot,extrameta=item.extrameta,fanart=item.fanart if item.fanart != "" else item.poster, folder=True))
  151.  
  152.     return itemlist
  153.  
  154.  
  155.  
  156. def add_transmission(item):
  157.     logger.info("streamondemand.scambiofile add_transmission")
  158.     itemlist = []
  159.  
  160.     if Tran_stato:
  161.         risposta = xbmcgui.Dialog().yesno("Aggiungi Torrent a trasmission", "Vuoi aggiungerlo a transmission ?")
  162.         xbmc.log("risposta %s" % risposta)
  163.         if risposta==1:
  164.             Tran.add_torrent(item.url)
  165.     if not Tran_stato:
  166.         xbmcgui.Dialog().ok("trasmission", "Attenzione transmission non è contattabile! \n controllare la connesso.")
  167.  
  168.     return itemlist
  169.  
  170. def scarica(item):
  171.     logger.info("streamondemand.scambiofile add_transmission")
  172.     itemlist = []
  173.  
  174.     if Tran_stato:
  175.         with open(os.path.join(local_folder, "new.torrent"), "wb") as f:
  176.             f.write(urllib2.urlopen(item.url).read())
  177.         risposta = xbmcgui.Dialog().yesno("Aggiungi Torrent a trasmission", "Vuoi aggiungerlo il torrent scaricato a transmission ?")
  178.         #xbmc.log("risposta %s" % risposta)
  179.         #if risposta == 1: Tran.add_torrent(f)
  180.     return itemlist
  181.  
  182. '''
  183. def elenca_torrent(item):
  184.    logger.info("streamondemand.scambiofile elenca_torrent")
  185.    itemlist = []
  186.  
  187.    if Tran_stato:
  188.        for elenca in Tran.get_torrents():
  189.            titolo = "[COLOR azure]%s[/COLOR]" % elenca
  190.            itemlist.append(Item(channel=__channel__, action="", title=titolo, url="", thumbnail=item.thumbnail, plot="", folder=False))
  191.    else:
  192.        itemlist.append(Item(channel=__channel__, action="mainlist", title="Il servizio non è attivo", url="", thumbnail="", plot="", folder=False))
  193.  
  194.    return itemlist(item)
  195. '''
  196.  
  197. def conta():
  198.     if Tran_stato:
  199.         count= len(Tran.get_torrents())
  200.     else:
  201.         count="- Servizio non attivo -"
  202.        
  203.        
  204.     return count
  205.  
  206. def HomePage(item):
  207.  
  208.     xbmc.executebuiltin("ReplaceWindow(10024,plugin://plugin.video.streamondemand)")
  209.  
  210.  
  211.  
  212. def info(title):
  213.     logger.info("streamondemand.tntvillate info")
  214.     try:
  215.         from core.tmdb import Tmdb
  216.         oTmdb = Tmdb(texto_buscado=title, tipo="movie", include_adult="false", idioma_busqueda="it")
  217.         if oTmdb.total_results > 0:
  218.             extrameta = {"Year": oTmdb.result["release_date"][:4],
  219.                          "Genre": ", ".join(oTmdb.result["genres"]),
  220.                          "Rating": float(oTmdb.result["vote_average"])}
  221.             fanart = oTmdb.get_backdrop()
  222.             poster = oTmdb.get_poster()
  223.             plot = oTmdb.get_sinopsis()
  224.             return plot, fanart, poster, extrameta
  225.     except:
  226.         pass
Advertisement
Add Comment
Please, Sign In to add comment