def run(item=None): logger.info() if not item: # Extract item from sys.argv if sys.argv[2]: sp = sys.argv[2].split('&') url = sp[0] item = Item().fromurl(url) if len(sp) > 1: for e in sp[1:]: key, val = e.split('=') item.__setattr__(key, val) # If no item, this is mainlist else: if config.get_setting("start_page"): if not config.get_setting("custom_start"): category = config.get_setting("category") if isinstance(category, int): category = config.get_localized_string( config.get_setting("category")).lower() item = Item(channel="news", action="news", news=category.lower(), startpage=True) else: from channels import side_menu item = Item() item = side_menu.check_user_home(item) item.startpage = True else: item = Item(channel="channelselector", action="getmainlist", viewmode="movie") if not config.get_setting('show_once'): from platformcode import configurator configurator.show_window() logger.info(item.tostring()) try: if not config.get_setting('tmdb_active'): config.set_setting('tmdb_active', True) # Cleans infoLabels["playcount"] if set by generictools if item.video_path: item.infoLabels["playcount"] = 1 del item.infoLabels["playcount"] # If item has no action, stops here if item.action == "": logger.info("Item sin accion") return # Action for main menu in channelselector elif item.action == "getmainlist": import channelselector itemlist = channelselector.getmainlist() platformtools.render_items(itemlist, item) # Action for channel types on channelselector: movies, series, etc. elif item.action == "getchanneltypes": import channelselector itemlist = channelselector.getchanneltypes() platformtools.render_items(itemlist, item) # Action for channel listing on channelselector elif item.action == "filterchannels": import channelselector itemlist = channelselector.filterchannels(item.channel_type) platformtools.render_items(itemlist, item) # Action for addon install on channelselector elif item.action == "install_alfa": import channelselector channelselector.install_alfa() # Special action for playing a video from the library elif item.action == "play_from_library": play_from_library(item) return elif item.action == "keymap": from platformcode import keymaptools if item.open: return keymaptools.open_shortcut_menu() else: return keymaptools.set_key() elif item.action == "script": from core import tmdb if tmdb.drop_bd(): platformtools.dialog_notification( config.get_localized_string(20000), config.get_localized_string(60011), time=2000, sound=False) elif item.action == "function": """ { "action": "function", "folder": "lib", "function": "alfa_assistant", "method": "install_alfa_assistant", "options": "auto" } """ # Checks if function file exists function_file = os.path.join(config.get_runtime_path(), item.folder, item.function + ".py") logger.info("function_file=%s" % function_file) function = None if os.path.exists(function_file): try: function = __import__( '%s.%s' % (item.folder, item.function), None, None, ["%s.%s" % (item.folder, item.function)]) except ImportError: exec("import %s." + item.function + " as function") logger.info( "Running function %s(%s) | %s" % (function.__name__, item.options, function.__file__)) getattr(function, item.method)(item.options) else: logger.error( "ERROR Running function %s(%s) | %s" % (function.__name__, item.options, function.__file__)) # Action in certain channel specified in "action" and "channel" parameters else: # Entry point for a channel is the "mainlist" action, so here we check parental control if item.action == "mainlist": # Parental control # If it is an adult channel, and user has configured pin, asks for it if channeltools.is_adult(item.channel) and config.get_setting( "adult_request_password"): tecleado = platformtools.dialog_input( "", config.get_localized_string(60334), True) if tecleado is None or tecleado != config.get_setting( "adult_password"): return # # Actualiza el canal individual # if (item.action == "mainlist" and item.channel != "channelselector" and # config.get_setting("check_for_channel_updates") == True): # from core import updater # updater.update_channel(item.channel) # Checks if channel exists channel_file = os.path.join(config.get_runtime_path(), 'channels', item.channel + ".py") logger.info("channel_file=%s" % channel_file) channel = None if os.path.exists(channel_file): try: channel = __import__('channels.%s' % item.channel, None, None, ["channels.%s" % item.channel]) except ImportError: exec("import channels." + item.channel + " as channel") logger.info("Running channel %s | %s" % (channel.__name__, channel.__file__)) if item.channel == "test" and item.contentChannel: if item.parameters == "test_channel": getattr(channel, item.action)(item.contentChannel) # Calls redirection if Alfavorites findvideos, episodios, seasons if item.context and 'alfavorites' in str(item.context) \ and item.action in ['findvideos', 'episodios', 'seasons', 'play']: try: from lib import generictools item, it, overwrite = generictools.redirect_clone_newpct1( item) except: import traceback logger.error(traceback.format_exc()) # Special play action if item.action == "play": #define la info para trakt try: trakt_tools.set_trakt_info(item) except: pass logger.info("item.action=%s" % item.action.upper()) # logger.debug("item_toPlay: " + "\n" + item.tostring('\n')) # First checks if channel has a "play" function if hasattr(channel, 'play'): logger.info("Executing channel 'play' method") itemlist = channel.play(item) b_favourite = item.isFavourite # Play should return a list of playable URLS if len(itemlist) > 0 and isinstance(itemlist[0], Item): item = itemlist[0] if b_favourite: item.isFavourite = True platformtools.play_video(item) # Permitir varias calidades desde play en el canal elif len(itemlist) > 0 and isinstance(itemlist[0], list): item.video_urls = itemlist platformtools.play_video(item) # If not, shows user an error message else: platformtools.dialog_ok( config.get_localized_string(20000), config.get_localized_string(60339)) # If player don't have a "play" function, not uses the standard play from platformtools else: logger.info("Executing core 'play' method") platformtools.play_video(item) # Special action for findvideos, where the plugin looks for known urls elif item.action == "findvideos": # First checks if channel has a "findvideos" function if hasattr(channel, 'findvideos'): itemlist = getattr(channel, item.action)(item) itemlist = servertools.filter_servers(itemlist) # If not, uses the generic findvideos function else: logger.info("No channel 'findvideos' method, " "executing core method") itemlist = servertools.find_video_items(item) if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist) from platformcode import subtitletools subtitletools.saveSubtitleName(item) platformtools.render_items(itemlist, item) # Special action for adding a movie to the library elif item.action == "add_pelicula_to_library": videolibrarytools.add_movie(item) # Special action for adding a serie to the library elif item.action == "add_serie_to_library": videolibrarytools.add_tvshow(item, channel) # Special action for downloading all episodes from a serie elif item.action == "download_all_episodes": from channels import downloads item.action = item.extra del item.extra downloads.save_download(item) # Special action for searching, first asks for the words then call the "search" function elif item.action == "search": logger.info("item.action=%s" % item.action.upper()) # last_search = "" # last_search_active = config.get_setting("last_search", "search") # if last_search_active: # try: # current_saved_searches_list = list(config.get_setting("saved_searches_list", "search")) # last_search = current_saved_searches_list[0] # except: # pass last_search = channeltools.get_channel_setting( 'Last_searched', 'search', '') tecleado = platformtools.dialog_input(last_search) if tecleado is not None: if "http" not in tecleado: channeltools.set_channel_setting( 'Last_searched', tecleado, 'search') itemlist = channel.search(item, tecleado) else: return platformtools.render_items(itemlist, item) # For all other actions else: logger.info("Executing channel '%s' method" % item.action) itemlist = getattr(channel, item.action)(item) if config.get_setting('trakt_sync'): token_auth = config.get_setting("token_trakt", "trakt") if not token_auth: trakt_tools.auth_trakt() else: import xbmc if not xbmc.getCondVisibility( 'System.HasAddon(script.trakt)' ) and config.get_setting('install_trakt'): trakt_tools.ask_install_script() itemlist = trakt_tools.trakt_check(itemlist) else: config.set_setting('install_trakt', True) platformtools.render_items(itemlist, item) except urllib2.URLError as e: import traceback logger.error(traceback.format_exc()) # Grab inner and third party errors if hasattr(e, 'reason'): logger.error("Razon del error, codigo: %s | Razon: %s" % (str(e.reason[0]), str(e.reason[1]))) texto = config.get_localized_string( 30050) # "No se puede conectar con el sitio web" platformtools.dialog_ok("alfa", texto) # Grab server response errors elif hasattr(e, 'code'): logger.error("Codigo de error HTTP : %d" % e.code) # "El sitio web no funciona correctamente (error http %d)" platformtools.dialog_ok( "alfa", config.get_localized_string(30051) % e.code) except WebErrorException as e: import traceback logger.error(traceback.format_exc()) patron = 'File "' + os.path.join(config.get_runtime_path(), "channels", "").replace("\\", "\\\\") + '([^.]+)\.py"' canal = scrapertools.find_single_match(traceback.format_exc(), patron) platformtools.dialog_ok( config.get_localized_string(59985) + canal, config.get_localized_string(60013) % (e)) except: import traceback logger.error(traceback.format_exc()) patron = 'File "' + os.path.join(config.get_runtime_path(), "channels", "").replace("\\", "\\\\") + '([^.]+)\.py"' canal = scrapertools.find_single_match(traceback.format_exc(), patron) try: if config.get_platform(True)['num_version'] < 14: log_name = "xbmc.log" else: log_name = "kodi.log" log_message = config.get_localized_string( 50004) + config.translatePath("special://logpath") + log_name except: log_message = "" if canal: platformtools.dialog_ok( config.get_localized_string(60087) % canal, config.get_localized_string(60014), log_message) else: platformtools.dialog_ok(config.get_localized_string(60038), config.get_localized_string(60015), log_message)
def check_for_update(overwrite=True): logger.info("Actualizando series...") from core import filetools from core import channeltools, videolibrarytools from platformcode import platformtools from channels import videolibrary from lib import generictools if config.is_xbmc(): from platformcode import xbmc_videolibrary p_dialog = None serie_actualizada = False update_when_finished = False hoy = datetime.date.today() estado_verify_playcount_series = False try: if config.get_setting("update", "videolibrary") != 0 or overwrite: config.set_setting("updatelibrary_last_check", hoy.strftime('%Y-%m-%d'), "videolibrary") heading = config.get_localized_string(60389) p_dialog = platformtools.dialog_progress_bg( config.get_localized_string(20000), heading) p_dialog.update(0, '') show_list = [] for path, folders, files in filetools.walk( videolibrarytools.TVSHOWS_PATH): show_list.extend([ filetools.join(path, f) for f in files if f == "tvshow.nfo" ]) if show_list: t = float(100) / len(show_list) for i, tvshow_file in enumerate(show_list): try: head_nfo, serie = videolibrarytools.read_nfo(tvshow_file) if not serie: logger.error('.nfo erroneo en ' + str(tvshow_file)) continue path = filetools.dirname(tvshow_file) ###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial overwrite_forced = False try: serie, serie, overwrite_forced = generictools.redirect_clone_newpct1( serie, head_nfo, serie, path, overwrite, lookup=True) except: logger.error(traceback.format_exc()) if overwrite_forced == True: overwrite = True serie.update_next = '' info_status = '' if serie.infoLabels['status']: info_status = serie.infoLabels['status'] logger.info("Serie=%s, Activa=%s, Fecha=%s, Status=%s" % (serie.contentSerieName, \ str(serie.active), str(serie.update_last), str(info_status))) p_dialog.update(int(math.ceil((i + 1) * t)), heading, serie.contentSerieName) #Verificamos el estado del serie.library_playcounts de la Serie por si está incompleto try: estado = False #Si no hemos hecho la verificación o no tiene playcount, entramos estado = config.get_setting("verify_playcount", "videolibrary") if not estado or estado == False or not serie.library_playcounts: #Si no se ha pasado antes, lo hacemos ahora serie, estado = videolibrary.verify_playcount_series( serie, path ) #También se pasa si falta un PlayCount por completo except: logger.error(traceback.format_exc()) else: if estado: #Si ha tenido éxito la actualización... estado_verify_playcount_series = True #... se marca para cambiar la opción de la Videoteca interval = int(serie.active) # Podria ser del tipo bool if not serie.active: # si la serie no esta activa descartar if overwrite_forced == False: #Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa, aunque la serie esté desactivada try: if config.is_xbmc(): #Si es Kodi, lo hacemos xbmc_videolibrary.mark_content_as_watched_on_alfa( path + '/tvshow.nfo') except: logger.error(traceback.format_exc()) continue # obtenemos las fecha de actualizacion y de la proxima programada para esta serie update_next = serie.update_next if update_next: y, m, d = update_next.split('-') update_next = datetime.date(int(y), int(m), int(d)) else: update_next = hoy update_last = serie.update_last if update_last: y, m, d = update_last.split('-') update_last = datetime.date(int(y), int(m), int(d)) else: update_last = hoy # si la serie esta activa ... if overwrite or config.get_setting( "updatetvshows_interval", "videolibrary") == 0: # ... forzar actualizacion independientemente del intervalo serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada: update_next = hoy + datetime.timedelta( days=interval) elif interval == 1 and update_next <= hoy: # ...actualizacion diaria serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada and update_last <= hoy - datetime.timedelta( days=7): # si hace una semana q no se actualiza, pasar el intervalo a semanal interval = 7 update_next = hoy + datetime.timedelta( days=interval) elif interval == 7 and update_next <= hoy: # ...actualizacion semanal serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada: if update_last <= hoy - datetime.timedelta( days=14): # si hace 2 semanas q no se actualiza, pasar el intervalo a mensual interval = 30 update_next += datetime.timedelta(days=interval) elif interval == 30 and update_next <= hoy: # ...actualizacion mensual serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada: update_next += datetime.timedelta(days=interval) if serie_actualizada: update_last = hoy update_next = hoy + datetime.timedelta(days=interval) head_nfo, serie = videolibrarytools.read_nfo( tvshow_file ) #Vuelve a leer el.nfo, que ha sido modificado if interval != int(serie.active) or update_next.strftime( '%Y-%m-%d' ) != serie.update_next or update_last.strftime( '%Y-%m-%d') != serie.update_last: serie.update_last = update_last.strftime('%Y-%m-%d') if update_next > hoy: serie.update_next = update_next.strftime( '%Y-%m-%d') if serie.infoLabels[ "status"] != "Ended" and serie.infoLabels[ "status"] != "Canceled": serie.active = interval serie.channel = "videolibrary" serie.action = "get_seasons" filetools.write(tvshow_file, head_nfo + serie.tojson()) if serie_actualizada and not config.get_setting( 'cleanlibrary', 'videolibrary', default=False): if config.get_setting("search_new_content", "videolibrary") == 0: # Actualizamos la videoteca de Kodi: Buscar contenido en la carpeta de la serie if config.is_xbmc(): xbmc_videolibrary.update( folder=filetools.basename(path)) update_when_finished = True else: update_when_finished = True except Exception as ex: logger.error( "Se ha producido un error al actualizar la serie %s" % tvshow_file) template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) logger.error(traceback.format_exc(1)) if estado_verify_playcount_series: #Si se ha cambiado algún playcount, ... estado = config.set_setting( "verify_playcount", True, "videolibrary" ) #... actualizamos la opción de Videolibrary #if config.get_setting("search_new_content", "videolibrary") == 1 and update_when_finished: if config.is_xbmc() and config.get_setting( 'cleanlibrary', 'videolibrary', default=False): while xbmc.getCondVisibility( 'Library.IsScanningVideo()'): # Se espera a que acabe time.sleep(1) xbmc.executebuiltin('CleanLibrary(video)') while xbmc.getCondVisibility( 'Library.IsScanningVideo()'): # Se espera a que acabe time.sleep(1) update_when_finished = True config.set_setting('cleanlibrary', False, 'videolibrary') if update_when_finished: # Actualizamos la videoteca de Kodi: Buscar contenido en todas las series if config.is_xbmc(): xbmc_videolibrary.update() p_dialog.close() else: logger.info( "No actualiza la videoteca, está desactivado en la configuración de alfa" ) except Exception as ex: logger.error("Se ha producido un error al actualizar las series") template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) if p_dialog: p_dialog.close() # Sincroniza los "vistos" de la Videoteca de Películas from core.item import Item item_dummy = Item() videolibrary.list_movies(item_dummy, silent=True) # Descarga los últimos episodios disponibles, si el canal lo permite from channels import downloads downloads.download_auto(item_dummy)
def clear_saved_searches(item): config.set_setting("saved_searches_list", list(), "search") platformtools.dialog_ok(config.get_localized_string(60329), config.get_localized_string(60424))
def check_for_update(overwrite=True): logger.info("Actualizando series...") p_dialog = None serie_actualizada = False update_when_finished = False hoy = datetime.date.today() estado_verify_playcount_series = False try: if config.get_setting("update", "videolibrary") != 0 or overwrite: config.set_setting("updatelibrary_last_check", hoy.strftime('%Y-%m-%d'), "videolibrary") heading = config.get_localized_string(60389) p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), heading) p_dialog.update(0, '') show_list = [] for path, folders, files in filetools.walk(videolibrarytools.TVSHOWS_PATH): show_list.extend([filetools.join(path, f) for f in files if f == "tvshow.nfo"]) if show_list: t = float(100) / len(show_list) for i, tvshow_file in enumerate(show_list): head_nfo, serie = videolibrarytools.read_nfo(tvshow_file) path = filetools.dirname(tvshow_file) ###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial overwrite_forced = False try: serie, serie, overwrite_forced = generictools.redirect_clone_newpct1(serie, head_nfo, serie, path, overwrite, lookup=True) except: pass if overwrite_forced == True: overwrite = True serie.update_next = '' logger.info("serie=" + serie.contentSerieName) p_dialog.update(int(math.ceil((i + 1) * t)), heading, serie.contentSerieName) #Verificamos el estado del serie.library_playcounts de la Serie por si está incompleto try: estado = False #Si no hemos hecho la verificación o no tiene playcount, entramos estado = config.get_setting("verify_playcount", "videolibrary") if not estado or estado == False or not serie.library_playcounts: #Si no se ha pasado antes, lo hacemos ahora serie, estado = videolibrary.verify_playcount_series(serie, path) #También se pasa si falta un PlayCount por completo except: pass else: if estado: #Si ha tenido éxito la actualización... estado_verify_playcount_series = True #... se marca para cambiar la opción de la Videoteca interval = int(serie.active) # Podria ser del tipo bool if not serie.active: # si la serie no esta activa descartar if overwrite_forced == False: #Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa, aunque la serie esté desactivada try: if config.is_xbmc(): #Si es Kodi, lo hacemos from platformcode import xbmc_videolibrary xbmc_videolibrary.mark_content_as_watched_on_alfa(path + '/tvshow.nfo') except: pass continue # obtenemos las fecha de actualizacion y de la proxima programada para esta serie update_next = serie.update_next if update_next: y, m, d = update_next.split('-') update_next = datetime.date(int(y), int(m), int(d)) else: update_next = hoy update_last = serie.update_last if update_last: y, m, d = update_last.split('-') update_last = datetime.date(int(y), int(m), int(d)) else: update_last = hoy # si la serie esta activa ... if overwrite or config.get_setting("updatetvshows_interval", "videolibrary") == 0: # ... forzar actualizacion independientemente del intervalo serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) elif interval == 1 and update_next <= hoy: # ...actualizacion diaria serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada and update_last <= hoy - datetime.timedelta(days=7): # si hace una semana q no se actualiza, pasar el intervalo a semanal interval = 7 update_next = hoy + datetime.timedelta(days=interval) elif interval == 7 and update_next <= hoy: # ...actualizacion semanal serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada: if update_last <= hoy - datetime.timedelta(days=14): # si hace 2 semanas q no se actualiza, pasar el intervalo a mensual interval = 30 update_next += datetime.timedelta(days=interval) elif interval == 30 and update_next <= hoy: # ...actualizacion mensual serie_actualizada = update(path, p_dialog, i, t, serie, overwrite) if not serie_actualizada: update_next += datetime.timedelta(days=interval) head_nfo, serie = videolibrarytools.read_nfo(tvshow_file) #Vuelve a leer el.nfo, que ha sido modificado if interval != int(serie.active) or update_next.strftime('%Y-%m-%d') != serie.update_next: if update_next > hoy: serie.update_next = update_next.strftime('%Y-%m-%d') serie.active = interval serie.channel = "videolibrary" serie.action = "get_seasons" filetools.write(tvshow_file, head_nfo + serie.tojson()) if serie_actualizada: if config.get_setting("search_new_content", "videolibrary") == 0: # Actualizamos la videoteca de Kodi: Buscar contenido en la carpeta de la serie if config.is_xbmc(): from platformcode import xbmc_videolibrary xbmc_videolibrary.update(folder=filetools.basename(path)) else: update_when_finished = True if estado_verify_playcount_series: #Si se ha cambiado algún playcount, ... estado = config.set_setting("verify_playcount", True, "videolibrary") #... actualizamos la opción de Videolibrary if config.get_setting("search_new_content", "videolibrary") == 1 and update_when_finished: # Actualizamos la videoteca de Kodi: Buscar contenido en todas las series if config.is_xbmc(): from platformcode import xbmc_videolibrary xbmc_videolibrary.update() p_dialog.close() else: logger.info("No actualiza la videoteca, está desactivado en la configuración de alfa") except Exception, ex: logger.error("Se ha producido un error al actualizar las series") template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) if p_dialog: p_dialog.close()
def update_libtorrent(): logger.info() if not config.get_setting("mct_buffer", server="torrent", default=""): default = config.get_setting("torrent_client", server="torrent", default=0) config.set_setting("torrent_client", default, server="torrent") config.set_setting("mct_buffer", "50", server="torrent") if config.get_setting("mct_download_path", server="torrent", default=config.get_setting("downloadpath")): config.set_setting("mct_download_path", config.get_setting("downloadpath"), server="torrent") config.set_setting("mct_background_download", True, server="torrent") config.set_setting("mct_rar_unpack", True, server="torrent") config.set_setting("bt_buffer", "50", server="torrent") if config.get_setting("bt_download_path", server="torrent", default=config.get_setting("downloadpath")): config.set_setting("bt_download_path", config.get_setting("downloadpath"), server="torrent") config.set_setting("mct_download_limit", "", server="torrent") config.set_setting("magnet2torrent", False, server="torrent") if not filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) or not \ config.get_setting("unrar_path", server="torrent", default=""): path = filetools.join(config.get_runtime_path(), 'lib', 'rarfiles') creationflags = '' sufix = '' unrar = '' for device in filetools.listdir(path): if xbmc.getCondVisibility( "system.platform.android") and 'android' not in device: continue if xbmc.getCondVisibility( "system.platform.windows") and 'windows' not in device: continue if not xbmc.getCondVisibility("system.platform.windows") and not xbmc.getCondVisibility("system.platform.android") \ and ('android' in device or 'windows' in device): continue if 'windows' in device: creationflags = 0x08000000 sufix = '.exe' else: creationflags = '' sufix = '' unrar = filetools.join(path, device, 'unrar%s') % sufix if not filetools.exists(unrar): unrar = '' if unrar: if not xbmc.getCondVisibility("system.platform.windows"): try: if xbmc.getCondVisibility("system.platform.android"): # Para Android copiamos el binario a la partición del sistema unrar_org = unrar unrar = filetools.join( xbmc.translatePath('special://xbmc/'), 'files').replace('/cache/apk/assets', '') if not filetools.exists(unrar): filetools.mkdir(unrar) unrar = filetools.join(unrar, 'unrar') filetools.copy(unrar_org, unrar, silent=True) command = ['chmod', '777', '%s' % unrar] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output_cmd, error_cmd = p.communicate() command = ['ls', '-l', unrar] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output_cmd, error_cmd = p.communicate() xbmc.log('######## UnRAR file: %s' % str(output_cmd), xbmc.LOGNOTICE) except: xbmc.log( '######## UnRAR ERROR in path: %s' % str(unrar), xbmc.LOGNOTICE) logger.error(traceback.format_exc(1)) try: if xbmc.getCondVisibility("system.platform.windows"): p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=creationflags) else: p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output_cmd, error_cmd = p.communicate() if p.returncode != 0 or error_cmd: xbmc.log('######## UnRAR returncode in module %s: %s, %s in %s' % \ (device, str(p.returncode), str(error_cmd), unrar), xbmc.LOGNOTICE) unrar = '' else: xbmc.log( '######## UnRAR OK in %s: %s' % (device, unrar), xbmc.LOGNOTICE) break except: xbmc.log( '######## UnRAR ERROR in module %s: %s' % (device, unrar), xbmc.LOGNOTICE) logger.error(traceback.format_exc(1)) unrar = '' if unrar: config.set_setting("unrar_path", unrar, server="torrent") if filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) and \ config.get_setting("libtorrent_path", server="torrent", default="") : return try: from lib.python_libtorrent.python_libtorrent import get_libtorrent except Exception as e: logger.error(traceback.format_exc(1)) if not PY3: e = unicode(str(e), "utf8", errors="replace").encode("utf8") config.set_setting("libtorrent_path", "", server="torrent") if not config.get_setting( "libtorrent_error", server="torrent", default=''): config.set_setting("libtorrent_error", str(e), server="torrent") return
def setting_channel_new(item): import xbmcgui # Load list of options (active user channels that allow global search) lista = [] ids = [] lista_lang = [] lista_ctgs = [] channels_list = channelselector.filterchannels('all') for channel in channels_list: if channel.action == '': continue channel_parameters = channeltools.get_channel_parameters( channel.channel) # Do not include if "include_in_global_search" does not exist in the channel configuration if not channel_parameters.get('include_in_global_search', ''): continue lbl = '%s' % channel_parameters['language'] lbl += ' %s' % ', '.join( config.get_localized_category(categ) for categ in channel_parameters['categories']) if config.get_platform(True)['num_version'] >= 18.0: it = xbmcgui.ListItem(channel.title, lbl, offscreen=True) else: it = xbmcgui.ListItem(channel.title, lbl) it.setArt({'thumb': channel.thumbnail, 'fanart': channel.fanart}) lista.append(it) ids.append(channel.channel) lista_lang.append(channel_parameters['language']) lista_ctgs.append(channel_parameters['categories']) # Pre-select dialog preselecciones = [ config.get_localized_string(70570), config.get_localized_string(70571), 'Modificar partiendo de Recomendados', 'Modificar partiendo de Frecuentes', config.get_localized_string(70572), config.get_localized_string(70573), config.get_localized_string(70574), config.get_localized_string(70575) ] presel_values = [ 'skip', 'actual', 'recom', 'freq', 'all', 'none', 'cast', 'lat' ] categs = [ 'movie', 'tvshow', 'documentary', 'anime', 'vos', 'direct', 'torrent', 'sport' ] if config.get_setting('adult_mode') > 0: categs.append('adult') for c in categs: preselecciones.append( config.get_localized_string(70577) + config.get_localized_category(c)) presel_values.append(c) if item.action == 'setting_channel': # Configuración de los canales incluídos en la búsqueda del preselecciones[0] del presel_values[0] # else: # Call from "search on other channels" (you can skip the selection and go directly to the search) ret = dialog_select(config.get_localized_string(59994), preselecciones) if ret == -1: return False # order cancel if presel_values[ret] == 'skip': return True # continue unmodified elif presel_values[ret] == 'none': preselect = [] elif presel_values[ret] == 'all': preselect = list(range(len(ids))) elif presel_values[ret] in ['cast', 'lat']: preselect = [] for i, lg in enumerate(lista_lang): if presel_values[ret] in lg or '*' in lg: preselect.append(i) elif presel_values[ret] == 'actual': preselect = [] for i, canal in enumerate(ids): channel_status = config.get_setting('include_in_global_search', canal) if channel_status: preselect.append(i) elif presel_values[ret] == 'recom': preselect = [] for i, canal in enumerate(ids): _not, set_canal_list = channeltools.get_channel_controls_settings( canal) if set_canal_list.get('include_in_global_search', False): preselect.append(i) elif presel_values[ret] == 'freq': preselect = [] for i, canal in enumerate(ids): frequency = channeltools.get_channel_setting('frequency', canal, 0) if frequency > 0: preselect.append(i) else: preselect = [] for i, ctgs in enumerate(lista_ctgs): if presel_values[ret] in ctgs: preselect.append(i) # Dialog to select ret = xbmcgui.Dialog().multiselect(config.get_localized_string(59994), lista, preselect=preselect, useDetails=True) if not ret: return False # order cancel seleccionados = [ids[i] for i in ret] # Save changes to search channels for canal in ids: channel_status = config.get_setting('include_in_global_search', canal) if channel_status and canal not in seleccionados: config.set_setting('include_in_global_search', False, canal) elif not channel_status and canal in seleccionados: config.set_setting('include_in_global_search', True, canal) return True
def token_trakt(item): from platformcode import platformtools headers = { 'Content-Type': 'application/json', 'trakt-api-key': client_id, 'trakt-api-version': '2' } try: if item.extra == "renew": refresh = config.get_setting("refresh_token_trakt", "trakt") url = "http://api-v2launch.trakt.tv/oauth/device/token" post = { 'refresh_token': refresh, 'client_id': client_id, 'client_secret': client_secret, 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token' } post = jsontools.dump(post) data = httptools.downloadpage(url, post=post, headers=headers).data data = jsontools.load(data) elif item.action == "token_trakt": url = "http://api-v2launch.trakt.tv/oauth/device/token" post = "code=%s&client_id=%s&client_secret=%s" % ( item.device_code, client_id, client_secret) data = httptools.downloadpage(url, post=post, headers=headers).data data = jsontools.load(data) else: import time dialog_auth = platformtools.dialog_progress( config.get_localized_string(60251), config.get_localized_string(60252) % item.verify_url, config.get_localized_string(60253) % item.user_code, config.get_localized_string(60254)) # Generalmente cada 5 segundos se intenta comprobar si el usuario ha introducido el código while True: time.sleep(item.intervalo) try: if dialog_auth.iscanceled(): config.set_setting("trakt_sync", False) return url = "http://api-v2launch.trakt.tv/oauth/device/token" post = { 'code': item.device_code, 'client_id': client_id, 'client_secret': client_secret } post = jsontools.dump(post) data = httptools.downloadpage(url, post=post, headers=headers).data data = jsontools.load(data) if "access_token" in data: # Código introducido, salimos del bucle break except: pass try: dialog_auth.close() except: pass token = data["access_token"] refresh = data["refresh_token"] config.set_setting("token_trakt", token, "trakt") config.set_setting("refresh_token_trakt", refresh, "trakt") if not item.folder: platformtools.dialog_notification( config.get_localized_string(60255), config.get_localized_string(60256)) if config.is_xbmc(): import xbmc xbmc.executebuiltin("Container.Refresh") return except: import traceback logger.error(traceback.format_exc()) if not item.folder: return platformtools.dialog_notification( config.get_localized_string(60527), config.get_localized_string(60258)) token = "" itemlist = [] if token: itemlist.append( item.clone(config.get_localized_string(60256), action="")) else: itemlist.append( item.clone(config.get_localized_string(60260), action="")) return itemlist
def setting_channel_new(item): import channelselector, xbmcgui from core import channeltools # Cargar lista de opciones (canales activos del usuario y que permitan búsqueda global) # ------------------------ lista = []; ids = []; lista_lang = [] channels_list = channelselector.filterchannels('all') for channel in channels_list: channel_parameters = channeltools.get_channel_parameters(channel.channel) # No incluir si en la configuracion del canal no existe "include_in_global_search" if not channel_parameters['include_in_global_search']: continue lbl = '%s' % channel_parameters['language'] lbl += ' %s' % ', '.join(config.get_localized_category(categ) for categ in channel_parameters['categories']) it = xbmcgui.ListItem(channel.title, lbl) it.setArt({ 'thumb': channel.thumbnail, 'fanart': channel.fanart }) lista.append(it) ids.append(channel.channel) lista_lang.append(channel_parameters['language']) # Diálogo para pre-seleccionar # ---------------------------- preselecciones_std = ['Modificar selección actual', 'Modificar partiendo de Todos', 'Modificar partiendo de Ninguno', 'Modificar partiendo de Castellano', 'Modificar partiendo de Latino'] if item.action == 'setting_channel': # Configuración de los canales incluídos en la búsqueda preselecciones = preselecciones_std presel_values = [1, 2, 3, 4, 5] else: # Llamada desde "buscar en otros canales" (se puede saltar la selección e ir directo a la búsqueda) preselecciones = ['Buscar con la selección actual'] + preselecciones_std presel_values = [0, 1, 2, 3, 4, 5] ret = platformtools.dialog_select(config.get_localized_string(59994), preselecciones) if ret == -1: return False # pedido cancel if presel_values[ret] == 0: return True # continuar sin modificar elif presel_values[ret] == 3: preselect = [] elif presel_values[ret] == 2: preselect = range(len(ids)) elif presel_values[ret] in [4, 5]: busca = 'cast' if presel_values[ret] == 4 else 'lat' preselect = [] for i, lg in enumerate(lista_lang): if busca in lg or '*' in lg: preselect.append(i) else: preselect = [] for i, canal in enumerate(ids): channel_status = config.get_setting('include_in_global_search', canal) if channel_status: preselect.append(i) # Diálogo para seleccionar # ------------------------ ret = xbmcgui.Dialog().multiselect(config.get_localized_string(59994), lista, preselect=preselect, useDetails=True) if ret == None: return False # pedido cancel seleccionados = [ids[i] for i in ret] # Guardar cambios en canales para la búsqueda # ------------------------------------------- for canal in ids: channel_status = config.get_setting('include_in_global_search', canal) if channel_status is None: channel_status = True if channel_status and canal not in seleccionados: config.set_setting('include_in_global_search', False, canal) elif not channel_status and canal in seleccionados: config.set_setting('include_in_global_search', True, canal) return True
def setting_channel_new(item): import channelselector, xbmcgui from core import channeltools # Cargar lista de opciones (canales activos del usuario y que permitan búsqueda global) # ------------------------ lista = [] ids = [] lista_lang = [] lista_ctgs = [] channels_list = channelselector.filterchannels('all') for channel in channels_list: if channel.action == '': continue channel_parameters = channeltools.get_channel_parameters( channel.channel) # No incluir si en la configuracion del canal no existe "include_in_global_search" if not channel_parameters['include_in_global_search']: continue lbl = '%s' % channel_parameters['language'] lbl += ' %s' % ', '.join( config.get_localized_category(categ) for categ in channel_parameters['categories']) it = xbmcgui.ListItem(channel.title, lbl) it.setArt({'thumb': channel.thumbnail, 'fanart': channel.fanart}) lista.append(it) ids.append(channel.channel) lista_lang.append(channel_parameters['language']) lista_ctgs.append(channel_parameters['categories']) # Diálogo para pre-seleccionar # ---------------------------- preselecciones = [ 'Buscar con la selección actual', 'Modificar selección actual', 'Modificar partiendo de Frecuentes', 'Modificar partiendo de Todos', 'Modificar partiendo de Ninguno', 'Modificar partiendo de Castellano', 'Modificar partiendo de Latino' ] presel_values = ['skip', 'actual', 'freq', 'all', 'none', 'cast', 'lat'] categs = [ 'movie', 'tvshow', 'documentary', 'anime', 'vos', 'direct', 'torrent' ] if config.get_setting('adult_mode') > 0: categs.append('adult') for c in categs: preselecciones.append('Modificar partiendo de %s' % config.get_localized_category(c)) presel_values.append(c) if item.action == 'setting_channel': # Configuración de los canales incluídos en la búsqueda del preselecciones[0] del presel_values[0] #else: # Llamada desde "buscar en otros canales" (se puede saltar la selección e ir directo a la búsqueda) ret = platformtools.dialog_select(config.get_localized_string(59994), preselecciones) logger.debug(presel_values[ret]) if ret == -1: return False # pedido cancel if presel_values[ret] == 'skip': return True # continuar sin modificar elif presel_values[ret] == 'none': preselect = [] elif presel_values[ret] == 'all': preselect = range(len(ids)) elif presel_values[ret] in ['cast', 'lat']: preselect = [] for i, lg in enumerate(lista_lang): if presel_values[ret] in lg or '*' in lg: preselect.append(i) elif presel_values[ret] == 'actual': preselect = [] for i, canal in enumerate(ids): channel_status = config.get_setting('include_in_global_search', canal) if channel_status: preselect.append(i) elif presel_values[ret] == 'freq': preselect = [] for i, canal in enumerate(ids): logger.debug('el canal: %s' % canal) frequency = channeltools.get_channel_setting('frequency', canal, 0) if frequency > 0: logger.debug(ids) preselect.append(i) logger.debug(preselect) else: preselect = [] for i, ctgs in enumerate(lista_ctgs): if presel_values[ret] in ctgs: preselect.append(i) # Diálogo para seleccionar # ------------------------ ret = xbmcgui.Dialog().multiselect(config.get_localized_string(59994), lista, preselect=preselect, useDetails=True) if ret == None: return False # pedido cancel seleccionados = [ids[i] for i in ret] # Guardar cambios en canales para la búsqueda # ------------------------------------------- for canal in ids: channel_status = config.get_setting('include_in_global_search', canal) if channel_status is None: channel_status = True if channel_status and canal not in seleccionados: config.set_setting('include_in_global_search', False, canal) elif not channel_status and canal in seleccionados: config.set_setting('include_in_global_search', True, canal) return True
def save_settings(item, dict_values): for v in dict_values: config.set_setting("include_in_newest_" + item.extra, dict_values[v], v)
def check_addon_init(): logger.info() # Subtarea de monitor. Se activa cada X horas para comprobar si hay FIXES al addon def check_addon_monitor(): logger.info() # Obtiene el íntervalo entre actualizaciones y si se quieren mensajes try: timer = int( config.get_setting('addon_update_timer', default=12) ) # Intervalo entre actualizaciones, en Ajustes de Alfa if timer <= 0: try: user_type = base64.b64decode( config.get_setting('proxy_dev')).decode('utf-8') except: user_type = 'user' if user_type == 'user': config.set_setting( 'addon_update_timer', 12) # Si es usuario se fuerza a 12 horas timer = 12 else: return # 0. No se quieren actualizaciones verbose = config.get_setting('addon_update_message', default=False) except: logger.error(traceback.format_exc()) timer = 12 # Por defecto cada 12 horas verbose = False # Por defecto, sin mensajes timer = timer * 3600 # Lo pasamos a segundos if config.get_platform( True)['num_version'] >= 14: # Si es Kodi, lanzamos el monitor monitor = xbmc.Monitor() else: # Lanzamos solo una actualización y salimos check_addon_updates(verbose) # Lanza la actualización return while not monitor.abortRequested( ): # Loop infinito hasta cancelar Kodi check_addon_updates(verbose) # Lanza la actualización if monitor.waitForAbort( timer ): # Espera el tiempo programado o hasta que cancele Kodi break # Cancelación de Kodi, salimos check_update_to_others( verbose=False, app=False ) # Actualizamos otros add-ons antes de irnos, para el siguiente inicio # Borra el .zip de instalación de Alfa de la carpeta Packages, por si está corrupto, y que así se pueda descargar de nuevo version = 'plugin.video.alfa-%s.zip' % config.get_addon_version( with_fix=False, from_xml=True) packages_path = os.path.join(config.translatePath('special://home'), 'addons', 'packages', version) if os.path.exists(packages_path): os.remove(packages_path) return # Lanzamos en Servicio de actualización de FIXES try: threading.Thread(target=check_addon_monitor).start( ) # Creamos un Thread independiente, hasta el fin de Kodi time.sleep(5) # Dejamos terminar la primera verificación... except: # Si hay problemas de threading, se llama una sola vez try: timer = int( config.get_setting('addon_update_timer', default=12) ) # Intervalo entre actualizaciones, en Ajustes de Alfa if timer <= 0: try: user_type = base64.b64decode( config.get_setting('proxy_dev')).decode('utf-8') except: user_type = 'user' if user_type == 'user': config.set_setting( 'addon_update_timer', 12) # Si es usuario se fuerza a 12 horas timer = 12 else: return # 0. No se quieren actualizaciones verbose = config.get_setting('addon_update_message', default=False) except: verbose = False # Por defecto, sin mensajes pass check_addon_updates( verbose) # Lanza la actualización, en Ajustes de Alfa time.sleep(5) # Dejamos terminar la primera verificación... return
def novedades(item): logger.info() global list_newest threads = [] list_newest = [] start_time = time.time() mode = item.mode if mode == '': mode = 'normal' if mode=='get_cached': if os.path.exists(menu_cache_path): return get_from_cache(item) multithread = config.get_setting("multithread", "news") logger.info("multithread= " + str(multithread)) if not multithread: if platformtools.dialog_yesno("Búsqueda concurrente desactivada", "La búsqueda concurrente de novedades proporciona", "una mayor velocidad y su desactivación solo es aconsejable en caso de fallo.", "¿Desea activar la búsqueda concurrente ahora?"): if config.set_setting("multithread", True, "news"): multithread = True if mode == 'normal': progreso = platformtools.dialog_progress(item.category, "Buscando canales...") list_canales, any_active = get_channels_list() if mode=='silent' and any_active and len(list_canales[item.extra]) > 0: side_menu.set_menu_settings(item) aux_list=[] for canal in list_canales[item.extra]: if len(aux_list)<2: aux_list.append(canal) list_canales[item.extra]=aux_list if mode == 'set_cache': list_canales[item.extra] = list_canales[item.extra][2:] if any_active and len(list_canales[item.extra])>0: import math # fix float porque la division se hace mal en python 2.x number_of_channels = float(100) / len(list_canales[item.extra]) for index, channel in enumerate(list_canales[item.extra]): channel_id, channel_title = channel percentage = int(math.ceil((index + 1) * number_of_channels)) # if progreso.iscanceled(): # progreso.close() # logger.info("Búsqueda cancelada") # return itemlist # Modo Multi Thread if multithread: t = Thread(target=get_newest, args=[channel_id, item.extra], name=channel_title) t.start() threads.append(t) if mode == 'normal': progreso.update(percentage, "", "Buscando en '%s'..." % channel_title) # Modo single Thread else: if mode == 'normal': logger.info("Obteniendo novedades de channel_id=" + channel_id) progreso.update(percentage, "", "Buscando en '%s'..." % channel_title) get_newest(channel_id, item.extra) # Modo Multi Thread: esperar q todos los hilos terminen if multithread: pendent = [a for a in threads if a.isAlive()] t = float(100) / len(pendent) while pendent: index = (len(threads) - len(pendent)) + 1 percentage = int(math.ceil(index * t)) list_pendent_names = [a.getName() for a in pendent] if mode == 'normal': mensaje = "Buscando en %s" % (", ".join(list_pendent_names)) progreso.update(percentage, "Finalizado en %d/%d canales..." % (len(threads) - len(pendent), len(threads)), mensaje) logger.debug(mensaje) if progreso.iscanceled(): logger.info("Busqueda de novedades cancelada") break time.sleep(0.5) pendent = [a for a in threads if a.isAlive()] if mode == 'normal': mensaje = "Resultados obtenidos: %s | Tiempo: %2.f segundos" % (len(list_newest), time.time() - start_time) progreso.update(100, mensaje, " ", " ") logger.info(mensaje) start_time = time.time() # logger.debug(start_time) result_mode = config.get_setting("result_mode", "news") if mode != 'normal': result_mode=0 if result_mode == 0: # Agrupados por contenido ret = group_by_content(list_newest) elif result_mode == 1: # Agrupados por canales ret = group_by_channel(list_newest) else: # Sin agrupar ret = no_group(list_newest) while time.time() - start_time < 2: # mostrar cuadro de progreso con el tiempo empleado durante almenos 2 segundos time.sleep(0.5) if mode == 'normal': progreso.close() if mode == 'silent': set_cache(item) item.mode = 'set_cache' ret = add_menu_items(item, ret) if mode != 'set_cache': return ret else: if mode != 'set_cache': no_channels = platformtools.dialog_ok('Novedades - %s'%item.extra, 'No se ha definido ningun canal para la ' 'busqueda.','Utilice el menu contextual ' 'para agregar al menos uno') return
return xbmc.AddonData( kodi_home_path=os.path.join(os.getcwd(), 'tests', 'home'), add_on_id='plugin.video.kod', add_on_path=os.getcwd(), kodi_profile_path=os.path.join(os.getcwd(), 'tests', 'home', 'userdata')) # override xbmc.get_add_on_info_from_calling_script = add_on_info import HtmlTestRunner import parameterized from platformcode import config, logger config.set_setting('tmdb_active', False) librerias = os.path.join(config.get_runtime_path(), 'lib') sys.path.insert(0, librerias) from core.support import typo from core.item import Item from core.httptools import downloadpage from core import servertools import channelselector import re validUrlRegex = re.compile( r'^(?:http|ftp)s?://' # http:// or https:// r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... r'localhost|' # localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
def registerOrLogin(page_url): if config.get_setting('username', server='hdmario') and config.get_setting( 'password', server='hdmario'): if login(): return True if platformtools.dialog_yesno( 'HDmario', 'Questo server necessita di un account, ne hai già uno oppure vuoi tentare una registrazione automatica?', yeslabel='Accedi', nolabel='Tenta registrazione'): from specials import setting from core.item import Item user_pre = config.get_setting('username', server='hdmario') password_pre = config.get_setting('password', server='hdmario') setting.server_config(Item(config='hdmario')) user_post = config.get_setting('username', server='hdmario') password_post = config.get_setting('password', server='hdmario') if user_pre != user_post or password_pre != password_post: return registerOrLogin(page_url) else: return False else: import random import string logger.debug('Registrazione automatica in corso') mailbox = Gmailnator() randPsw = ''.join( random.choice(string.ascii_letters + string.digits) for i in range(10)) captcha = httptools.downloadpage(baseUrl + '/captchaInfo').json logger.debug('email: ' + mailbox.address) logger.debug('pass: '******'/register/', email=True, password=True, email_default=mailbox.address, password_default=randPsw, captcha_img=captcha['captchaUrl']) if not reg: return False regPost = httptools.downloadpage(baseUrl + '/register/', post={ 'email': reg['email'], 'email_confirmation': reg['email'], 'password': reg['password'], 'password_confirmation': reg['password'], 'captchaUuid': captcha['captchaUuid'], 'captcha': reg['captcha'] }) if '/register' in regPost.url: error = scrapertools.htmlclean( scrapertools.find_single_match( regPost.data, 'Impossibile proseguire.*?</div>')) error = scrapertools.unescape( scrapertools.re.sub('\n\s+', ' ', error)) platformtools.dialog_ok('HDmario', error) return False if reg['email'] == mailbox.address: mail = mailbox.waitForMail() if mail: checkUrl = scrapertools.find_single_match( mail.body, 'href="([^"]+)">Premi qui').replace(r'\/', '/') logger.debug('CheckURL: ' + checkUrl) httptools.downloadpage(checkUrl) config.set_setting('username', mailbox.address, server='hdmario') config.set_setting('password', randPsw, server='hdmario') platformtools.dialog_ok( 'HDmario', 'Registrato automaticamente con queste credenziali:\nemail:' + mailbox.address + '\npass: '******'HDmario', 'Impossibile registrarsi automaticamente') return False else: platformtools.dialog_ok( 'HDmario', 'Hai modificato la mail quindi KoD non sarà in grado di effettuare la verifica in autonomia, apri la casella ' + reg['email'] + ' e clicca sul link. Premi ok quando fatto') logger.debug('Registrazione completata') return True
path_list = [dest_path] log('path_list = ' + str(path_list)) fp, pathname, description = imp.find_module( 'libtorrent', path_list) log('fp = ' + str(fp)) log('pathname = ' + str(pathname)) log('description = ' + str(description)) try: libtorrent = imp.load_module('libtorrent', fp, pathname, description) finally: if fp: fp.close() except Exception as e: if not PY3: e = unicode(str(e), "utf8", errors="replace").encode("utf8") config.set_setting("libtorrent_path", "", server="torrent") ### Alfa config.set_setting("libtorrent_error", str(e), server="torrent") ### Alfa log(traceback.format_exc(1)) log('fp = ' + str(fp)) log('pathname = ' + str(pathname)) log('description = ' + str(description)) log('Error importing libtorrent from "' + dest_path + '". Exception: ' + str(e)) if fp: fp.close() # If no permission in dest_path we need to go deeper on root! try: ### Alfa START sys_path = '/data/app/' fp = '' pathname = sys_path
def findvideos(item): logger.info() itemlist = [] item.url = item.url.replace(host + 'black_json/movie/', 'http://tv-vip.com/json/repo/').replace( 'movie.js', 'index.json') item.referer = item.referer.replace(host + 'playmovie/', 'http://tv-vip.com/film/') headers = default_headers.copy() cookies = {} proxies = config.get_setting('proxies', item.channel, default='').replace(' ', '') if ';' in proxies: # Si los proxies estan separados por ; orden aleatorio proxies = proxies.replace(',', ';').split(';') import random random.shuffle(proxies) else: proxies = proxies.split(',') proxy_ok = False for n, proxy in enumerate(proxies): use_proxy = None if proxy == '' else {'http': proxy} # 1- /film/... (obtener cookies __cfduid y __cflb) resp = httptools.downloadpage(item.referer, headers=headers, only_headers=True, cookies=False, use_proxy=use_proxy, raise_weberror=False) if (type(resp.code) == int and (resp.code < 200 or resp.code > 399)) or not resp.sucess: logger.info('El proxy %s NO responde adecuadamente. %s' % (proxy, resp.code)) else: proxy_ok = True logger.info('El proxy %s parece válido.' % proxy) if n > 0: # guardar el proxy que ha funcionado como primero de la lista si no lo está del proxies[n] new_proxies = proxy + ', ' + ', '.join(proxies) config.set_setting('proxies', new_proxies, item.channel) break if not proxy_ok: platformtools.dialog_notification( 'Sin respuesta válida', 'Ninguno de los proxies ha funcionado.') return itemlist cks = httptools.get_cookies_from_headers(resp.headers) cookies.update(cks) # 2- /video2-prod/s/c (obtener cookie c) headers['Referer'] = item.referer headers['Cookie'] = '; '.join( [ck_name + '=' + ck_value for ck_name, ck_value in cookies.items()]) resp = httptools.downloadpage('http://tv-vip.com/video2-prod/s/c', headers=headers, cookies=False, use_proxy=use_proxy) cks = httptools.get_cookies_from_headers(resp.headers) cookies.update(cks) # 3- /json/repo/... headers['X-Requested-With'] = 'XMLHttpRequest' headers['Cookie'] = '; '.join( [ck_name + '=' + ck_value for ck_name, ck_value in cookies.items()]) try: data = jsontools.load( httptools.downloadpage(item.url, headers=headers, cookies=False, use_proxy=use_proxy).data) except: return itemlist if 'profiles' not in data: return itemlist # 4- /vendors/font-awesome/ (por cf_clearance !? required !?) url = 'http://tv-vip.com/vendors/font-awesome/fonts/fontawesome-webfont.woff2?v=4.7.0' headers[ 'Referer'] = 'http://tv-vip.com/vendors/font-awesome/css/font-awesome.min.css' headers['Accept-Encoding'] = 'identity' del headers['X-Requested-With'] resp = httptools.downloadpage(url, headers=headers, only_headers=True, cookies=False, use_proxy=use_proxy) for perfil, datos in data['profiles'].items(): for servidor in datos['servers']: if servidor['id'] == 's2': continue # con s2 parece que siempre falla el vídeo itemlist.append( Item(channel=item.channel, action='play', server='directo', title='', videoUri=datos['videoUri'], videoServer=servidor['id'], referer=item.referer, cookies=headers['Cookie'], use_proxy=use_proxy, language='', quality=datos['videoResolution'], quality_num=datos['height'], other=datos['sizeHuman'] + ', ' + servidor['id'])) # ~ return sorted(itemlist, key=lambda it: it.quality_num) # ordenar por calidad ascendente return itemlist
def clear_saved_searches(item): config.set_setting("saved_searches_list", list(), "search") dialog_ok(config.get_localized_string(60423), config.get_localized_string(60424))
def show_channel_settings(self, list_controls=None, dict_values=None, caption="", callback=None, item=None, custom_button=None, channelpath=None): from platformcode import config from core import channeltools from core import servertools import inspect if not os.path.isdir(os.path.join(config.get_data_path(), "settings_channels")): os.mkdir(os.path.join(config.get_data_path(), "settings_channels")) title = caption if type(custom_button) == dict: custom_button = {"label": custom_button.get("label", ""), "function": custom_button.get("function", ""), "visible": bool(custom_button.get("visible", True)), "close": bool(custom_button.get("close", False))} else: custom_button = None # Obtenemos el canal desde donde se ha echo la llamada y cargamos los settings disponibles para ese canal if not channelpath: channelpath = inspect.currentframe().f_back.f_back.f_code.co_filename channelname = os.path.basename(channelpath).replace(".py", "") ch_type = os.path.basename(os.path.dirname(channelpath)) # Si no tenemos list_controls, hay que sacarlos del json del canal if not list_controls: # Si la ruta del canal esta en la carpeta "channels", obtenemos los controles y valores mediante chaneltools if os.path.join(config.get_runtime_path(), "channels") in channelpath: # La llamada se hace desde un canal list_controls, default_values = channeltools.get_channel_controls_settings(channelname) kwargs = {"channel": channelname} # Si la ruta del canal esta en la carpeta "servers", obtenemos los controles y valores mediante servertools elif os.path.join(config.get_runtime_path(), "servers") in channelpath: # La llamada se hace desde un server list_controls, default_values = servertools.get_server_controls_settings(channelname) kwargs = {"server": channelname} # En caso contrario salimos else: return None # Si no se pasan dict_values, creamos un dict en blanco if dict_values == None: dict_values = {} # Ponemos el titulo if caption == "": caption = str(config.get_localized_string(30100)) + " -- " + channelname.capitalize() elif caption.startswith('@') and unicode(caption[1:]).isnumeric(): caption = config.get_localized_string(int(caption[1:])) JsonData = {} JsonData["action"] = "OpenConfig" JsonData["data"] = {} JsonData["data"]["title"] = self.kodi_labels_to_html(caption) JsonData["data"]["custom_button"] = custom_button JsonData["data"]["items"] = [] # Añadir controles for c in list_controls: if not "default" in c: c["default"] = "" if not "color" in c: c["color"] = "auto" if not "label" in c: continue # Obtenemos el valor if "id" in c: if not c["id"] in dict_values: if not callback: c["value"] = config.get_setting(c["id"], **kwargs) else: c["value"] = c["default"] dict_values[c["id"]] = c["value"] else: c["value"] = dict_values[c["id"]] # Translation if c['label'].startswith('@') and unicode(c['label'][1:]).isnumeric(): c['label'] = str(config.get_localized_string(c['label'][1:])) if c["label"].endswith(":"): c["label"] = c["label"][:-1] if c['type'] == 'list': lvalues = [] for li in c['lvalues']: if li.startswith('@') and unicode(li[1:]).isnumeric(): lvalues.append(str(config.get_localized_string(li[1:]))) else: lvalues.append(li) c['lvalues'] = lvalues c["label"] = self.kodi_labels_to_html(c["label"]) JsonData["data"]["items"].append(c) ID = self.send_message(JsonData) close = False while True: data = self.get_data(ID) if type(data) == dict: JsonData["action"] = "HideLoading" JsonData["data"] = {} self.send_message(JsonData) for v in data: if data[v] == "true": data[v] = True if data[v] == "false": data[v] = False if unicode(data[v]).isnumeric(): data[v] = int(data[v]) if callback and '.' in callback: package, callback = callback.rsplit('.', 1) else: package = '%s.%s' % (ch_type, channelname) cb_channel = None try: cb_channel = __import__(package, None, None, [package]) except ImportError: logger.error('Imposible importar %s' % package) if callback: # Si existe una funcion callback la invocamos ... return getattr(cb_channel, callback)(item, data) else: # si no, probamos si en el canal existe una funcion 'cb_validate_config' ... try: return getattr(cb_channel, 'cb_validate_config')(item, data) except AttributeError: # ... si tampoco existe 'cb_validate_config'... for v in data: config.set_setting(v, data[v], **kwargs) elif data == "custom_button": if '.' in callback: package, callback = callback.rsplit('.', 1) else: package = '%s.%s' % (ch_type, channelname) try: cb_channel = __import__(package, None, None, [package]) except ImportError: logger.error('Imposible importar %s' % package) else: return_value = getattr(cb_channel, custom_button['function'])(item, dict_values) if custom_button["close"] == True: return return_value else: JsonData["action"] = "custom_button" JsonData["data"] = {} JsonData["data"]["values"] = dict_values JsonData["data"]["return_value"] = return_value ID = self.send_message(JsonData) elif data == False: return None
def start(itemlist, item): ''' Main method from which the links are automatically reproduced - In case the option to activate it will use the options defined by the user. - Otherwise it will try to reproduce any link that has the preferred language. :param itemlist: list (list of items ready to play, ie with action = 'play') :param item: item (the main item of the channel) :return: try to auto-reproduce, in case of failure it returns the itemlist that it received in the beginning ''' if item.global_search: return itemlist logger.info() global PLAYED PLAYED = False base_item = item if not config.is_xbmc(): return itemlist if config.get_setting('autoplay'): url_list_valid = [] autoplay_list = [] autoplay_b = [] favorite_quality = [] favorite_servers = [] blacklisted_servers = config.get_setting("black_list", server='servers') if not blacklisted_servers: blacklisted_servers = [] from core import servertools servers_list = list(servertools.get_servers_list().items()) for server, server_parameters in servers_list: if config.get_setting('favorites_servers_list', server=server): favorite_servers.append(server.lower()) if not favorite_servers: config.set_setting('favorites_servers_list', [], server='servers') favorite_servers = [] else: favorite_servers = list( set(favorite_servers) - set(blacklisted_servers)) # Save the current value of "Action and Player Mode" in preferences user_config_setting_action = config.get_setting("default_action") user_config_setting_player = config.get_setting("player_mode") # Enable the "View in high quality" action (if the server returns more than one quality, eg gdrive) if not user_config_setting_action: config.set_setting("default_action", 2) if user_config_setting_player != 0: config.set_setting("player_mode", 0) # Priorities when ordering itemlist: # 0: Servers and qualities # 1: Qualities and servers # 2: Servers only # 3: Only qualities # 4: Do not order if config.get_setting('favorites_servers' ) and favorite_servers and config.get_setting( 'default_action'): priority = 0 # 0: Servers and qualities or 1: Qualities and servers elif config.get_setting('favorites_servers') and favorite_servers: priority = 2 # Servers only elif config.get_setting('default_action'): priority = 3 # Only qualities else: priority = 4 # Do not order if config.get_setting('default_action') == 1: quality_list.reverse() favorite_quality = quality_list for item in itemlist: autoplay_elem = dict() b_dict = dict() # We check that it is a video item if 'server' not in item: continue if item.server.lower() in blacklisted_servers: continue # If it does not have a defined quality, it assigns a 'default' quality. if item.quality.lower() not in quality_list: item.quality = 'default' # The list for custom settings is created if priority < 2: # 0: Servers and qualities or 1: Qualities and servers # if the server and the quality are not in the favorites lists or the url is repeated, we discard the item if item.server.lower( ) not in favorite_servers or item.quality.lower( ) not in favorite_quality or item.url in url_list_valid: item.type_b = True item.play_from = base_item.play_from b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_server"] = favorite_servers.index( item.server.lower()) autoplay_elem["indice_quality"] = favorite_quality.index( item.quality.lower()) elif priority == 2: # Servers only # if the server is not in the favorites list or the url is repeated, we discard the item if item.server.lower( ) not in favorite_servers or item.url in url_list_valid: item.type_b = True item.play_from = base_item.play_from b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_server"] = favorite_servers.index( item.server.lower()) elif priority == 3: # Only qualities # if the quality is not in the favorites list or the url is repeated, we discard the item if item.quality.lower( ) not in favorite_quality or item.url in url_list_valid: item.type_b = True item.play_from = base_item.play_from b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_quality"] = favorite_quality.index( item.quality.lower()) else: # Do not order # if the url is repeated, we discard the item item.play_from = base_item.play_from if item.url in url_list_valid: continue # If the item reaches here we add it to the list of valid urls and to autoplay_list url_list_valid.append(item.url) item.plan_b = True item.play_from = base_item.play_from autoplay_elem['videoitem'] = item autoplay_list.append(autoplay_elem) # We order according to priority if priority == 0: autoplay_list.sort(key=lambda orden: (orden['indice_quality'], orden['indice_server'] )) # Servers and qualities elif priority == 1: autoplay_list.sort(key=lambda orden: (orden['indice_quality'], orden['indice_server'] )) # Qualities and servers elif priority == 2: autoplay_list.sort(key=lambda orden: (orden['indice_server'])) # Servers only elif priority == 3: autoplay_list.sort(key=lambda orden: (orden['indice_quality'])) # Only qualities # if quality priority is active if priority == 0 and config.get_setting('quality_priority'): max_quality = autoplay_list[0][ "indice_quality"] if autoplay_list and "indice_quality" in autoplay_list[ 0] else 0 for n, item in enumerate(itemlist): if 'server' not in item: continue if item.server.lower() in blacklisted_servers: continue # If it does not have a defined quality, it assigns a 'default' quality. if item.quality == '': item.quality = 'default' if favorite_quality.index(item.quality.lower()) < max_quality: item.type_b = False autoplay_elem["indice_server"] = n autoplay_elem["indice_quality"] = favorite_quality.index( item.quality.lower()) autoplay_elem['videoitem'] = item autoplay_list.append(autoplay_elem) autoplay_list.sort(key=lambda orden: (orden['indice_quality'], orden['indice_server'])) # Plan b is prepared, in case it is active the non-favorite elements are added at the end # try: plan_b = settings_node['plan_b'] # except: plan_b = True text_b = '' if plan_b: autoplay_list.extend(autoplay_b) # If there are elements in the autoplay list, an attempt is made to reproduce each element, until one is found or all fail. if autoplay_list or (plan_b and autoplay_b): max_intentos = 5 max_intentos_servers = {} # If something is playing it stops playing if platformtools.is_playing(): platformtools.stop_video() for autoplay_elem in autoplay_list: play_item = Item channel_id = autoplay_elem['videoitem'].channel if autoplay_elem['videoitem'].channel == 'videolibrary': channel_id = autoplay_elem['videoitem'].contentChannel # If it is not a favorite element if you add the text plan b if autoplay_elem['videoitem'].type_b: text_b = '(Plan B)' if not platformtools.is_playing() and not PLAYED: videoitem = autoplay_elem['videoitem'] if videoitem.server.lower() not in max_intentos_servers: max_intentos_servers[ videoitem.server.lower()] = max_intentos # If the maximum number of attempts of this server have been reached, we jump to the next if max_intentos_servers[videoitem.server.lower()] == 0: continue lang = " " if hasattr(videoitem, 'language') and videoitem.language != "": lang = " '%s' " % videoitem.language name = servername(videoitem.server) platformtools.dialog_notification( "AutoPlay %s" % text_b, "%s%s%s" % (name, lang, videoitem.quality.upper()), sound=False) # Try to play the links If the channel has its own play method, use it try: channel = __import__('channels.%s' % channel_id, None, None, ["channels.%s" % channel_id]) except: channel = __import__('specials.%s' % channel_id, None, None, ["specials.%s" % channel_id]) if hasattr(channel, 'play'): resolved_item = getattr(channel, 'play')(videoitem) if len(resolved_item) > 0: if isinstance(resolved_item[0], list): videoitem.video_urls = resolved_item else: videoitem = resolved_item[0] # If not directly reproduce and mark as seen # Check if the item comes from the video library try: if base_item.contentChannel == 'videolibrary' or base_item.nfo: # Fill the video with the data of the main item and play play_item = base_item.clone(**videoitem.__dict__) platformtools.play_video(play_item, autoplay=True) else: # If it doesn't come from the video library, just play platformtools.play_video(videoitem, autoplay=True) except: pass sleep(3) try: if platformtools.is_playing(): PLAYED = True break except: logger.debug(str(len(autoplay_list))) # If we have come this far, it is because it could not be reproduced max_intentos_servers[videoitem.server.lower()] -= 1 # If the maximum number of attempts of this server has been reached, ask if we want to continue testing or ignore it. if max_intentos_servers[videoitem.server.lower()] == 0: text = config.get_localized_string(60072) % name if not platformtools.dialog_yesno( "AutoPlay", text, config.get_localized_string(60073)): max_intentos_servers[ videoitem.server.lower()] = max_intentos # If there are no items in the list, it is reported if autoplay_elem == autoplay_list[-1]: platformtools.dialog_notification( 'AutoPlay', config.get_localized_string(60072) % name) else: platformtools.dialog_notification( config.get_localized_string(60074), config.get_localized_string(60075)) # Restore if necessary the previous value of "Action and Player Mode" in preferences if not user_config_setting_action: config.set_setting("default_action", user_config_setting_action) if user_config_setting_player != 0: config.set_setting("player_mode", user_config_setting_player) return itemlist
e = e1 or e2 do.ok('ERROR en el cliente MCT Libtorrent', 'Módulo no encontrado o imcompatible con el dispositivo.', 'Reporte el fallo adjuntando un "log".', str(e)) from core import scrapertools from core import filetools from core import httptools #try: config.set_setting("background_download", False, "mct") #except: config.set_setting("mct_background_download", "false") try: BUFFER = int(config.get_setting("mct_buffer", server="torrent", default="50")) except: BUFFER = 50 config.set_setting("mct_buffer", "50", server="torrent") DOWNLOAD_PATH = config.get_setting("mct_download_path", server="torrent", default=config.get_setting("downloadpath")) BACKGROUND = config.get_setting("mct_background_download", server="torrent", default=True) RAR = config.get_setting("mct_rar_unpack", server="torrent", default=True) DOWNLOAD_LIMIT = config.get_setting("mct_download_limit", server="torrent", default="") if DOWNLOAD_LIMIT: try: DOWNLOAD_LIMIT = int(DOWNLOAD_LIMIT) * 1024 except: DOWNLOAD_LIMIT = 0 else: DOWNLOAD_LIMIT = 0 UPLOAD_LIMIT = 100 * 1024 msg_header = 'Alfa MCT Cliente Torrent' def play(url, xlistitem={}, is_view=None, subtitle="", password="", item=None):
def agrupa_datos(url, post=None, referer=True, json=False, proxy=True, forced_proxy=None, proxy_retries=1): global host headers = {'Referer': host} if 'episodes' in url or 'buscar' in url: headers['Referer'] += 'episodios' if not referer: headers.pop('Referer') # if cookie: # headers.update('Cookie:' 'language=es') if isinstance(referer, str): headers.update({'Referer': referer}) if host in host_blacklist: list_controls, dict_settings = channeltools.get_channel_controls_settings("hdfull") config.set_setting("current_host", dict_settings['current_host'], channel="hdfull") host = dict_settings['current_host'] parsed = urlparse.urlparse(host) if len(parsed.path) > 1: parse_url = "https://%s/" % parsed.netloc config.set_setting("current_host", parse_url, channel="hdfull") url = re.sub(r'http(?:s|)://[^/]+/', host, url) page = httptools.downloadpage(url, post=post, headers=headers, ignore_response_code=True, proxy=proxy, forced_proxy=forced_proxy, proxy_retries=proxy_retries) if not page.sucess: list_controls, dict_settings = channeltools.get_channel_controls_settings("hdfull") if dict_settings['current_host'] != config.get_setting("current_host", channel="hdfull", default=""): config.set_setting("current_host", dict_settings['current_host'], channel="hdfull") host = dict_settings['current_host'] return agrupa_datos(url, post=post, referer=referer, json=json, proxy=True, forced_proxy='ProxyWeb', proxy_retries=0) if not page.sucess and not proxy: return agrupa_datos(url, post=post, referer=referer, json=json, proxy=True, forced_proxy='ProxyWeb', proxy_retries=0) new_host = scrapertools.find_single_match(page.data, r'location.replace\("(http(?:s|)://\w+.hdfull.\w{2,4})') backup = scrapertools.find_single_match(page.data, r'onclick="redirect\(\)"><strong>(http[^<]+)') if not new_host and backup and 'dominio temporalmente' in page.data: new_host = backup if new_host: if not new_host.endswith('/'): new_host += '/' config.set_setting("current_host", new_host, channel="hdfull") url = re.sub(host, new_host, url) host = config.get_setting("current_host", channel="hdfull") return agrupa_datos(url, post=post, referer=referer, json=json) if json: return page.json # if raw: # return page.data data = page.data if PY3 and isinstance(data, bytes): data = "".join(chr(x) for x in bytes(data)) ## Agrupa los datos data = re.sub(r'\n|\r|\t| |<br>|<!--.*?-->', '', data) data = re.sub(r'\s+', ' ', data) data = re.sub(r'>\s<', '><', data) return data
def clear_saved_searches(item): config.set_setting("saved_searches_list", list(), "search") platformtools.dialog_ok("Buscador", "Búsquedas borradas correctamente")
def update_external_addon(addon_name): logger.info(addon_name) try: #Verificamos que el addon está instalado if xbmc.getCondVisibility('System.HasAddon("plugin.video.%s")' % addon_name): #Path de actualizaciones de Alfa alfa_addon_updates_mig = filetools.join(config.get_runtime_path(), "lib") alfa_addon_updates = filetools.join(alfa_addon_updates_mig, addon_name) #Path de destino en addon externo __settings__ = xbmcaddon.Addon(id="plugin.video." + addon_name) if addon_name.lower() in ['quasar', 'elementum']: addon_path_mig = filetools.join(xbmc.translatePath(__settings__.getAddonInfo('Path')), \ filetools.join("resources", "site-packages")) addon_path = filetools.join(addon_path_mig, addon_name) else: addon_path_mig = '' addon_path = '' #Hay modificaciones en Alfa? Las copiamos al addon, incuidas las carpetas de migración a PY3 if filetools.exists(alfa_addon_updates) and filetools.exists( addon_path): for root, folders, files in filetools.walk( alfa_addon_updates_mig): if ('future' in root or 'past' in root) and not 'concurrent' in root: for file in files: alfa_addon_updates_mig_folder = root.replace( alfa_addon_updates_mig, addon_path_mig) if not filetools.exists( alfa_addon_updates_mig_folder): filetools.mkdir(alfa_addon_updates_mig_folder) if file.endswith('.pyo') or file.endswith('.pyd'): continue input_file = filetools.join(root, file) output_file = input_file.replace( alfa_addon_updates_mig, addon_path_mig) if not filetools.copy( input_file, output_file, silent=True): logger.error( 'Error en la copia de MIGRACIÓN: Input: %s o Output: %s' % (input_file, output_file)) return False for root, folders, files in filetools.walk(alfa_addon_updates): for file in files: input_file = filetools.join(root, file) output_file = input_file.replace( alfa_addon_updates, addon_path) if not filetools.copy( input_file, output_file, silent=True): logger.error( 'Error en la copia: Input: %s o Output: %s' % (input_file, output_file)) return False return True else: logger.error('Alguna carpeta no existe: Alfa: %s o %s: %s' % (alfa_addon_updates, addon_name, addon_path)) # Se ha desinstalado Quasar, reseteamos la opción else: config.set_setting('addon_quasar_update', False) if filetools.exists( filetools.join(config.get_data_path(), "%s.json" % addon_name)): filetools.remove( filetools.join(config.get_data_path(), "%s.json" % addon_name)) return True except: logger.error(traceback.format_exc()) return False
def run(item=None): logger.info() if not item: # Extract item from sys.argv if sys.argv[2]: sp = sys.argv[2].split('&') url = sp[0] item = Item().fromurl(url) if len(sp) > 1: for e in sp[1:]: key, val = e.split('=') item.__setattr__(key, val) # If no item, this is mainlist else: if config.get_setting("start_page"): if not config.get_setting("custom_start"): dictCategory = { config.get_localized_string(70137): 'peliculas', config.get_localized_string(30123): 'series', config.get_localized_string(30124): 'anime', config.get_localized_string(70018): 'infantiles', config.get_localized_string(60513): 'documentales', config.get_localized_string(70013): 'terror', config.get_localized_string(70014): 'castellano', config.get_localized_string(59976): 'latino', config.get_localized_string(70171): 'torrent', } if not config.get_setting( "category") in dictCategory.keys(): config.set_setting('category', config.get_localized_string(70137)) category = dictCategory[config.get_setting("category")] item = Item(channel="news", action="novedades", extra=category, mode='silent') else: from specials import side_menu item = Item() item = side_menu.check_user_home(item) item.start = True else: item = Item(channel="channelselector", action="getmainlist", viewmode="movie") if not config.get_setting('show_once'): from platformcode import xbmc_videolibrary xbmc_videolibrary.ask_set_content(silent=False) config.set_setting('show_once', True) logger.info(item.tostring()) try: if not config.get_setting('tmdb_active'): config.set_setting('tmdb_active', True) # If item has no action, stops here if item.action == "": logger.info("Item without action") return # Action for main menu in channelselector elif item.action == "getmainlist": import channelselector itemlist = channelselector.getmainlist() platformtools.render_items(itemlist, item) # Action for channel types on channelselector: movies, series, etc. elif item.action == "getchanneltypes": import channelselector itemlist = channelselector.getchanneltypes() platformtools.render_items(itemlist, item) # Action for channel listing on channelselector elif item.action == "filterchannels": import channelselector itemlist = channelselector.filterchannels(item.channel_type) platformtools.render_items(itemlist, item) # Special action for playing a video from the library elif item.action == "play_from_library": play_from_library(item) return elif item.action == "keymap": from platformcode import keymaptools if item.open: return keymaptools.open_shortcut_menu() else: return keymaptools.set_key() elif item.action == "delete_key": from platformcode import keymaptools return keymaptools.delete_key() elif item.action == "script": from core import tmdb if tmdb.drop_bd(): platformtools.dialog_notification( config.get_localized_string(20000), config.get_localized_string(60011), time=2000, sound=False) elif item.action == "itemInfo": import base64 platformtools.dialog_textviewer('Item info', item.parent) elif item.action == "open_browser": import webbrowser if not webbrowser.open(item.url): import xbmc if xbmc.getCondVisibility( 'system.platform.linux') and xbmc.getCondVisibility( 'system.platform.android'): # android xbmc.executebuiltin( 'StartAndroidActivity("", "android.intent.action.VIEW", "", "%s")' % (item.url)) else: try: import urllib.request as urllib except ImportError: import urllib short = urllib.urlopen( 'https://u.nu/api.php?action=shorturl&format=simple&url=' + item.url).read().decode('utf-8') platformtools.dialog_ok( config.get_localized_string(20000), config.get_localized_string(70740) % short) # Action in certain channel specified in "action" and "channel" parameters else: # Entry point for a channel is the "mainlist" action, so here we check parental control if item.action == "mainlist": from core import channeltools #updater.checkforupdates() beta version checking for update, still disabled # Parental control # If it is an adult channel, and user has configured pin, asks for it if channeltools.is_adult(item.channel) and config.get_setting( "adult_request_password"): tecleado = platformtools.dialog_input( "", config.get_localized_string(60334), True) if tecleado is None or tecleado != config.get_setting( "adult_password"): return # # Actualiza el canal individual # if (item.action == "mainlist" and item.channel != "channelselector" and # config.get_setting("check_for_channel_updates") == True): # from core import updater # updater.update_channel(item.channel) # Checks if channel exists if os.path.isfile( os.path.join(config.get_runtime_path(), 'channels', item.channel + ".py")): CHANNELS = 'channels' elif os.path.isfile( os.path.join(config.get_runtime_path(), 'channels', 'p**n', item.channel + ".py")): CHANNELS = 'channels.p**n' else: CHANNELS = 'specials' if CHANNELS != 'channels.p**n': channel_file = os.path.join(config.get_runtime_path(), CHANNELS, item.channel + ".py") else: channel_file = os.path.join(config.get_runtime_path(), 'channels', 'p**n', item.channel + ".py") logger.info("channel_file= " + channel_file + ' - ' + CHANNELS + ' - ' + item.channel) channel = None if os.path.exists(channel_file): try: channel = __import__('%s.%s' % (CHANNELS, item.channel), None, None, ['%s.%s' % (CHANNELS, item.channel)]) except ImportError: exec("import " + CHANNELS + "." + item.channel + " as channel") logger.info("Running channel %s | %s" % (channel.__name__, channel.__file__)) # Special play action if item.action == "play": #define la info para trakt try: from core import trakt_tools trakt_tools.set_trakt_info(item) except: pass logger.info("item.action=%s" % item.action.upper()) # logger.debug("item_toPlay: " + "\n" + item.tostring('\n')) # First checks if channel has a "play" function if hasattr(channel, 'play'): logger.info("Executing channel 'play' method") itemlist = channel.play(item) b_favourite = item.isFavourite # Play should return a list of playable URLS if len(itemlist) > 0 and isinstance(itemlist[0], Item): item = itemlist[0] if b_favourite: item.isFavourite = True platformtools.play_video(item) # Permitir varias calidades desde play en el canal elif len(itemlist) > 0 and isinstance(itemlist[0], list): item.video_urls = itemlist platformtools.play_video(item) # If not, shows user an error message else: platformtools.dialog_ok( config.get_localized_string(20000), config.get_localized_string(60339)) # If player don't have a "play" function, not uses the standard play from platformtools else: logger.info("Executing core 'play' method") platformtools.play_video(item) # Special action for findvideos, where the plugin looks for known urls elif item.action == "findvideos": from core import servertools # First checks if channel has a "findvideos" function if hasattr(channel, 'findvideos'): itemlist = getattr(channel, item.action)(item) itemlist = servertools.filter_servers(itemlist) # If not, uses the generic findvideos function else: logger.info("No channel 'findvideos' method, " "executing core method") itemlist = servertools.find_video_items(item) if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist) from platformcode import subtitletools subtitletools.saveSubtitleName(item) platformtools.render_items(itemlist, item) # Special action for adding a movie to the library elif item.action == "add_pelicula_to_library": from core import videolibrarytools videolibrarytools.add_movie(item) # Special action for adding a serie to the library elif item.action == "add_serie_to_library": from core import videolibrarytools videolibrarytools.add_tvshow(item, channel) # Special action for downloading all episodes from a serie elif item.action == "download_all_episodes": from specials import downloads item.action = item.extra del item.extra downloads.save_download(item) # Special action for searching, first asks for the words then call the "search" function elif item.action == "search": logger.info("item.action=%s" % item.action.upper()) from core import channeltools # last_search = "" # last_search_active = config.get_setting("last_search", "search") # if last_search_active: # try: # current_saved_searches_list = list(config.get_setting("saved_searches_list", "search")) # last_search = current_saved_searches_list[0] # except: # pass # last_search = channeltools.get_channel_setting('Last_searched', 'search', '') if channeltools.get_channel_setting('last_search', 'search'): last_search = channeltools.get_channel_setting( 'Last_searched', 'search', '') else: last_search = '' tecleado = platformtools.dialog_input(last_search) if tecleado is not None: channeltools.set_channel_setting('Last_searched', tecleado, 'search') if 'search' in dir(channel): itemlist = channel.search(item, tecleado) else: from core import support itemlist = support.search(channel, item, tecleado) else: return platformtools.render_items(itemlist, item) # For all other actions else: # import web_pdb; web_pdb.set_trace() logger.info("Executing channel '%s' method" % item.action) itemlist = getattr(channel, item.action)(item) if config.get_setting('trakt_sync'): from core import trakt_tools token_auth = config.get_setting("token_trakt", "trakt") if not token_auth: trakt_tools.auth_trakt() else: import xbmc if not xbmc.getCondVisibility( 'System.HasAddon(script.trakt)' ) and config.get_setting('install_trakt'): trakt_tools.ask_install_script() itemlist = trakt_tools.trakt_check(itemlist) else: config.set_setting('install_trakt', True) platformtools.render_items(itemlist, item) except urllib2.URLError as e: import traceback logger.error(traceback.format_exc()) # Grab inner and third party errors if hasattr(e, 'reason'): logger.error("Reason for the error, code: %s | Reason: %s" % (str(e.reason[0]), str(e.reason[1]))) texto = config.get_localized_string( 30050) # "No se puede conectar con el sitio web" platformtools.dialog_ok(config.get_localized_string(20000), texto) # Grab server response errors elif hasattr(e, 'code'): logger.error("HTTP error code: %d" % e.code) # "El sitio web no funciona correctamente (error http %d)" platformtools.dialog_ok( config.get_localized_string(20000), config.get_localized_string(30051) % e.code) except WebErrorException as e: import traceback from core import scrapertools logger.error(traceback.format_exc()) patron = 'File "' + os.path.join(config.get_runtime_path(), "channels", "").replace("\\", "\\\\") + '([^.]+)\.py"' canal = scrapertools.find_single_match(traceback.format_exc(), patron) platformtools.dialog_ok( config.get_localized_string(59985) + canal, config.get_localized_string(60013) % (e)) except: import traceback from core import scrapertools logger.error(traceback.format_exc()) patron = 'File "' + os.path.join(config.get_runtime_path(), "channels", "").replace("\\", "\\\\") + '([^.]+)\.py"' canal = scrapertools.find_single_match(traceback.format_exc(), patron) try: import xbmc if config.get_platform(True)['num_version'] < 14: log_name = "xbmc.log" else: log_name = "kodi.log" log_message = config.get_localized_string( 50004) + xbmc.translatePath("special://logpath") + log_name except: log_message = "" if canal: if item.url: if platformtools.dialog_yesno( config.get_localized_string(60087) % canal, config.get_localized_string(60014), log_message, nolabel='ok', yeslabel=config.get_localized_string(70739)): run(Item(action="open_browser", url=item.url)) else: platformtools.dialog_ok( config.get_localized_string(60087) % canal, config.get_localized_string(60014), log_message) else: platformtools.dialog_ok(config.get_localized_string(60038), config.get_localized_string(60015), log_message)
# Se ejecuta en cada inicio import xbmc import time # modo adulto: # sistema actual 0: Nunca, 1:Siempre, 2:Solo hasta que se reinicie Kodi # si es == 2 lo desactivamos. if config.get_platform(True)['num_version'] >= 17.0: if not PY3: from lib.alfaresolver import updated, update_now else: from lib.alfaresolver_py3 import updated, update_now if not updated(): update_now() if config.get_setting("adult_mode") == 2: config.set_setting("adult_mode", 0) update_wait = [0, 10000, 20000, 30000, 60000] wait = update_wait[int(config.get_setting("update_wait", "videolibrary"))] if wait > 0: xbmc.sleep(wait) # Verificar quick-fixes al abrirse Kodi, y dejarlo corriendo como Thread from platformcode import updater updater.check_addon_init() # Copia Custom code a las carpetas de Alfa desde la zona de Userdata from platformcode import custom_code custom_code.init() # Identifica la dirección Proxy y la lista de alternativas
def start(itemlist, item): ''' Metodo principal desde donde se reproduce automaticamente los enlaces - En caso la opcion de personalizar activa utilizara las opciones definidas por el usuario. - En caso contrario intentara reproducir cualquier enlace que cuente con el idioma preferido. :param itemlist: list (lista de items listos para reproducir, o sea con action='play') :param item: item (el item principal del canal) :return: intenta autoreproducir, en caso de fallar devuelve el itemlist que recibio en un principio ''' logger.info() global PLAYED global autoplay_node PLAYED = False base_item = item if not config.is_xbmc(): #platformtools.dialog_notification('AutoPlay ERROR', 'Sólo disponible para XBMC/Kodi') return itemlist if not autoplay_node: # Obtiene el nodo AUTOPLAY desde el json autoplay_node = jsontools.get_node_from_file('autoplay', 'AUTOPLAY') channel_id = item.channel if item.channel == 'videolibrary': autoplay_node = jsontools.get_node_from_file('autoplay', 'AUTOPLAY') channel_id = item.contentChannel try: active = autoplay_node['status'] except: active = is_active(item.channel) if not channel_id in autoplay_node or not active: return itemlist # Agrega servidores y calidades que no estaban listados a autoplay_node new_options = check_value(channel_id, itemlist) # Obtiene el nodo del canal desde autoplay_node channel_node = autoplay_node.get(channel_id, {}) # Obtiene los ajustes des autoplay para este canal settings_node = channel_node.get('settings', {}) if get_setting('autoplay') or settings_node['active']: url_list_valid = [] autoplay_list = [] autoplay_b = [] favorite_langs = [] favorite_servers = [] favorite_quality = [] #2nd lang, vemos si se quiere o no filtrar status_language = config.get_setting("filter_languages", channel_id) # Guarda el valor actual de "Accion y Player Mode" en preferencias user_config_setting_action = config.get_setting("default_action") user_config_setting_player = config.get_setting("player_mode") # Habilita la accion "Ver en calidad alta" (si el servidor devuelve más de una calidad p.e. gdrive) if user_config_setting_action != 2: config.set_setting("default_action", 2) if user_config_setting_player != 0: config.set_setting("player_mode", 0) # Informa que AutoPlay esta activo #platformtools.dialog_notification('AutoPlay Activo', '', sound=False) # Prioridades a la hora de ordenar itemlist: # 0: Servidores y calidades # 1: Calidades y servidores # 2: Solo servidores # 3: Solo calidades # 4: No ordenar if (settings_node['custom_servers'] and settings_node['custom_quality']) or get_setting('autoplay'): priority = settings_node[ 'priority'] # 0: Servidores y calidades o 1: Calidades y servidores elif settings_node['custom_servers']: priority = 2 # Solo servidores elif settings_node['custom_quality']: priority = 3 # Solo calidades else: priority = 4 # No ordenar # Obtiene las listas servidores, calidades disponibles desde el nodo del json de AutoPlay server_list = channel_node.get('servers', []) for server in server_list: server = server.lower() quality_list = channel_node.get('quality', []) # Si no se definen calidades la se asigna default como calidad unica if len(quality_list) == 0: quality_list = ['default'] # Se guardan los textos de cada servidor y calidad en listas p.e. favorite_servers = ['verystream', 'openload', # 'streamcloud'] for num in range(1, 4): favorite_servers.append( channel_node['servers'][settings_node['server_%s' % num]].lower()) favorite_quality.append( channel_node['quality'][settings_node['quality_%s' % num]]) # Se filtran los enlaces de itemlist y que se correspondan con los valores de autoplay for n, item in enumerate(itemlist): autoplay_elem = dict() b_dict = dict() # Comprobamos q se trata de un item de video if 'server' not in item: continue #2nd lang lista idiomas if item.language not in favorite_langs: favorite_langs.append(item.language) # Agrega la opcion configurar AutoPlay al menu contextual if 'context' not in item: item.context = list() if not [x for x in context if x['action'] == 'autoplay_config']: item.context.append({ "title": config.get_localized_string(60071), "action": "autoplay_config", "channel": "autoplay", "from_channel": channel_id }) # Si no tiene calidad definida le asigna calidad 'default' if item.quality == '': item.quality = 'default' # Se crea la lista para configuracion personalizada if priority < 2: # 0: Servidores y calidades o 1: Calidades y servidores # si el servidor y la calidad no se encuentran en las listas de favoritos o la url esta repetida, # descartamos el item if item.server.lower() not in favorite_servers or item.quality not in favorite_quality \ or item.url in url_list_valid: item.type_b = True b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_lang"] = favorite_langs.index( item.language) autoplay_elem["indice_server"] = favorite_servers.index( item.server.lower()) autoplay_elem["indice_quality"] = favorite_quality.index( item.quality) elif priority == 2: # Solo servidores # si el servidor no se encuentra en la lista de favoritos o la url esta repetida, # descartamos el item if item.server.lower( ) not in favorite_servers or item.url in url_list_valid: item.type_b = True b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_lang"] = favorite_langs.index( item.language) autoplay_elem["indice_server"] = favorite_servers.index( item.server.lower()) elif priority == 3: # Solo calidades # si la calidad no se encuentra en la lista de favoritos o la url esta repetida, # descartamos el item if item.quality not in favorite_quality or item.url in url_list_valid: item.type_b = True b_dict['videoitem'] = item autoplay_b.append(b_dict) continue autoplay_elem["indice_lang"] = favorite_langs.index( item.language) autoplay_elem["indice_quality"] = favorite_quality.index( item.quality) else: # No ordenar # si la url esta repetida, descartamos el item if item.url in url_list_valid: continue # Si el item llega hasta aqui lo añadimos al listado de urls validas y a autoplay_list url_list_valid.append(item.url) item.plan_b = True autoplay_elem['videoitem'] = item # autoplay_elem['server'] = item.server # autoplay_elem['quality'] = item.quality autoplay_list.append(autoplay_elem) # Ordenamos segun la prioridad if priority == 0: # Servidores y calidades autoplay_list.sort(key=lambda orden: (orden['indice_lang'], orden[ 'indice_server'], orden['indice_quality'])) elif priority == 1: # Calidades y servidores autoplay_list.sort(key=lambda orden: (orden['indice_lang'], orden[ 'indice_quality'], orden['indice_server'])) elif priority == 2: # Solo servidores autoplay_list.sort(key=lambda orden: (orden['indice_lang'], orden['indice_server'])) elif priority == 3: # Solo calidades autoplay_list.sort(key=lambda orden: (orden['indice_lang'], orden['indice_quality'])) # Se prepara el plan b, en caso de estar activo se agregan los elementos no favoritos al final try: plan_b = settings_node['plan_b'] except: plan_b = True text_b = '' if plan_b: autoplay_list.extend(autoplay_b) # Si hay elementos en la lista de autoplay se intenta reproducir cada elemento, hasta encontrar uno # funcional o fallen todos if autoplay_list or (plan_b and autoplay_b): #played = False max_intentos = 5 max_intentos_servers = {} # Si se esta reproduciendo algo detiene la reproduccion if platformtools.is_playing(): platformtools.stop_video() for autoplay_elem in autoplay_list: play_item = Item # Si no es un elemento favorito si agrega el texto plan b if autoplay_elem['videoitem'].type_b: text_b = '(Plan B)' if not platformtools.is_playing() and not PLAYED: videoitem = autoplay_elem['videoitem'] if videoitem.server.lower() not in max_intentos_servers: max_intentos_servers[ videoitem.server.lower()] = max_intentos # Si se han alcanzado el numero maximo de intentos de este servidor saltamos al siguiente if max_intentos_servers[videoitem.server.lower()] == 0: continue lang = " " if hasattr(videoitem, 'language') and videoitem.language != "": lang = " '%s' " % videoitem.language platformtools.dialog_notification( "AutoPlay %s" % text_b, "%s%s%s" % (videoitem.server.upper(), lang, videoitem.quality.upper()), sound=False) # TODO videoitem.server es el id del server, pero podria no ser el nombre!!! # Intenta reproducir los enlaces # Si el canal tiene metodo play propio lo utiliza try: channel = __import__('channels.%s' % channel_id, None, None, ["channels.%s" % channel_id]) except: channel = __import__('specials.%s' % channel_id, None, None, ["specials.%s" % channel_id]) if hasattr(channel, 'play'): resolved_item = getattr(channel, 'play')(videoitem) if len(resolved_item) > 0: if isinstance(resolved_item[0], list): videoitem.video_urls = resolved_item else: videoitem = resolved_item[0] # Si no directamente reproduce y marca como visto # Verifica si el item viene de la videoteca try: if base_item.contentChannel == 'videolibrary': # Marca como visto from platformcode import xbmc_videolibrary xbmc_videolibrary.mark_auto_as_watched(base_item) # Rellena el video con los datos del item principal y reproduce play_item = base_item.clone(url=videoitem) platformtools.play_video(play_item.url, autoplay=True) else: # Si no viene de la videoteca solo reproduce platformtools.play_video(videoitem, autoplay=True) except: pass sleep(3) try: if platformtools.is_playing(): PLAYED = True break except: logger.debug(str(len(autoplay_list))) # Si hemos llegado hasta aqui es por q no se ha podido reproducir max_intentos_servers[videoitem.server.lower()] -= 1 # Si se han alcanzado el numero maximo de intentos de este servidor # preguntar si queremos seguir probando o lo ignoramos if max_intentos_servers[videoitem.server.lower()] == 0: text = config.get_localized_string( 60072) % videoitem.server.upper() if not platformtools.dialog_yesno( "AutoPlay", text, config.get_localized_string(60073)): max_intentos_servers[ videoitem.server.lower()] = max_intentos # Si no quedan elementos en la lista se informa if autoplay_elem == autoplay_list[-1]: platformtools.dialog_notification( 'AutoPlay', config.get_localized_string(60072) % videoitem.server.upper()) else: platformtools.dialog_notification( config.get_localized_string(60074), config.get_localized_string(60075)) if new_options: platformtools.dialog_notification( "AutoPlay", config.get_localized_string(60076), sound=False) # Restaura si es necesario el valor previo de "Accion y Player Mode" en preferencias if user_config_setting_action != 2: config.set_setting("default_action", user_config_setting_action) if user_config_setting_player != 0: config.set_setting("player_mode", user_config_setting_player) return itemlist
def update(path, p_dialog, i, t, serie, overwrite): logger.info("Actualizando " + path) from core import filetools from core import channeltools, videolibrarytools from platformcode import platformtools from channels import videolibrary from lib import generictools if config.is_xbmc(): from platformcode import xbmc_videolibrary insertados_total = 0 head_nfo, it = videolibrarytools.read_nfo(path + '/tvshow.nfo') category = serie.category # logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) )) for channel, url in list(serie.library_urls.items()): serie.channel = channel serie.url = url ###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial try: head_nfo, it = videolibrarytools.read_nfo( path + '/tvshow.nfo') #Refresca el .nfo para recoger actualizaciones if not it: logger.error('.nfo erroneo en ' + str(path)) continue if it.emergency_urls: serie.emergency_urls = it.emergency_urls serie.category = category serie, it, overwrite = generictools.redirect_clone_newpct1( serie, head_nfo, it, path, overwrite) except: logger.error(traceback.format_exc()) channel_enabled = channeltools.is_enabled(serie.channel) if channel_enabled: heading = config.get_localized_string(60389) p_dialog.update( int(math.ceil((i + 1) * t)), heading, "%s: %s" % (serie.contentSerieName, serie.channel.capitalize())) try: pathchannels = filetools.join(config.get_runtime_path(), "channels", serie.channel + '.py') logger.info("Cargando canal: " + pathchannels) if serie.library_filter_show: serie.show = serie.library_filter_show.get( serie.channel, serie.contentSerieName) obj = __import__('channels.%s' % serie.channel, fromlist=["channels.%s" % serie.channel]) itemlist = getattr(obj, 'episodios')( serie) #... se procesa Episodios para ese canal try: if int(overwrite) == 3: # Sobrescribir todos los archivos (tvshow.nfo, 1x01.nfo, 1x01 [canal].json, 1x01.strm, etc...) insertados, sobreescritos, fallidos, notusedpath = videolibrarytools.save_tvshow( serie, itemlist) #serie= videolibrary.check_season_playcount(serie, serie.contentSeason) #if filetools.write(path + '/tvshow.nfo', head_nfo + it.tojson()): # serie.infoLabels['playcount'] = serie.playcount else: insertados, sobreescritos, fallidos = videolibrarytools.save_episodes( path, itemlist, serie, silent=True, overwrite=overwrite) #it = videolibrary.check_season_playcount(it, it.contentSeason) #if filetools.write(path + '/tvshow.nfo', head_nfo + it.tojson()): # serie.infoLabels['playcount'] = serie.playcount insertados_total += insertados except Exception as ex: logger.error("Error al guardar los capitulos de la serie") template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) logger.error(traceback.format_exc()) except Exception as ex: logger.error("Error al obtener los episodios de: %s" % serie.show) template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) logger.error(traceback.format_exc()) #Si el canal lo permite, se comienza el proceso de descarga de los nuevos episodios descargados serie.channel = generictools.verify_channel(serie.channel) if insertados > 0 and config.get_setting( 'auto_download_new', serie.channel, default=False): config.set_setting( "search_new_content", 1, "videolibrary") # Escaneamos a final todas la series serie.sub_action = 'auto' serie.category = itemlist[0].category from channels import downloads downloads.save_download(serie, silent=True) if serie.sub_action: del serie.sub_action else: logger.debug("Canal %s no activo no se actualiza" % serie.channel) #Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa try: if config.is_xbmc() and not config.get_setting( 'cleanlibrary', 'videolibrary', default=False): #Si es Kodi, lo hacemos xbmc_videolibrary.mark_content_as_watched_on_alfa(path + '/tvshow.nfo') except: logger.error(traceback.format_exc()) return insertados_total > 0
def onClick(self, id): # Valores por defecto if id == 10006: if self.custom_button is not None: if self.custom_button["close"]: self.close() if '.' in self.callback: package, self.callback = self.callback.rsplit('.', 1) else: package = '%s.%s' % (self.ch_type, self.channel) try: cb_channel = __import__(package, None, None, [package]) except ImportError: logger.error('Imposible importar %s' % package) else: self.return_value = getattr( cb_channel, self.custom_button['function'])(self.item, self.values) if not self.custom_button["close"]: if isinstance(self.return_value, dict) and "label" in self.return_value: self.getControl(10006).setLabel( self.return_value['label']) for c in self.list_controls: if c["type"] == "text": c["control"].setText(self.values[c["id"]]) if c["type"] == "bool": c["control"].setSelected(self.values[c["id"]]) if c["type"] == "list": c["label"].setLabel( c["lvalues"][self.values[c["id"]]]) self.evaluate_conditions() self.dispose_controls(self.index, force=True) else: for c in self.list_controls: if c["type"] == "text": c["control"].setText(c["default"]) self.values[c["id"]] = c["default"] if c["type"] == "bool": c["control"].setSelected(c["default"]) self.values[c["id"]] = c["default"] if c["type"] == "list": c["label"].setLabel(c["lvalues"][c["default"]]) self.values[c["id"]] = c["default"] self.evaluate_conditions() self.dispose_controls(self.index, force=True) self.check_default() self.check_ok() # Boton Cancelar y [X] if id == 10003 or id == 10005: self.close() # Boton Aceptar if id == 10004: self.close() if self.callback and '.' in self.callback: package, self.callback = self.callback.rsplit('.', 1) else: package = '%s.%s' % (self.ch_type, self.channel) cb_channel = None try: cb_channel = __import__(package, None, None, [package]) except ImportError: logger.error('Imposible importar %s' % package) if self.callback: # Si existe una funcion callback la invocamos ... self.return_value = getattr(cb_channel, self.callback)(self.item, self.values) else: # si no, probamos si en el canal existe una funcion 'cb_validate_config' ... try: self.return_value = getattr( cb_channel, 'cb_validate_config')(self.item, self.values) except AttributeError: # ... si tampoco existe 'cb_validate_config'... for v in self.values: config.set_setting(v, self.values[v], **self.kwargs) # Controles de ajustes, si se cambia el valor de un ajuste, cambiamos el valor guardado en el diccionario de # valores # Obtenemos el control sobre el que se ha echo click # control = self.getControl(id) # Lo buscamos en el listado de controles for cont in self.list_controls: # Si el control es un "downBtn" o "upBtn" son los botones del "list" # en este caso cambiamos el valor del list if cont["type"] == "list" and (cont["downBtn"].getId() == id or cont["upBtn"].getId() == id): # Para bajar una posicion if cont["downBtn"].getId() == id: index = cont["lvalues"].index(cont["label"].getLabel()) if index > 0: cont["label"].setLabel(cont["lvalues"][index - 1]) # Para subir una posicion elif cont["upBtn"].getId() == id: index = cont["lvalues"].index(cont["label"].getLabel()) if index < len(cont["lvalues"]) - 1: cont["label"].setLabel(cont["lvalues"][index + 1]) # Guardamos el nuevo valor en el diccionario de valores self.values[cont["id"]] = cont["lvalues"].index( cont["label"].getLabel()) # Si esl control es un "bool", guardamos el nuevo valor True/False if cont["type"] == "bool" and cont["control"].getId() == id: self.values[cont["id"]] = bool(cont["control"].isSelected()) # Si esl control es un "text", guardamos el nuevo valor if cont["type"] == "text" and cont["control"].getId() == id: # Versiones antiguas requieren abrir el teclado manualmente if xbmcgui.ControlEdit == ControlEdit: import xbmc keyboard = xbmc.Keyboard(cont["control"].getText(), cont["control"].getLabel(), cont["control"].isPassword) keyboard.setHiddenInput(cont["control"].isPassword) keyboard.doModal() if keyboard.isConfirmed(): cont["control"].setText(keyboard.getText()) self.values[cont["id"]] = cont["control"].getText() self.evaluate_conditions() self.dispose_controls(self.index, force=True) self.check_default() self.check_ok()
def channel_search(item): logger.info(item) start = time.time() searching = list() searching_titles = list() results = list() valid = list() ch_list = dict() mode = item.mode max_results = 10 if item.infoLabels['title']: item.text = item.infoLabels['title'] searched_id = item.infoLabels['tmdb_id'] channel_list, channel_titles = get_channels(item) searching += channel_list searching_titles += channel_titles cnt = 0 progress = platformtools.dialog_progress( config.get_localized_string(30993) % item.title, config.get_localized_string(70744) % len(channel_list), str(searching_titles)) config.set_setting('tmdb_active', False) with futures.ThreadPoolExecutor(max_workers=set_workers()) as executor: c_results = [ executor.submit(get_channel_results, ch, item) for ch in channel_list ] for res in futures.as_completed(c_results): cnt += 1 finished = res.result()[0] if res.result()[1]: ch_list[res.result()[0]] = res.result()[1] if progress.iscanceled(): break if finished in searching: searching_titles.remove( searching_titles[searching.index(finished)]) searching.remove(finished) progress.update( old_div((cnt * 100), len(channel_list)), config.get_localized_string(70744) % str(len(channel_list) - cnt), str(searching_titles)) progress.close() cnt = 0 progress = platformtools.dialog_progress( config.get_localized_string(30993) % item.title, config.get_localized_string(60295), config.get_localized_string(60293)) config.set_setting('tmdb_active', True) res_count = 0 for key, value in ch_list.items(): ch_name = channel_titles[channel_list.index(key)] grouped = list() cnt += 1 progress.update(old_div((cnt * 100), len(ch_list)), config.get_localized_string(60295), config.get_localized_string(60293)) if len(value) <= max_results and item.mode != 'all': if len(value) == 1: if not value[0].action or config.get_localized_string( 70006).lower() in value[0].title.lower(): continue tmdb.set_infoLabels_itemlist(value, True, forced=True) for elem in value: if not elem.infoLabels.get('year', ""): elem.infoLabels['year'] = '-' tmdb.set_infoLabels_item(elem, True) if elem.infoLabels['tmdb_id'] == searched_id: elem.from_channel = key if not config.get_setting('unify'): elem.title += ' [%s]' % key valid.append(elem) for it in value: if it.channel == item.channel: it.channel = key if it in valid: continue if mode == 'all' or (it.contentType and mode == it.contentType): if config.get_setting('result_mode') != 0: if config.get_localized_string(30992) not in it.title: it.title += typo(ch_name, '_ [] color kod bold') results.append(it) else: grouped.append(it) elif (mode == 'movie' and it.contentTitle) or (mode == 'tvshow' and (it.contentSerieName or it.show)): grouped.append(it) else: continue if not grouped: continue # to_temp[key] = grouped if config.get_setting('result_mode') == 0: if not config.get_setting('unify'): title = typo(ch_name, 'bold') + typo(str(len(grouped)), '_ [] color kod bold') else: title = typo( '%s %s' % (len(grouped), config.get_localized_string(70695)), 'bold') res_count += len(grouped) plot = '' for it in grouped: plot += it.title + '\n' ch_thumb = channeltools.get_channel_parameters(key)['thumbnail'] results.append( Item(channel='search', title=title, action='get_from_temp', thumbnail=ch_thumb, itemlist=[ris.tourl() for ris in grouped], plot=plot, page=1)) # send_to_temp(to_temp) config.set_setting('tmdb_active', True) if item.mode == 'all': if config.get_setting('result_mode', 'search') != 0: res_count = len(results) results = sorted(results, key=lambda it: it.title) results_statistic = config.get_localized_string(59972) % ( item.title, res_count, time.time() - start) results.insert(0, Item(title=typo(results_statistic, 'color kod bold'))) # logger.debug(results_statistic) return valid + results
def run(item=None): logger.info() if not item: # Extract item from sys.argv if sys.argv[2]: item = Item().fromurl(sys.argv[2]) # If no item, this is mainlist else: if config.get_setting("start_page"): if not config.get_setting("custom_start"): category = config.get_setting("category").lower() item = Item(channel="news", action="novedades", extra=category, mode='silent') else: from channels import side_menu item = Item() item = side_menu.check_user_home(item) item.start = True else: item = Item(channel="channelselector", action="getmainlist", viewmode="movie") logger.info(item.tostring()) try: # If item has no action, stops here if item.action == "": logger.info("Item sin accion") return # Action for main menu in channelselector elif item.action == "getmainlist": import channelselector itemlist = channelselector.getmainlist() platformtools.render_items(itemlist, item) # Action for channel types on channelselector: movies, series, etc. elif item.action == "getchanneltypes": import channelselector itemlist = channelselector.getchanneltypes() platformtools.render_items(itemlist, item) # Action for channel listing on channelselector elif item.action == "filterchannels": import channelselector itemlist = channelselector.filterchannels(item.channel_type) platformtools.render_items(itemlist, item) # Special action for playing a video from the library elif item.action == "play_from_library": play_from_library(item) return elif item.action == "keymap": from platformcode import keymaptools if item.open: return keymaptools.open_shortcut_menu() else: return keymaptools.set_key() elif item.action == "script": from core import tmdb if tmdb.drop_bd(): platformtools.dialog_notification("Alfa", "caché eliminada", time=2000, sound=False) # Action in certain channel specified in "action" and "channel" parameters else: # Entry point for a channel is the "mainlist" action, so here we check parental control if item.action == "mainlist": # Parental control # If it is an adult channel, and user has configured pin, asks for it if channeltools.is_adult(item.channel) and config.get_setting( "adult_request_password"): tecleado = platformtools.dialog_input( "", "Contraseña para canales de adultos", True) if tecleado is None or tecleado != config.get_setting( "adult_password"): return # # Actualiza el canal individual # if (item.action == "mainlist" and item.channel != "channelselector" and # config.get_setting("check_for_channel_updates") == True): # from core import updater # updater.update_channel(item.channel) # Checks if channel exists channel_file = os.path.join(config.get_runtime_path(), 'channels', item.channel + ".py") logger.info("channel_file=%s" % channel_file) channel = None if os.path.exists(channel_file): try: channel = __import__('channels.%s' % item.channel, None, None, ["channels.%s" % item.channel]) except ImportError: exec "import channels." + item.channel + " as channel" logger.info("Running channel %s | %s" % (channel.__name__, channel.__file__)) # Special play action if item.action == "play": #define la info para trakt try: trakt_tools.set_trakt_info(item) except: pass logger.info("item.action=%s" % item.action.upper()) # logger.debug("item_toPlay: " + "\n" + item.tostring('\n')) # First checks if channel has a "play" function if hasattr(channel, 'play'): logger.info("Executing channel 'play' method") itemlist = channel.play(item) b_favourite = item.isFavourite # Play should return a list of playable URLS if len(itemlist) > 0 and isinstance(itemlist[0], Item): item = itemlist[0] if b_favourite: item.isFavourite = True platformtools.play_video(item) # Permitir varias calidades desde play en el canal elif len(itemlist) > 0 and isinstance(itemlist[0], list): item.video_urls = itemlist platformtools.play_video(item) # If not, shows user an error message else: platformtools.dialog_ok("alfa", "No hay nada para reproducir") # If player don't have a "play" function, not uses the standard play from platformtools else: logger.info("Executing core 'play' method") platformtools.play_video(item) # Special action for findvideos, where the plugin looks for known urls elif item.action == "findvideos": # First checks if channel has a "findvideos" function if hasattr(channel, 'findvideos'): itemlist = getattr(channel, item.action)(item) itemlist = servertools.filter_servers(itemlist) # If not, uses the generic findvideos function else: logger.info("No channel 'findvideos' method, " "executing core method") itemlist = servertools.find_video_items(item) if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist) from platformcode import subtitletools subtitletools.saveSubtitleName(item) platformtools.render_items(itemlist, item) # Special action for adding a movie to the library elif item.action == "add_pelicula_to_library": videolibrarytools.add_movie(item) # Special action for adding a serie to the library elif item.action == "add_serie_to_library": videolibrarytools.add_tvshow(item, channel) # Special action for downloading all episodes from a serie elif item.action == "download_all_episodes": from channels import downloads item.action = item.extra del item.extra downloads.save_download(item) # Special action for searching, first asks for the words then call the "search" function elif item.action == "search": logger.info("item.action=%s" % item.action.upper()) last_search = "" last_search_active = config.get_setting( "last_search", "search") if last_search_active: try: current_saved_searches_list = list( config.get_setting("saved_searches_list", "search")) last_search = current_saved_searches_list[0] except: pass tecleado = platformtools.dialog_input(last_search) if tecleado is not None: if last_search_active and not tecleado.startswith("http"): from channels import search search.save_search(tecleado) itemlist = channel.search(item, tecleado) else: return platformtools.render_items(itemlist, item) # For all other actions else: logger.info("Executing channel '%s' method" % item.action) itemlist = getattr(channel, item.action)(item) if config.get_setting('trakt_sync'): token_auth = config.get_setting("token_trakt", "trakt") if not token_auth: trakt_tools.auth_trakt() else: import xbmc if not xbmc.getCondVisibility( 'System.HasAddon(script.trakt)' ) and config.get_setting('install_trakt'): trakt_tools.ask_install_script() itemlist = trakt_tools.trakt_check(itemlist) else: config.set_setting('install_trakt', True) platformtools.render_items(itemlist, item) except urllib2.URLError, e: import traceback logger.error(traceback.format_exc()) # Grab inner and third party errors if hasattr(e, 'reason'): logger.error("Razon del error, codigo: %s | Razon: %s" % (str(e.reason[0]), str(e.reason[1]))) texto = config.get_localized_string( 30050) # "No se puede conectar con el sitio web" platformtools.dialog_ok("alfa", texto) # Grab server response errors elif hasattr(e, 'code'): logger.error("Codigo de error HTTP : %d" % e.code) # "El sitio web no funciona correctamente (error http %d)" platformtools.dialog_ok( "alfa", config.get_localized_string(30051) % e.code)