def play_torrent(self,item): import time import os played = False #Importamos el cliente from btserver import Client #Iniciamos el cliente: c = Client(url=item.url, is_playing_fnc=self.is_playing ,wait_time=None, timeout=5, temp_path =os.path.join(config.get_data_path(),"torrent") ) #Mostramos el progreso progreso = self.dialog_progress( "Pelisalacarta - Torrent" , "Iniciando...") #Mientras el progreso no sea cancelado ni el cliente cerrado while not progreso.iscanceled() and not c.closed: try: #Obtenemos el estado del torrent s = c.status #Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers,s.dht_peers, s.pex_peers, s.lsd_peers) progreso.update(s.buffer,txt, txt2, txt3) time.sleep(1) #Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: #Cerramos el progreso progreso.close() #Obtenemos el playlist del torrent item.video_url = c.get_play_list() item.server = "directo" self.play_video(item) #Marcamos como reproducido para que no se vuelva a iniciar played = True #Y esperamos a que el reproductor se cierre while self.is_playing(): time.sleep(1) #Cuando este cerrado, Volvemos a mostrar el dialogo progreso = self.dialog_progress( "Pelisalacarta - Torrent" , "Iniciando...") except: import traceback logger.info(traceback.format_exc()) break progreso.update(100,"Terminando y eliminando datos"," "," ") #Detenemos el cliente if not c.closed: c.stop() #Y cerramos el progreso progreso.close() return
def play_video(item,desdefavoritos=False,desdedescargados=False,desderrordescargas=False,strmfile=False): from core import servertools logger.info("pelisalacarta.platformcode.xbmctools play_video") #logger.info(item.tostring('\n')) try: item.server = item.server.lower() except: item.server = "" if item.server=="": item.server="directo" view = False # Abre el diálogo de selección opciones = [] default_action = config.get_setting("default_action") logger.info("default_action="+default_action) # Si no es el modo normal, no muestra el diálogo porque cuelga XBMC muestra_dialogo = (config.get_setting("player_mode")=="0" and not strmfile) # Extrae las URL de los vídeos, y si no puedes verlo te dice el motivo video_urls,puedes,motivo = servertools.resolve_video_urls_for_playing(item.server,item.url,item.password,muestra_dialogo) # Si puedes ver el vídeo, presenta las opciones if puedes: for video_url in video_urls: opciones.append(config.get_localized_string(30151) + " " + video_url[0]) if item.server=="local": opciones.append(config.get_localized_string(30164)) else: opcion = config.get_localized_string(30153) opciones.append(opcion) # "Descargar" if item.channel=="favoritos": opciones.append(config.get_localized_string(30154)) # "Quitar de favoritos" else: opciones.append(config.get_localized_string(30155)) # "Añadir a favoritos" if not strmfile: opciones.append(config.get_localized_string(30161)) # "Añadir a Biblioteca" if item.channel!="descargas": opciones.append(config.get_localized_string(30157)) # "Añadir a lista de descargas" else: if item.category=="errores": opciones.append(config.get_localized_string(30159)) # "Borrar descarga definitivamente" opciones.append(config.get_localized_string(30160)) # "Pasar de nuevo a lista de descargas" else: opciones.append(config.get_localized_string(30156)) # "Quitar de lista de descargas" if config.get_setting("jdownloader_enabled")=="true": opciones.append(config.get_localized_string(30158)) # "Enviar a JDownloader" if config.get_setting("pyload_enabled")=="true": opciones.append(config.get_localized_string(30158).replace("jDownloader","pyLoad")) # "Enviar a pyLoad" if default_action=="3": seleccion = len(opciones)-1 # Busqueda de trailers en youtube if not item.channel in ["Trailer","ecarteleratrailers"]: opciones.append(config.get_localized_string(30162)) # "Buscar Trailer" # Si no puedes ver el vídeo te informa else: if item.server!="": advertencia = xbmcgui.Dialog() if "<br/>" in motivo: resultado = advertencia.ok( "No puedes ver ese vídeo porque...",motivo.split("<br/>")[0],motivo.split("<br/>")[1],item.url) else: resultado = advertencia.ok( "No puedes ver ese vídeo porque...",motivo,item.url) else: resultado = advertencia.ok( "No puedes ver ese vídeo porque...","El servidor donde está alojado no está","soportado en pelisalacarta todavía",item.url) if item.channel=="favoritos": opciones.append(config.get_localized_string(30154)) # "Quitar de favoritos" if item.channel=="descargas": if item.category=="errores": opciones.append(config.get_localized_string(30159)) # "Borrar descarga definitivamente" else: opciones.append(config.get_localized_string(30156)) # "Quitar de lista de descargas" if len(opciones)==0: return # Si la accion por defecto es "Preguntar", pregunta if default_action=="0": # and server!="torrent": dia = xbmcgui.Dialog() seleccion = dia.select(config.get_localized_string(30163), opciones) # "Elige una opción" #dia.close() ''' elif default_action=="0" and server=="torrent": advertencia = xbmcgui.Dialog() logger.info("video_urls[0]="+str(video_urls[0][1])) if puedes and ('"status":"COMPLETED"' in video_urls[0][1] or '"percent_done":100' in video_urls[0][1]): listo = "y está listo para ver" else: listo = "y se está descargando" resultado = advertencia.ok( "Torrent" , "El torrent ha sido añadido a la lista" , listo ) seleccion=-1 ''' elif default_action=="1": seleccion = 0 elif default_action=="2": seleccion = len(video_urls)-1 elif default_action=="3": seleccion = seleccion else: seleccion=0 logger.info("seleccion=%d" % seleccion) logger.info("seleccion=%s" % opciones[seleccion]) # No ha elegido nada, lo más probable porque haya dado al ESC if seleccion==-1: #Para evitar el error "Uno o más elementos fallaron" al cancelar la selección desde fichero strm listitem = xbmcgui.ListItem( item.title, iconImage="DefaultVideo.png", thumbnailImage=item.thumbnail) xbmcplugin.setResolvedUrl(int(sys.argv[ 1 ]),False,listitem) # JUR Added #if config.get_setting("subtitulo") == "true": # config.set_setting("subtitulo", "false") return if opciones[seleccion]==config.get_localized_string(30158): # "Enviar a JDownloader" #d = {"web": url}urllib.urlencode(d) from core import scrapertools if item.subtitle!="": data = scrapertools.cachePage(config.get_setting("jdownloader")+"/action/add/links/grabber0/start1/web="+item.url+ " " +item.thumbnail + " " + item.subtitle) else: data = scrapertools.cachePage(config.get_setting("jdownloader")+"/action/add/links/grabber0/start1/web="+item.url+ " " +item.thumbnail) return if opciones[seleccion]==config.get_localized_string(30158).replace("jDownloader","pyLoad"): # "Enviar a pyLoad" logger.info("Enviando a pyload...") if item.show!="": package_name = item.show else: package_name = "pelisalacarta" from core import pyload_client pyload_client.download(url=item.url,package_name=package_name) return elif opciones[seleccion]==config.get_localized_string(30164): # Borrar archivo en descargas # En "extra" está el nombre del fichero en favoritos os.remove( item.url ) xbmc.executebuiltin( "Container.Refresh" ) return # Ha elegido uno de los vídeos elif seleccion < len(video_urls): mediaurl = video_urls[seleccion][1] if len(video_urls[seleccion])>3: wait_time = video_urls[seleccion][2] item.subtitle = video_urls[seleccion][3] elif len(video_urls[seleccion])>2: wait_time = video_urls[seleccion][2] else: wait_time = 0 view = True # Descargar elif opciones[seleccion]==config.get_localized_string(30153): # "Descargar" download_title = item.fulltitle if item.hasContentDetails=="true": download_title = item.contentTitle # El vídeo de más calidad es el último mediaurl = video_urls[len(video_urls)-1][1] from core import downloadtools keyboard = xbmc.Keyboard(download_title) keyboard.doModal() if (keyboard.isConfirmed()): download_title = keyboard.getText() devuelve = downloadtools.downloadbest(video_urls,download_title) if devuelve==0: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("plugin" , "Descargado con éxito") elif devuelve==-1: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("plugin" , "Descarga abortada") else: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("plugin" , "Error en la descarga") return elif opciones[seleccion]==config.get_localized_string(30154): #"Quitar de favoritos" from channels import favoritos # En "extra" está el nombre del fichero en favoritos favoritos.deletebookmark(urllib.unquote_plus( item.extra )) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30102) , item.title , config.get_localized_string(30105)) # 'Se ha quitado de favoritos' xbmc.executebuiltin( "Container.Refresh" ) return elif opciones[seleccion]==config.get_localized_string(30159): #"Borrar descarga definitivamente" descargas.delete_error_bookmark(urllib.unquote_plus( item.extra )) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30101) , item.title , config.get_localized_string(30106)) # 'Se ha quitado de la lista' xbmc.executebuiltin( "Container.Refresh" ) return elif opciones[seleccion]==config.get_localized_string(30160): #"Pasar de nuevo a lista de descargas": descargas.mover_descarga_error_a_pendiente(urllib.unquote_plus( item.extra )) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30101) , item.title , config.get_localized_string(30107)) # 'Ha pasado de nuevo a la lista de descargas' return elif opciones[seleccion]==config.get_localized_string(30155): #"Añadir a favoritos": from channels import favoritos from core import downloadtools download_title = item.fulltitle download_thumbnail = item.thumbnail download_plot = item.plot if item.hasContentDetails=="true": download_title = item.contentTitle download_thumbnail = item.contentThumbnail download_plot = item.contentPlot keyboard = xbmc.Keyboard(downloadtools.limpia_nombre_excepto_1(download_title)+" ["+item.channel+"]") keyboard.doModal() if keyboard.isConfirmed(): title = keyboard.getText() favoritos.savebookmark(titulo=download_title,url=item.url,thumbnail=download_thumbnail,server=item.server,plot=download_plot,fulltitle=item.title) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30102) , item.title , config.get_localized_string(30108)) # 'se ha añadido a favoritos' return elif opciones[seleccion]==config.get_localized_string(30156): #"Quitar de lista de descargas": # La categoría es el nombre del fichero en la lista de descargas descargas.deletebookmark((urllib.unquote_plus( item.extra ))) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30101) , item.title , config.get_localized_string(30106)) # 'Se ha quitado de lista de descargas' xbmc.executebuiltin( "Container.Refresh" ) return elif opciones[seleccion]==config.get_localized_string(30157): #"Añadir a lista de descargas": from core import downloadtools download_title = item.fulltitle download_thumbnail = item.thumbnail download_plot = item.plot if item.hasContentDetails=="true": download_title = item.contentTitle download_thumbnail = item.contentThumbnail download_plot = item.contentPlot keyboard = xbmc.Keyboard(downloadtools.limpia_nombre_excepto_1(download_title)) keyboard.doModal() if keyboard.isConfirmed(): download_title = keyboard.getText() descargas.savebookmark(titulo=download_title,url=item.url,thumbnail=download_thumbnail,server=item.server,plot=download_plot,fulltitle=download_title) advertencia = xbmcgui.Dialog() resultado = advertencia.ok(config.get_localized_string(30101) , download_title , config.get_localized_string(30109)) # 'se ha añadido a la lista de descargas' return elif opciones[seleccion] == config.get_localized_string(30161): # "Añadir a Biblioteca": # Library titulo = item.fulltitle if titulo == "": titulo = item.title #library.savelibrary(titulo,item.url,item.thumbnail,item.server,item.plot,canal=item.channel,category=item.category,Serie=item.show) # TODO ¿SOLO peliculas? #logger.debug(item.tostring('\n')) new_item = item.clone(title=titulo, action="play_from_library", category="Cine", fulltitle=item.fulltitle, channel=item.channel) #logger.debug(new_item.tostring('\n')) insertados, sobreescritos, fallidos = library.save_library_movie(new_item) advertencia = xbmcgui.Dialog() if fallidos == 0: advertencia.ok(config.get_localized_string(30131), titulo, config.get_localized_string(30135)) # 'se ha añadido a la biblioteca' return elif opciones[seleccion]==config.get_localized_string(30162): #"Buscar Trailer": config.set_setting("subtitulo", "false") xbmc.executebuiltin("XBMC.RunPlugin(%s?%s)" % ( sys.argv[ 0 ] , item.clone(channel="trailertools", action="buscartrailer", contextual=True).tourl())) return # Si no hay mediaurl es porque el vídeo no está :) logger.info("pelisalacarta.platformcode.xbmctools mediaurl="+mediaurl) if mediaurl=="": if server == "unknown": alertUnsopportedServer() else: alertnodisponibleserver(item.server) return # Si hay un tiempo de espera (como en megaupload), lo impone ahora if wait_time>0: continuar = handle_wait(wait_time,server,"Cargando vídeo...") if not continuar: return # Obtención datos de la Biblioteca (solo strms que estén en la biblioteca) if strmfile: xlistitem = getLibraryInfo(mediaurl) else: play_title = item.fulltitle play_thumbnail = item.thumbnail play_plot = item.plot if item.hasContentDetails=="true": play_title = item.contentTitle play_thumbnail = item.contentThumbnail play_plot = item.contentPlot try: xlistitem = xbmcgui.ListItem( play_title, iconImage="DefaultVideo.png", thumbnailImage=play_thumbnail, path=mediaurl) except: xlistitem = xbmcgui.ListItem( play_title, iconImage="DefaultVideo.png", thumbnailImage=play_thumbnail) xlistitem.setInfo( "video", { "Title": play_title, "Plot" : play_plot , "Studio" : item.channel , "Genre" : item.category } ) #set_infoLabels(listitem,plot) # Modificacion introducida por super_berny para añadir infoLabels al ListItem # Lanza el reproductor # Lanza el reproductor if strmfile and not item.from_biblioteca: #Si es un fichero strm no hace falta el play xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xlistitem) if item.subtitle != "": xbmc.sleep(2000) xbmc.Player().setSubtitles(item.subtitle) #Movido del conector "torrent" aqui elif item.server=="torrent": #Opciones disponibles para Reproducir torrents torrent_options = [] torrent_options.append(["Cliente interno (necesario libtorrent)"]) torrent_options.append(["Cliente interno MCT (necesario libtorrent)"]) #Plugins externos se pueden añadir otros if xbmc.getCondVisibility('System.HasAddon("plugin.video.xbmctorrent")'): torrent_options.append(["Plugin externo: xbmctorrent","plugin://plugin.video.xbmctorrent/play/%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.pulsar")'): torrent_options.append(["Plugin externo: pulsar","plugin://plugin.video.pulsar/play?uri=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.quasar")'): torrent_options.append(["Plugin externo: quasar","plugin://plugin.video.quasar/play?uri=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.stream")'): torrent_options.append(["Plugin externo: stream","plugin://plugin.video.stream/play/%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrenter")'): torrent_options.append(["Plugin externo: torrenter","plugin://plugin.video.torrenter/?action=playSTRM&url=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrentin")'): torrent_options.append(["Plugin externo: torrentin","plugin://plugin.video.torrentin/?uri=%s&image="]) if len(torrent_options)>1: seleccion = xbmcgui.Dialog().select("Abrir torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = 0 #Plugins externos if seleccion > 1: mediaurl = urllib.quote_plus(item.url) xbmc.executebuiltin( "PlayMedia(" + torrent_options[seleccion][1] % mediaurl +")" ) if seleccion ==1: from platformcode import mct mct.play( mediaurl, xbmcgui.ListItem("", iconImage=item.thumbnail, thumbnailImage=item.thumbnail), subtitle=item.subtitle ) #Reproductor propio (libtorrent) if seleccion == 0: import time videourl = None played = False #Importamos el cliente from btserver import Client #Iniciamos el cliente: c = Client(url=mediaurl, is_playing_fnc= xbmc.Player().isPlaying, wait_time=None, timeout=5, temp_path =os.path.join(config.get_data_path(),"torrent") ) #Mostramos el progreso progreso = xbmcgui.DialogProgress() progreso.create( "Pelisalacarta - Torrent" , "Iniciando...") #Mientras el progreso no sea cancelado ni el cliente cerrado while not progreso.iscanceled() and not c.closed: try: #Obtenemos el estado del torrent s = c.status #Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers,s.dht_peers, s.pex_peers, s.lsd_peers) progreso.update(s.buffer,txt, txt2, txt3) time.sleep(1) #Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: #Cerramos el progreso progreso.close() #Obtenemos el playlist del torrent videourl = c.get_play_list() #Iniciamos el reproductor playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO ) playlist.clear() playlist.add( videourl, xlistitem ) xbmcPlayer = xbmc.Player() xbmcPlayer.play(playlist) #Marcamos como reproducido para que no se vuelva a iniciar played = True #Y esperamos a que el reproductor se cierre while xbmc.Player().isPlaying(): time.sleep(1) #Cuando este cerrado, Volvemos a mostrar el dialogo progreso.create( "Pelisalacarta - Torrent" , "Iniciando...") except: import traceback logger.info(traceback.format_exc()) break progreso.update(100,"Terminando y eliminando datos"," "," ") #Detenemos el cliente if not c.closed: c.stop() #Y cerramos el progreso progreso.close() return else: logger.info("player_mode="+config.get_setting("player_mode")) logger.info("mediaurl="+mediaurl) if config.get_setting("player_mode")=="3" or "megacrypter.com" in mediaurl: import download_and_play download_and_play.download_and_play( mediaurl , "download_and_play.tmp" , config.get_setting("downloadpath") ) return elif config.get_setting("player_mode")=="0" or (config.get_setting("player_mode")=="3" and mediaurl.startswith("rtmp")): # Añadimos el listitem a una lista de reproducción (playlist) playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO ) playlist.clear() playlist.add( mediaurl, xlistitem ) # Reproduce playersettings = config.get_setting('player_type') logger.info("pelisalacarta.platformcode.xbmctools playersettings="+playersettings) if config.get_system_platform()=="xbox": player_type = xbmc.PLAYER_CORE_AUTO if playersettings == "0": player_type = xbmc.PLAYER_CORE_AUTO logger.info("pelisalacarta.platformcode.xbmctools PLAYER_CORE_AUTO") elif playersettings == "1": player_type = xbmc.PLAYER_CORE_MPLAYER logger.info("pelisalacarta.platformcode.xbmctools PLAYER_CORE_MPLAYER") elif playersettings == "2": player_type = xbmc.PLAYER_CORE_DVDPLAYER logger.info("pelisalacarta.platformcode.xbmctools PLAYER_CORE_DVDPLAYER") xbmcPlayer = xbmc.Player( player_type ) else: xbmcPlayer = xbmc.Player() xbmcPlayer.play(playlist) if item.channel=="cuevana" and item.subtitle!="": logger.info("subtitulo="+subtitle) if item.subtitle!="" and (opciones[seleccion].startswith("Ver") or opciones[seleccion].startswith("Watch")): logger.info("pelisalacarta.platformcode.xbmctools Con subtitulos") setSubtitles() elif config.get_setting("player_mode")=="1": logger.info("mediaurl :"+ mediaurl) logger.info("Tras setResolvedUrl") xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path=mediaurl)) elif config.get_setting("player_mode")=="2": xbmc.executebuiltin( "PlayMedia("+mediaurl+")" ) if item.subtitle!="" and view: logger.info("Subtítulos externos: "+item.subtitle) xbmc.Player().setSubtitles(item.subtitle)
def play_torrent(item, xlistitem, mediaurl): logger.info("platformtools play_torrent") # Opciones disponibles para Reproducir torrents torrent_options = list() torrent_options.append(["Cliente interno (necesario libtorrent)"]) torrent_options.append(["Cliente interno MCT (necesario libtorrent)"]) # Plugins externos se pueden añadir otros if xbmc.getCondVisibility('System.HasAddon("plugin.video.xbmctorrent")'): torrent_options.append(["Plugin externo: xbmctorrent", "plugin://plugin.video.xbmctorrent/play/%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.pulsar")'): torrent_options.append(["Plugin externo: pulsar", "plugin://plugin.video.pulsar/play?uri=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.quasar")'): torrent_options.append(["Plugin externo: quasar", "plugin://plugin.video.quasar/play?uri=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.stream")'): torrent_options.append(["Plugin externo: stream", "plugin://plugin.video.stream/play/%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrenter")'): torrent_options.append(["Plugin externo: torrenter", "plugin://plugin.video.torrenter/?action=playSTRM&url=%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrentin")'): torrent_options.append(["Plugin externo: torrentin", "plugin://plugin.video.torrentin/?uri=%s&image="]) if len(torrent_options) > 1: seleccion = dialog_select("Abrir torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = 0 # Plugins externos if seleccion > 1: mediaurl = urllib.quote_plus(item.url) xbmc.executebuiltin("PlayMedia(" + torrent_options[seleccion][1] % mediaurl + ")") if seleccion == 1: from platformcode import mct mct.play(mediaurl, xlistitem, subtitle=item.subtitle) # Reproductor propio (libtorrent) if seleccion == 0: import time played = False debug = (config.get_setting("debug") == "true") # Importamos el cliente from btserver import Client clientTmpPath = config.get_setting("downloadpath") if not clientTmpPath: clientTmpPath = config.get_data_path() # Iniciamos el cliente: c = Client(url=mediaurl, is_playing_fnc=xbmc.Player().isPlaying, wait_time=None, timeout=10, temp_path=os.path.join(clientTmpPath, "pelisalacarta-torrent"), print_status=debug) # Mostramos el progreso progreso = dialog_progress("Pelisalacarta - Torrent", "Iniciando...") # Mientras el progreso no sea cancelado ni el cliente cerrado while not c.closed: try: # Obtenemos el estado del torrent s = c.status if debug: # Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers, s.dht_peers, s.pex_peers, s.lsd_peers) else: txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d)' % (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete) try: txt3 = 'Deteniendo automaticamente en: %ss' % (int(s.timeout)) except: txt3 = '' progreso.update(s.buffer, txt, txt2, txt3) time.sleep(0.5) if progreso.iscanceled(): progreso.close() if s.buffer == 100: if dialog_yesno("Pelisalacarta - Torrent", "¿Deseas iniciar la reproduccion?"): played = False progreso = dialog_progress("Pelisalacarta - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) else: progreso = dialog_progress("Pelisalacarta - Torrent", "") break else: if dialog_yesno("Pelisalacarta - Torrent", "¿Deseas cancelar el proceso?"): progreso = dialog_progress("Pelisalacarta - Torrent", "") break else: progreso = dialog_progress("Pelisalacarta - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) # Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: # Cerramos el progreso progreso.close() # Obtenemos el playlist del torrent videourl = c.get_play_list() # Iniciamos el reproductor playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(videourl, xlistitem) xbmc_player = xbmc.Player() xbmc_player.play(playlist) # Marcamos como reproducido para que no se vuelva a iniciar played = True # Y esperamos a que el reproductor se cierre while xbmc.Player().isPlaying(): time.sleep(1) # Cuando este cerrado, Volvemos a mostrar el dialogo progreso = dialog_progress("Pelisalacarta - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) except: import traceback logger.info(traceback.format_exc()) break progreso.update(100, "Terminando y eliminando datos", " ", " ") # Detenemos el cliente if not c.closed: c.stop() # Y cerramos el progreso progreso.close()
def play_torrent(item, xlistitem, mediaurl): logger.info() # Opciones disponibles para Reproducir torrents torrent_options = list() torrent_options.append(["Cliente interno (necesario libtorrent)"]) torrent_options.append(["Cliente interno MCT (necesario libtorrent)"]) torrent_options.extend(torrent_client_installed(show_tuple=True)) torrent_client = config.get_setting("torrent_client", server="torrent") if torrent_client and torrent_client - 1 <= len(torrent_options): if torrent_client == 0: seleccion = dialog_select( "Abrir torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = torrent_client - 1 else: if len(torrent_options) > 1: seleccion = dialog_select( "Abrir torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = 0 # Plugins externos if seleccion > 1: mediaurl = urllib.quote_plus(item.url) xbmc.executebuiltin("PlayMedia(" + torrent_options[seleccion][1] % mediaurl + ")") if seleccion == 1: from platformcode import mct mct.play(mediaurl, xlistitem, subtitle=item.subtitle, item=item) # Reproductor propio (libtorrent) if seleccion == 0: import time played = False debug = (config.get_setting("debug") == True) # Importamos el cliente from btserver import Client client_tmp_path = config.get_setting("downloadpath") if not client_tmp_path: client_tmp_path = config.get_data_path() # Iniciamos el cliente: c = Client(url=mediaurl, is_playing_fnc=xbmc_player.isPlaying, wait_time=None, timeout=10, temp_path=os.path.join(client_tmp_path, "alfa-torrent"), print_status=debug) # Mostramos el progreso progreso = dialog_progress("Alfa - Torrent", "Iniciando...") # Mientras el progreso no sea cancelado ni el cliente cerrado while not c.closed: try: # Obtenemos el estado del torrent s = c.status if debug: # Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers, s.dht_peers, s.pex_peers, s.lsd_peers) else: txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d)' % ( s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete) try: txt3 = 'Deteniendo automaticamente en: %ss' % (int( s.timeout)) except: txt3 = '' progreso.update(s.buffer, txt, txt2, txt3) time.sleep(0.5) if progreso.iscanceled(): progreso.close() if s.buffer == 100: if dialog_yesno("Alfa - Torrent", "¿Deseas iniciar la reproduccion?"): played = False progreso = dialog_progress("Alfa - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) else: progreso = dialog_progress("Alfa - Torrent", "") break else: if dialog_yesno("Alfa - Torrent", "¿Deseas cancelar el proceso?"): progreso = dialog_progress("Alfa - Torrent", "") break else: progreso = dialog_progress("Alfa - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) # Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: # Cerramos el progreso progreso.close() # Obtenemos el playlist del torrent videourl = c.get_play_list() # Iniciamos el reproductor playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(videourl, xlistitem) # xbmc_player = xbmc_player xbmc_player.play(playlist) # Marcamos como reproducido para que no se vuelva a iniciar played = True # si es un archivo de la videoteca enviar a marcar como visto if item.strm_path: from platformcode import xbmc_videolibrary xbmc_videolibrary.mark_auto_as_watched(item) # Y esperamos a que el reproductor se cierre while xbmc_player.isPlaying(): time.sleep(1) # Cuando este cerrado, Volvemos a mostrar el dialogo progreso = dialog_progress("Alfa - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) except: import traceback logger.error(traceback.format_exc()) break progreso.update(100, "Terminando y eliminando datos", " ", " ") # Detenemos el cliente if not c.closed: c.stop() # Y cerramos el progreso progreso.close()
def play_torrent(self, item): import time import os played = False # Importamos el cliente from btserver import Client # Iniciamos el cliente: c = Client(url=item.url, is_playing_fnc=self.is_playing, wait_time=None, timeout=5, temp_path=os.path.join(config.get_data_path(), "torrent")) # Mostramos el progreso progreso = self.dialog_progress("Alfa - Torrent", "Iniciando...") # Mientras el progreso no sea cancelado ni el cliente cerrado while not progreso.iscanceled() and not c.closed: try: # Obtenemos el estado del torrent s = c.status # Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ ( s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers, s.dht_peers, s.pex_peers, s.lsd_peers) progreso.update(s.buffer, txt, txt2, txt3) time.sleep(1) # Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: # Cerramos el progreso progreso.close() # Obtenemos el playlist del torrent item.video_url = c.get_play_list() item.server = "directo" self.play_video(item) # Marcamos como reproducido para que no se vuelva a iniciar played = True # Y esperamos a que el reproductor se cierre while self.is_playing(): time.sleep(1) # Cuando este cerrado, Volvemos a mostrar el dialogo progreso = self.dialog_progress("Alfa - Torrent", "Iniciando...") except: import traceback logger.info(traceback.format_exc()) break progreso.update(100, "Terminando y eliminando datos", " ", " ") # Detenemos el cliente if not c.closed: c.stop() # Y cerramos el progreso progreso.close() return
def play_torrent(item, xlistitem, mediaurl): logger.info("platformtools play_torrent") # Opciones disponibles para Reproducir torrents torrent_options = list() torrent_options.append(["Cliente interno (necesario libtorrent)"]) torrent_options.append(["Cliente interno MCT (necesario libtorrent)"]) # Plugins externos se pueden añadir otros if xbmc.getCondVisibility('System.HasAddon("plugin.video.xbmctorrent")'): torrent_options.append([ "Plugin externo: xbmctorrent", "plugin://plugin.video.xbmctorrent/play/%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.pulsar")'): torrent_options.append([ "Plugin externo: pulsar", "plugin://plugin.video.pulsar/play?uri=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.quasar")'): torrent_options.append([ "Plugin externo: quasar", "plugin://plugin.video.quasar/play?uri=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.stream")'): torrent_options.append( ["Plugin externo: stream", "plugin://plugin.video.stream/play/%s"]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrenter")'): torrent_options.append([ "Plugin externo: torrenter", "plugin://plugin.video.torrenter/?action=playSTRM&url=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrentin")'): torrent_options.append([ "Plugin externo: torrentin", "plugin://plugin.video.torrentin/?uri=%s&image=" ]) if len(torrent_options) > 1: seleccion = dialog_select("Apri torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = 0 # Plugins externos if seleccion > 1: mediaurl = urllib.quote_plus(item.url) xbmc.executebuiltin("PlayMedia(" + torrent_options[seleccion][1] % mediaurl + ")") if seleccion == 1: from platformcode import mct mct.play(mediaurl, xlistitem, subtitle=item.subtitle) # Reproductor propio (libtorrent) if seleccion == 0: import time played = False debug = (config.get_setting("debug") == "true") # Importamos el cliente from btserver import Client # Iniciamos el cliente: c = Client(url=mediaurl, is_playing_fnc=xbmc.Player().isPlaying, wait_time=None, timeout=10, temp_path=os.path.join(config.get_data_path(), "torrent"), print_status=debug) # Mostramos el progreso progreso = dialog_progress("Streamondemand - Torrent", "Avvio...") # Mientras el progreso no sea cancelado ni el cliente cerrado while not c.closed: try: # Obtenemos el estado del torrent s = c.status if debug: # Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers, s.dht_peers, s.pex_peers, s.lsd_peers) else: txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d)' % ( s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete) try: txt3 = 'Arresto automatico in: %ss' % (int(s.timeout)) except: txt3 = '' progreso.update(s.buffer, txt, txt2, txt3) time.sleep(0.5) if progreso.iscanceled(): progreso.close() if s.buffer == 100: if dialog_yesno("Streamondemand - Torrent", "Vuoi avviare la riproduzione?"): played = False progreso = dialog_progress( "Streamondemand - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) else: progreso = dialog_progress( "Streamondemand - Torrent", "") break else: if dialog_yesno("Streamondemand - Torrent", "Vuoi annullare?"): progreso = dialog_progress( "Streamondemand - Torrent", "") break else: progreso = dialog_progress( "Streamondemand - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) # Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: # Cerramos el progreso progreso.close() # Obtenemos el playlist del torrent videourl = c.get_play_list() # Iniciamos el reproductor playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(videourl, xlistitem) xbmc_player = xbmc.Player() xbmc_player.play(playlist) # Marcamos como reproducido para que no se vuelva a iniciar played = True # Y esperamos a que el reproductor se cierre while xbmc.Player().isPlaying(): time.sleep(1) # Cuando este cerrado, Volvemos a mostrar el dialogo progreso = dialog_progress("Streamondemand - Torrent", "") progreso.update(s.buffer, txt, txt2, txt3) except: import traceback logger.info(traceback.format_exc()) break progreso.update(100, "Completamento e cancellazione dei dati", " ", " ") # Detenemos el cliente if not c.closed: c.stop() # Y cerramos el progreso progreso.close()
def play_video(item, desdefavoritos=False, desdedescargados=False, desderrordescargas=False, strmfile=False): from core import servertools logger.info("streamondemand.platformcode.xbmctools play_video") #logger.info(item.tostring('\n')) try: item.server = item.server.lower() except: item.server = "" if item.server == "": item.server = "directo" view = False # Abre el diálogo de selección opciones = [] default_action = config.get_setting("default_action") logger.info("default_action=" + default_action) # Si no es el modo normal, no muestra el diálogo porque cuelga XBMC muestra_dialogo = (config.get_setting("player_mode") == "0" and not strmfile) # Extrae las URL de los vídeos, y si no puedes verlo te dice el motivo video_urls, puedes, motivo = servertools.resolve_video_urls_for_playing( item.server, item.url, item.password, muestra_dialogo) # Si puedes ver el vídeo, presenta las opciones if puedes: for video_url in video_urls: opciones.append( config.get_localized_string(30151) + " " + video_url[0]) if item.server == "local": opciones.append(config.get_localized_string(30164)) else: opcion = config.get_localized_string(30153) opciones.append(opcion) # "Descargar" if item.channel == "favoritos": opciones.append(config.get_localized_string( 30154)) # "Quitar de favoritos" else: opciones.append( config.get_localized_string(30155)) # "Añadir a favoritos" if not strmfile: opciones.append(config.get_localized_string( 30161)) # "Añadir a Biblioteca" if item.channel != "descargas": opciones.append(config.get_localized_string( 30157)) # "Añadir a lista de descargas" else: if item.category == "errores": opciones.append(config.get_localized_string( 30159)) # "Borrar descarga definitivamente" opciones.append(config.get_localized_string( 30160)) # "Pasar de nuevo a lista de descargas" else: opciones.append(config.get_localized_string( 30156)) # "Quitar de lista de descargas" if config.get_setting("jdownloader_enabled") == "true": opciones.append(config.get_localized_string( 30158)) # "Enviar a JDownloader" if default_action == "3": seleccion = len(opciones) - 1 # Busqueda de trailers en youtube if not item.channel in ["Trailer", "ecarteleratrailers"]: opciones.append( config.get_localized_string(30162)) # "Buscar Trailer" # Si no puedes ver el vídeo te informa else: if item.server != "": advertencia = xbmcgui.Dialog() if "<br/>" in motivo: resultado = advertencia.ok( "Non è possibile guardare il video perché...", motivo.split("<br/>")[0], motivo.split("<br/>")[1], item.url) else: resultado = advertencia.ok( "Non è possibile guardare il video perché...", motivo, item.url) else: resultado = advertencia.ok( "Non è possibile guardare il video perché...", "Il server che lo ospita non è", "ancora supportato da streamondemand", item.url) if item.channel == "favoritos": opciones.append( config.get_localized_string(30154)) # "Quitar de favoritos" if item.channel == "descargas": if item.category == "errores": opciones.append(config.get_localized_string( 30159)) # "Borrar descarga definitivamente" else: opciones.append(config.get_localized_string( 30156)) # "Quitar de lista de descargas" if len(opciones) == 0: return # Si la accion por defecto es "Preguntar", pregunta if default_action == "0": # and server!="torrent": dia = xbmcgui.Dialog() seleccion = dia.select(config.get_localized_string(30163), opciones) # "Elige una opción" #dia.close() ''' elif default_action=="0" and server=="torrent": advertencia = xbmcgui.Dialog() logger.info("video_urls[0]="+str(video_urls[0][1])) if puedes and ('"status":"COMPLETED"' in video_urls[0][1] or '"percent_done":100' in video_urls[0][1]): listo = "y está listo para ver" else: listo = "y se está descargando" resultado = advertencia.ok( "Torrent" , "El torrent ha sido añadido a la lista" , listo ) seleccion=-1 ''' elif default_action == "1": seleccion = 0 elif default_action == "2": seleccion = len(video_urls) - 1 elif default_action == "3": seleccion = seleccion else: seleccion = 0 logger.info("seleccion=%d" % seleccion) logger.info("seleccion=%s" % opciones[seleccion]) # No ha elegido nada, lo más probable porque haya dado al ESC if seleccion == -1: #Para evitar el error "Uno o más elementos fallaron" al cancelar la selección desde fichero strm listitem = xbmcgui.ListItem(item.title, iconImage="DefaultVideo.png", thumbnailImage=item.thumbnail) xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem) # JUR Added #if config.get_setting("subtitulo") == "true": # config.set_setting("subtitulo", "false") return if opciones[seleccion] == config.get_localized_string( 30158): # "Enviar a JDownloader" #d = {"web": url}urllib.urlencode(d) from core import scrapertools if item.subtitle != "": data = scrapertools.cachePage( config.get_setting("jdownloader") + "/action/add/links/grabber0/start1/web=" + item.url + " " + item.thumbnail + " " + item.subtitle) else: data = scrapertools.cachePage( config.get_setting("jdownloader") + "/action/add/links/grabber0/start1/web=" + item.url + " " + item.thumbnail) return if opciones[seleccion] == config.get_localized_string(30158).replace( "jDownloader", "pyLoad"): # "Enviar a pyLoad" logger.info("Enviando a pyload...") if item.show != "": package_name = item.show else: package_name = "streamondemand" from core import pyload_client pyload_client.download(url=item.url, package_name=package_name) return elif opciones[seleccion] == config.get_localized_string( 30164): # Borrar archivo en descargas # En "extra" está el nombre del fichero en favoritos os.remove(item.url) xbmc.executebuiltin("Container.Refresh") return # Ha elegido uno de los vídeos elif seleccion < len(video_urls): mediaurl = video_urls[seleccion][1] if len(video_urls[seleccion]) > 3: wait_time = video_urls[seleccion][2] item.subtitle = video_urls[seleccion][3] elif len(video_urls[seleccion]) > 2: wait_time = video_urls[seleccion][2] else: wait_time = 0 view = True # Descargar elif opciones[seleccion] == config.get_localized_string( 30153): # "Descargar" download_title = item.fulltitle if item.hasContentDetails == "true": download_title = item.contentTitle # El vídeo de más calidad es el último mediaurl = video_urls[len(video_urls) - 1][1] from core import downloadtools keyboard = xbmc.Keyboard(download_title) keyboard.doModal() if (keyboard.isConfirmed()): download_title = keyboard.getText() devuelve = downloadtools.downloadbest(video_urls, download_title) if devuelve == 0: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("Download", "Scaricato con successo") elif devuelve == -1: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("Download", "Download interrotto") else: advertencia = xbmcgui.Dialog() resultado = advertencia.ok("Download", "Errore nel download") return elif opciones[seleccion] == config.get_localized_string( 30154): #"Quitar de favoritos" from channels import favoritos # En "extra" está el nombre del fichero en favoritos favoritos.deletebookmark(urllib.unquote_plus(item.extra)) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30102), item.title, config.get_localized_string(30105)) # 'Se ha quitado de favoritos' xbmc.executebuiltin("Container.Refresh") return elif opciones[seleccion] == config.get_localized_string( 30159): #"Borrar descarga definitivamente" from channels import descargas descargas.delete_error_bookmark(urllib.unquote_plus(item.extra)) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30101), item.title, config.get_localized_string(30106)) # 'Se ha quitado de la lista' xbmc.executebuiltin("Container.Refresh") return elif opciones[seleccion] == config.get_localized_string( 30160): #"Pasar de nuevo a lista de descargas": from channels import descargas descargas.mover_descarga_error_a_pendiente( urllib.unquote_plus(item.extra)) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30101), item.title, config.get_localized_string( 30107)) # 'Ha pasado de nuevo a la lista de descargas' return elif opciones[seleccion] == config.get_localized_string( 30155): #"Añadir a favoritos": from channels import favoritos from core import downloadtools download_title = item.fulltitle download_thumbnail = item.thumbnail download_plot = item.plot if item.hasContentDetails == "true": download_title = item.contentTitle download_thumbnail = item.contentThumbnail download_plot = item.contentPlot keyboard = xbmc.Keyboard( downloadtools.limpia_nombre_excepto_1(download_title) + " [" + item.channel + "]") keyboard.doModal() if keyboard.isConfirmed(): title = keyboard.getText() favoritos.savebookmark(titulo=title, url=item.url, thumbnail=download_thumbnail, server=item.server, plot=download_plot, fulltitle=title) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30102), title, config.get_localized_string( 30108)) # 'se ha añadido a favoritos' return elif opciones[seleccion] == config.get_localized_string( 30156): #"Quitar de lista de descargas": # La categoría es el nombre del fichero en la lista de descargas from channels import descargas descargas.deletebookmark((urllib.unquote_plus(item.extra))) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30101), item.title, config.get_localized_string( 30106)) # 'Se ha quitado de lista de descargas' xbmc.executebuiltin("Container.Refresh") return elif opciones[seleccion] == config.get_localized_string( 30157): #"Añadir a lista de descargas": from core import downloadtools download_title = item.fulltitle download_thumbnail = item.thumbnail download_plot = item.plot if item.hasContentDetails == "true": download_title = item.contentTitle download_thumbnail = item.contentThumbnail download_plot = item.contentPlot keyboard = xbmc.Keyboard( downloadtools.limpia_nombre_excepto_1(download_title)) keyboard.doModal() if keyboard.isConfirmed(): download_title = keyboard.getText() from channels import descargas descargas.savebookmark(titulo=download_title, url=item.url, thumbnail=download_thumbnail, server=item.server, plot=download_plot, fulltitle=download_title) advertencia = xbmcgui.Dialog() resultado = advertencia.ok( config.get_localized_string(30101), download_title, config.get_localized_string( 30109)) # 'se ha añadido a la lista de descargas' return elif opciones[seleccion] == config.get_localized_string( 30161): # "Añadir a Biblioteca": # Library titulo = item.fulltitle if titulo == "": titulo = item.title #library.savelibrary(titulo,item.url,item.thumbnail,item.server,item.plot,canal=item.channel,category=item.category,Serie=item.show) # TODO ¿SOLO peliculas? #logger.debug(item.tostring('\n')) new_item = item.clone(title=titulo, action="play_from_library", category="Cine", fulltitle=item.fulltitle, channel=item.channel) #logger.debug(new_item.tostring('\n')) insertados, sobreescritos, fallidos = library.save_library_movie( new_item) advertencia = xbmcgui.Dialog() if fallidos == 0: advertencia.ok(config.get_localized_string(30131), titulo, config.get_localized_string( 30135)) # 'se ha añadido a la biblioteca' return elif opciones[seleccion] == config.get_localized_string( 30162): #"Buscar Trailer": config.set_setting("subtitulo", "false") xbmc.executebuiltin("XBMC.RunPlugin(%s?%s)" % (sys.argv[0], item.clone(channel="trailertools", action="buscartrailer", contextual=True).tourl())) return # Si no hay mediaurl es porque el vídeo no está :) logger.info("streamondemand.platformcode.xbmctools mediaurl=" + mediaurl) if mediaurl == "": if server == "unknown": alertUnsopportedServer() else: alertnodisponibleserver(item.server) return # Si hay un tiempo de espera (como en megaupload), lo impone ahora if wait_time > 0: continuar = handle_wait(wait_time, server, "Cargando vídeo...") if not continuar: return # Obtención datos de la Biblioteca (solo strms que estén en la biblioteca) if strmfile: xlistitem = getLibraryInfo(mediaurl) else: play_title = item.fulltitle play_thumbnail = item.thumbnail play_plot = item.plot if item.hasContentDetails == "true": play_title = item.contentTitle play_thumbnail = item.contentThumbnail play_plot = item.contentPlot try: xlistitem = xbmcgui.ListItem(play_title, iconImage="DefaultVideo.png", thumbnailImage=play_thumbnail, path=mediaurl) except: xlistitem = xbmcgui.ListItem(play_title, iconImage="DefaultVideo.png", thumbnailImage=play_thumbnail) xlistitem.setInfo( "video", { "Title": play_title, "Plot": play_plot, "Studio": item.channel, "Genre": item.category }) #set_infoLabels(listitem,plot) # Modificacion introducida por super_berny para añadir infoLabels al ListItem # Lanza el reproductor # Lanza el reproductor if strmfile and not item.from_biblioteca: #Si es un fichero strm no hace falta el play xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xlistitem) if item.subtitle != "": xbmc.sleep(2000) xbmc.Player().setSubtitles(item.subtitle) #Movido del conector "torrent" aqui elif item.server == "torrent": #Opciones disponibles para Reproducir torrents torrent_options = [] torrent_options.append(["Client (necessario libtorrent)"]) torrent_options.append(["Client interno MCT (necessario libtorrent)"]) #Plugins externos se pueden añadir otros if xbmc.getCondVisibility( 'System.HasAddon("plugin.video.xbmctorrent")'): torrent_options.append([ "Plugin esterno: xbmctorrent", "plugin://plugin.video.xbmctorrent/play/%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.pulsar")'): torrent_options.append([ "Plugin esterno: pulsar", "plugin://plugin.video.pulsar/play?uri=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.quasar")'): torrent_options.append([ "Plugin esterno: quasar", "plugin://plugin.video.quasar/play?uri=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.stream")'): torrent_options.append([ "Plugin esterno: stream", "plugin://plugin.video.stream/play/%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrenter")'): torrent_options.append([ "Plugin esterno: torrenter", "plugin://plugin.video.torrenter/?action=playSTRM&url=%s" ]) if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrentin")'): torrent_options.append([ "Plugin esterno: torrentin", "plugin://plugin.video.torrentin/?uri=%s&image=" ]) if len(torrent_options) > 1: seleccion = xbmcgui.Dialog().select( "Aprire torrent con...", [opcion[0] for opcion in torrent_options]) else: seleccion = 0 #Plugins externos if seleccion > 1: mediaurl = urllib.quote_plus(item.url) xbmc.executebuiltin("PlayMedia(" + torrent_options[seleccion][1] % mediaurl + ")") if seleccion == 1: from platformcode import mct mct.play(mediaurl, xbmcgui.ListItem("", iconImage=item.thumbnail, thumbnailImage=item.thumbnail), subtitle=item.subtitle) #Reproductor propio (libtorrent) if seleccion == 0: import time videourl = None played = False #Importamos el cliente from btserver import Client #Iniciamos el cliente: c = Client(url=mediaurl, is_playing_fnc=xbmc.Player().isPlaying, wait_time=None, timeout=5, temp_path=os.path.join(config.get_data_path(), "torrent")) #Mostramos el progreso progreso = xbmcgui.DialogProgress() progreso.create("streamondemand - Torrent", "Avviando...") #Mientras el progreso no sea cancelado ni el cliente cerrado while not progreso.iscanceled() and not c.closed: try: #Obtenemos el estado del torrent s = c.status #Montamos las tres lineas con la info del torrent txt = '%.2f%% de %.1fMB %s | %.1f kB/s' % \ (s.progress_file, s.file_size, s.str_state, s._download_rate) txt2 = 'S: %d(%d) P: %d(%d) | DHT:%s (%d) | Trakers: %d' % \ (s.num_seeds, s.num_complete, s.num_peers, s.num_incomplete, s.dht_state, s.dht_nodes, s.trackers) txt3 = 'Origen Peers TRK: %d DHT: %d PEX: %d LSD %d ' % \ (s.trk_peers,s.dht_peers, s.pex_peers, s.lsd_peers) progreso.update(s.buffer, txt, txt2, txt3) time.sleep(1) #Si el buffer se ha llenado y la reproduccion no ha sido iniciada, se inicia if s.buffer == 100 and not played: #Cerramos el progreso progreso.close() #Obtenemos el playlist del torrent videourl = c.get_play_list() #Iniciamos el reproductor playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(videourl, xlistitem) xbmcPlayer = xbmc.Player() xbmcPlayer.play(playlist) #Marcamos como reproducido para que no se vuelva a iniciar played = True #Y esperamos a que el reproductor se cierre while xbmc.Player().isPlaying(): time.sleep(1) #Cuando este cerrado, Volvemos a mostrar el dialogo progreso.create("streamondemand - Torrent", "Avviando...") except: import traceback logger.info(traceback.format_exc()) break progreso.update(100, "Terminato, elimina dati", " ", " ") #Detenemos el cliente if not c.closed: c.stop() #Y cerramos el progreso progreso.close() return else: logger.info("player_mode=" + config.get_setting("player_mode")) logger.info("mediaurl=" + mediaurl) if config.get_setting( "player_mode") == "3" or "megacrypter.com" in mediaurl: import download_and_play download_and_play.download_and_play( mediaurl, "download_and_play.tmp", config.get_setting("downloadpath")) return elif config.get_setting("player_mode") == "0" or ( config.get_setting("player_mode") == "3" and mediaurl.startswith("rtmp")): # Añadimos el listitem a una lista de reproducción (playlist) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(mediaurl, xlistitem) # Reproduce playersettings = config.get_setting('player_type') logger.info( "streamondemand.platformcode.xbmctools playersettings=" + playersettings) if config.get_system_platform() == "xbox": player_type = xbmc.PLAYER_CORE_AUTO if playersettings == "0": player_type = xbmc.PLAYER_CORE_AUTO logger.info( "streamondemand.platformcode.xbmctools PLAYER_CORE_AUTO" ) elif playersettings == "1": player_type = xbmc.PLAYER_CORE_MPLAYER logger.info( "streamondemand.platformcode.xbmctools PLAYER_CORE_MPLAYER" ) elif playersettings == "2": player_type = xbmc.PLAYER_CORE_DVDPLAYER logger.info( "streamondemand.platformcode.xbmctools PLAYER_CORE_DVDPLAYER" ) xbmcPlayer = xbmc.Player(player_type) else: xbmcPlayer = xbmc.Player() xbmcPlayer.play(playlist) if item.channel == "cuevana" and item.subtitle != "": logger.info("subtitulo=" + subtitle) if item.subtitle != "" and ( opciones[seleccion].startswith("Ver") or opciones[seleccion].startswith("Watch")): logger.info( "streamondemand.platformcode.xbmctools Con subtitulos") setSubtitles() elif config.get_setting("player_mode") == "1": logger.info("mediaurl :" + mediaurl) logger.info("Tras setResolvedUrl") xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path=mediaurl)) elif config.get_setting("player_mode") == "2": xbmc.executebuiltin("PlayMedia(" + mediaurl + ")") if item.subtitle != "" and view: logger.info("Subtítulos externos: " + item.subtitle) xbmc.Player().setSubtitles(item.subtitle)