def __get_data(self, item, global_filter_lang_id): dict_filtered_shows = filetools.get_node_from_data_json(item.channel, TAG_TVSHOW_FILTER) tvshow = item.show.lower().strip() global_filter_language = config.get_setting(global_filter_lang_id, item.channel) if tvshow in dict_filtered_shows.keys(): self.result = ResultFilter({TAG_ACTIVE: dict_filtered_shows[tvshow][TAG_ACTIVE], TAG_LANGUAGE: dict_filtered_shows[tvshow][TAG_LANGUAGE], TAG_QUALITY_ALLOWED: dict_filtered_shows[tvshow][TAG_QUALITY_ALLOWED]}) # opcion general "no filtrar" elif global_filter_language != 0: from core import channeltools list_controls, dict_settings = channeltools.get_channel_controls_settings(item.channel) for control in list_controls: if control["id"] == global_filter_lang_id: try: language = control["lvalues"][global_filter_language] # logger.debug("language %s" % language) except: logger.error("No se ha encontrado el valor asociado al codigo '%s': %s" % (global_filter_lang_id, global_filter_language)) break self.result = ResultFilter({TAG_ACTIVE: True, TAG_LANGUAGE: language, TAG_QUALITY_ALLOWED: []}) break
def delete(item, dict_values): logger.info() if item: dict_series = filetools.get_node_from_data_json( item.from_channel, TAG_TVSHOW_FILTER) tvshow = item.show.strip().lower() heading = "¿Está seguro que desea eliminar el filtro?" line1 = "Pulse 'Si' para eliminar el filtro de [COLOR %s]%s[/COLOR], pulse 'No' o cierre la ventana para " \ "no hacer nada." % (COLOR.get("selected", "auto"), item.show.strip()) if platformtools.dialog_yesno(heading, line1) == 1: lang_selected = dict_series.get(tvshow, {}).get(TAG_LANGUAGE, "") dict_series.pop(tvshow, None) fname, json_data = filetools.update_json_data( dict_series, item.from_channel, TAG_TVSHOW_FILTER) result = filetools.write(fname, json_data) sound = False if result: message = "FILTRO ELIMINADO" else: message = "Error al guardar en disco" sound = True heading = "%s [%s]" % (item.show.strip(), lang_selected) platformtools.dialog_notification(heading, message, sound=sound) if item.action in ["findvideos", "play"]: platformtools.itemlist_refresh()
def delete_from_context(item): """ Elimina el filtro a través del menú contextual @param item: item @type item: item """ logger.info() # venimos desde get_links y no se ha obtenido ningún resultado, en menu contextual y damos a borrar if item.to_channel != "": item.from_channel = item.to_channel dict_series = filetools.get_node_from_data_json(item.from_channel, TAG_TVSHOW_FILTER) tvshow = item.show.strip().lower() lang_selected = dict_series.get(tvshow, {}).get(TAG_LANGUAGE, "") dict_series.pop(tvshow, None) fname, json_data = filetools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER) result = filetools.write(fname, json_data) sound = False if result: message = "FILTRO ELIMINADO" else: message = "Error al guardar en disco" sound = True heading = "%s [%s]" % (item.show.strip(), lang_selected) platformtools.dialog_notification(heading, message, sound=sound) if item.from_action in ["findvideos", "play", "no_filter"]: # 'no_filter' es el mismo caso que L#601 platformtools.itemlist_refresh()
def save_from_context(item): """ Salva el filtro a través del menú contextual @param item: item @type item: item """ logger.info() dict_series = filetools.get_node_from_data_json(item.from_channel, TAG_TVSHOW_FILTER) tvshow = item.show.strip().lower() dict_filter = {TAG_NAME: item.show, TAG_ACTIVE: True, TAG_LANGUAGE: item.language, TAG_QUALITY_ALLOWED: []} dict_series[tvshow] = dict_filter fname, json_data = filetools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER) result = filetools.write(fname, json_data) sound = False if result: message = "FILTRO GUARDADO" else: message = "Error al guardar en disco" sound = True heading = "%s [%s]" % (item.show.strip(), item.language) platformtools.dialog_notification(heading, message, sound=sound) if item.from_action in ["findvideos", "play"]: platformtools.itemlist_refresh()
def mainlist(channel, list_language, list_quality): """ Muestra una lista de las series filtradas @param channel: nombre del canal para obtener las series filtradas @type channel: str @param list_language: lista de idiomas del canal @type list_language: list[str] @param list_quality: lista de calidades del canal @type list_quality: list[str] @return: lista de Item @rtype: list[Item] """ logger.info() itemlist = [] dict_series = filetools.get_node_from_data_json(channel, TAG_TVSHOW_FILTER) idx = 0 for tvshow in sorted(dict_series): if idx % 2 == 0: if dict_series[tvshow][TAG_ACTIVE]: tag_color = COLOR.get("striped_even_active", "auto") else: tag_color = COLOR.get("striped_even_inactive", "auto") else: if dict_series[tvshow][TAG_ACTIVE]: tag_color = COLOR.get("striped_odd_active", "auto") else: tag_color = COLOR.get("striped_odd_inactive", "auto") idx += 1 name = dict_series.get(tvshow, {}).get(TAG_NAME, tvshow) activo = " (desactivado)" if dict_series[tvshow][TAG_ACTIVE]: activo = "" title = "Configurar [COLOR %s][%s][/COLOR]%s" % (tag_color, name, activo) itemlist.append( Item(channel=__channel__, action="config_item", title=title, show=name, list_language=list_language, list_quality=list_quality, from_channel=channel)) if len(itemlist) == 0: itemlist.append( Item(channel=channel, action="mainlist", title="No existen filtros, busca una serie y " "pulsa en menú contextual 'FILTRO: Configurar'")) return itemlist
def save(item, dict_data_saved): """ Guarda los valores configurados en la ventana @param item: item @type item: Item @param dict_data_saved: diccionario con los datos salvados @type dict_data_saved: dict """ logger.info() if item and dict_data_saved: logger.debug('item: %s\ndatos: %s' % (item.tostring(), dict_data_saved)) if item.from_channel == "biblioteca": item.from_channel = item.contentChannel dict_series = filetools.get_node_from_data_json( item.from_channel, TAG_TVSHOW_FILTER) tvshow = item.show.strip().lower() logger.info("Se actualiza los datos") list_quality = [] for _id, value in dict_data_saved.items(): if _id in item.list_quality and value: list_quality.append(_id.lower()) lang_selected = item.list_language[dict_data_saved[TAG_LANGUAGE]] dict_filter = { TAG_NAME: item.show, TAG_ACTIVE: dict_data_saved.get(TAG_ACTIVE, True), TAG_LANGUAGE: lang_selected, TAG_QUALITY_ALLOWED: list_quality } dict_series[tvshow] = dict_filter fname, json_data = filetools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER) result = filetools.write(fname, json_data) sound = False if result: message = "FILTRO GUARDADO" else: message = "Error al guardar en disco" sound = True heading = "%s [%s]" % (item.show.strip(), lang_selected) platformtools.dialog_notification(heading, message, sound=sound) if item.from_action in ["findvideos", "play"]: platformtools.itemlist_refresh()
def upgrade_version(channel, list_quality): if channel in ['seriesblanco', 'seriesdanko', 'seriespapaya']: if not config.get_setting("var_temp_filtertools_v2_%s" % channel): dict_series = filetools.get_node_from_data_json(channel, TAG_TVSHOW_FILTER) if dict_series: # Informamos al usuario platformtools.dialog_notification("Espere por favor", "Actualizando filtros al nuevo formato") # Hacemos backup del fichero original = filetools.join(config.get_data_path(), "settings_channels", channel + "_data.json") backup = filetools.join(config.get_data_path(), "settings_channels", channel + "_data.bk_ft") filetools.copy(original, backup) try: for serie in dict_series.keys(): logger.debug("serie %s" % serie) quality_not_allowed = dict_series[serie]["quality_not_allowed"] # Eliminamos el nodo antiguo dict_series[serie].pop("quality_not_allowed", None) # ponemos en minúsculas quality_allowed = [x.lower() for x in list_quality] for quality in quality_not_allowed: if quality in quality_allowed: quality_allowed.remove(quality) # añadimos el nuevo nodo con los datos correctos dict_series[serie][TAG_QUALITY_ALLOWED] = quality_allowed fname, json_data = filetools.update_json_data(dict_series, channel, TAG_TVSHOW_FILTER) result = filetools.write(fname, json_data) except: logger.error("Se ha producido un error al convertir los filtros") logger.error("Debe suministrar el fichero '%s'" % backup) result = False if result: message = "Conversión correcta" config.set_setting("var_temp_filtertools_v2_%s" % channel, "s") else: message = "Error, reporte en el foro" heading = "Proceso terminado" platformtools.dialog_notification(heading, message) else: config.set_setting("var_temp_filtertools_v2_%s" % channel, "s")
def config_item(item): """ muestra una serie filtrada para su configuración @param item: item @type item: Item """ logger.info() logger.info("item %s" % item.tostring()) # OBTENEMOS LOS DATOS DEL JSON dict_series = filetools.get_node_from_data_json(item.from_channel, TAG_TVSHOW_FILTER) tvshow = item.show.lower().strip() lang_selected = dict_series.get(tvshow, {}).get(TAG_LANGUAGE, 'Español') list_quality = dict_series.get(tvshow, {}).get( TAG_QUALITY_ALLOWED, [x.lower() for x in item.list_quality]) # logger.info("lang selected {}".format(lang_selected)) # logger.info("list quality {}".format(list_quality)) active = True custom_button = {'visible': False} allow_option = False if item.show.lower().strip() in dict_series: allow_option = True active = dict_series.get(item.show.lower().strip(), {}).get(TAG_ACTIVE, False) custom_button = { 'label': 'Borrar', 'function': 'delete', 'visible': True, 'close': True } list_controls = [] if allow_option: active_control = { "id": "active", "type": "bool", "label": "¿Activar/Desactivar filtro?", "color": "", "default": active, "enabled": allow_option, "visible": allow_option, } list_controls.append(active_control) language_option = { "id": "language", "type": "list", "label": "Idioma", "color": "0xFFee66CC", "default": item.list_language.index(lang_selected), "enabled": True, "visible": True, "lvalues": item.list_language } list_controls.append(language_option) if item.list_quality: list_controls_calidad = [ { "id": "textoCalidad", "type": "label", "label": "Calidad permitida", "color": "0xffC6C384", "enabled": True, "visible": True, }, ] for element in sorted(item.list_quality, key=str.lower): list_controls_calidad.append({ "id": element, "type": "bool", "label": element, "default": (False, True)[element.lower() in list_quality], "enabled": True, "visible": True, }) # concatenamos list_controls con list_controls_calidad list_controls.extend(list_controls_calidad) title = "Filtrado de enlaces para: [COLOR %s]%s[/COLOR]" % (COLOR.get( "selected", "auto"), item.show) platformtools.show_channel_settings(list_controls=list_controls, callback='save', item=item, caption=title, custom_button=custom_button)