def delete(item, dict_values):
    logger.info()

    if item:
        dict_series = jsontools.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)

            result, json_data = jsontools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER)

            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()
Example #2
0
def write_data(channel, show, data):
    # OBTENEMOS LOS DATOS DEL JSON
    dict_series = jsontools.get_node_from_data_json(channel,
                                                    TAG_TVSHOW_RENUMERATE)
    tvshow = show.strip()
    list_season_episode = dict_series.get(tvshow,
                                          {}).get(TAG_SEASON_EPISODE, [])
    logger.debug("data %s" % list_season_episode)

    if data:
        # cambiamos el orden para que se vea en orden descendente y usarse bien en el _data.json
        data.sort(key=lambda el: int(el[0]), reverse=True)
        dict_renumerate = {TAG_SEASON_EPISODE: data}

        dict_series[tvshow] = dict_renumerate
    else:
        # hemos borrado todos los elementos, por lo que se borra la serie del fichero
        dict_series.pop(tvshow, None)

    result, json_data = jsontools.update_json_data(dict_series, channel,
                                                   TAG_TVSHOW_RENUMERATE)

    if result:
        if data:
            message = "FILTRO GUARDADO"
        else:
            message = "FILTRO BORRADO"
    else:
        message = "Error al guardar en disco"

    heading = show.strip()
    platformtools.dialog_notification(heading, message)
Example #3
0
def save(item, dict_data_saved):
    '''
    Guarda los datos de la ventana de configuracion
    
    :param item: item
    :param dict_data_saved: dict  
    :return:
    '''
    logger.info()
    global autoplay_node

    if not autoplay_node:
        # Obtiene el nodo AUTOPLAY desde el json
        autoplay_node = jsontools.get_node_from_data_json(
            'autoplay', 'AUTOPLAY')

    channel_node = autoplay_node.get(item.from_channel)
    config.set_setting("filter_languages", dict_data_saved.pop("language"),
                       item.from_channel)
    channel_node['settings'] = dict_data_saved

    result, json_data = jsontools.update_json_data(autoplay_node, 'autoplay',
                                                   'AUTOPLAY')

    return result
Example #4
0
def mainlist(channel):
    """
    Muestra una lista de las series renumeradas

    :param channel: nombre del canal para obtener las series renumeradas
    :type channel: str
    :return: lista de Item
    :rtype: list[Item]
    """
    logger.info()
    itemlist = []
    dict_series = jsontools.get_node_from_data_json(channel, TAG_TVSHOW_RENUMERATE)

    idx = 0
    for tvshow in sorted(dict_series):
        tag_color = "0xff008000"
        if idx % 2 == 0:
            tag_color = "blue"

        idx += 1
        name = tvshow
        title = "Configurar [COLOR %s][%s][/COLOR]" % (tag_color, name)

        itemlist.append(Item(channel=__channel__, action="config_item", title=title, show=name, from_channel=channel))

    if len(itemlist) == 0:
        itemlist.append(Item(channel=channel, action="mainlist",
                             title="No se han encontrado series, busca una serie y pulsa en menú contextual "
                                   "'RENUMERAR'"))

    return itemlist
Example #5
0
def is_active():
    '''
    Devuelve un booleano q indica si esta activo o no autoplay en el canal desde el que se llama

    :return: True si esta activo autoplay para el canal desde el que se llama, False en caso contrario.
    '''
    logger.info()
    global autoplay_node

    if not config.is_xbmc():
        return False

    if not autoplay_node:
        # Obtiene el nodo AUTOPLAY desde el json
        autoplay_node = jsontools.get_node_from_data_json(
            'autoplay', 'AUTOPLAY')

        # Obtine el canal desde el q se hace la llamada
        import inspect
        module = inspect.getmodule(inspect.currentframe().f_back)
        canal = module.__name__.split('.')[1]
        logger.debug(canal)

        # Obtiene el nodo del canal desde autoplay_node
        channel_node = autoplay_node.get(canal, {})
        # Obtiene los ajustes des autoplay para este canal
        settings_node = channel_node.get('settings', {})

        return settings_node.get('active', False)
    def __get_data(self, item, global_filter_lang_id):

        dict_filtered_shows = jsontools.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_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 = jsontools.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)

    result, json_data = jsontools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER)

    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 = jsontools.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

    result, json_data = jsontools.update_json_data(dict_series, item.from_channel, TAG_TVSHOW_FILTER)

    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()
Example #9
0
def config_item(item):
    """
    muestra una serie renumerada para su configuración

    :param item: item
    :type item: Item
    """
    logger.info("item %s" % item.tostring("\n"))

    dict_series = jsontools.get_node_from_data_json(item.from_channel,
                                                    TAG_TVSHOW_RENUMERATE)
    data = dict_series.get(item.show, {})

    if data:
        data = data.get(TAG_SEASON_EPISODE, [])

        ventana = RenumberWindow(show=item.show,
                                 channel=item.from_channel,
                                 data=data)
        del ventana
    else:
        # tenemos información y devolvemos los datos añadidos para que se muestre en la ventana
        if data:
            return add_season(data)
        # es la primera vez que se añaden datos (usando menú contextual) por lo que no devolvemos nada
        # para evitar error al listar los items
        else:
            data = add_season(data)
            write_data(item.from_channel, item.show, data)
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 = jsontools.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 = jsontools.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

        result, json_data = jsontools.update_json_data(dict_series,
                                                       item.from_channel,
                                                       TAG_TVSHOW_FILTER)

        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()
Example #12
0
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 = jsontools.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

                    result, json_data = jsontools.update_json_data(dict_series, channel, TAG_TVSHOW_FILTER)


                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")
Example #13
0
def numbered_for_tratk(channel, show, season, episode):
    """
    Devuelve la temporada y episodio convertido para que se marque correctamente en tratk.tv

    @param channel: Nombre del canal
    @type channel: str
    @param show: Nombre de la serie a comprobar
    @type show: str
    @param season: Temporada que devuelve el scrapper
    @type season: int
    @param episode: Episodio que devuelve el scrapper
    @type episode: int
    @return: season, episode
    @rtype: int, int
    """
    logger.info()
    show = show.lower()

    new_season = season
    new_episode = episode
    dict_series = jsontools.get_node_from_data_json(channel,
                                                    TAG_TVSHOW_RENUMERATE)

    # ponemos en minusculas el key, ya que previamente hemos hecho lo mismo con show.
    for key in dict_series.keys():
        new_key = key.lower()
        if new_key != key:
            dict_series[new_key] = dict_series[key]
            del dict_series[key]

    if show in dict_series:
        logger.debug("ha encontrado algo: %s" % dict_series[show])

        if len(dict_series[show]['season_episode']) > 1:
            for row in dict_series[show]['season_episode']:

                if new_episode > row[1]:
                    new_episode -= row[1]
                    new_season = row[0]
                    break

        else:
            new_season = dict_series[show]['season_episode'][0][0]
            new_episode += dict_series[show]['season_episode'][0][1]

    logger.debug("%s:%s" % (new_season, new_episode))
    return new_season, new_episode
Example #14
0
def borrar(channel, show):
    logger.info()
    heading = "¿Está seguro que desea eliminar renumeración?"
    line1 = "Pulse 'Si' para eliminar la renumeración de [COLOR blue]%s[/COLOR], pulse 'No' o cierre la ventana " \
            "para no hacer nada." % show.strip()

    if platformtools.dialog_yesno(heading, line1) == 1:
        dict_series = jsontools.get_node_from_data_json(channel, TAG_TVSHOW_RENUMERATE)
        dict_series.pop(show, None)

        result, json_data = jsontools.update_json_data(dict_series, channel, TAG_TVSHOW_RENUMERATE)

        if result:
            message = "FILTRO ELIMINADO"
        else:
            message = "Error al guardar en disco"

        heading = show.strip()
        platformtools.dialog_notification(heading, message)
Example #15
0
def check_value(channel, itemlist):
    ''' comprueba la existencia de un valor en la lista de servidores o calidades
        si no existiera los agrega a la lista en el json

    :param channel: str
    :param values: list (una de servidores o calidades)
    :param value_type: str (server o quality)
    :return: list
    '''
    logger.info()
    global autoplay_node
    change = False

    if not autoplay_node:
        # Obtiene el nodo AUTOPLAY desde el json
        autoplay_node = jsontools.get_node_from_data_json(
            'autoplay', 'AUTOPLAY')

    channel_node = autoplay_node.get(channel)

    server_list = channel_node.get('servers')
    if not server_list:
        server_list = channel_node['servers'] = list()

    quality_list = channel_node.get('quality')
    if not quality_list:
        quality_list = channel_node['quality'] = list()

    for item in itemlist:
        if item.server not in server_list:
            server_list.append(item.server)
            change = True
        if item.quality not in quality_list:
            quality_list.append(item.quality)
            change = True

    if change:
        change, json_data = jsontools.update_json_data(autoplay_node,
                                                       'autoplay', 'AUTOPLAY')

    return change
Example #16
0
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 autoplay_node

    if not config.is_xbmc():
        platformtools.dialog_notification('AutoPlay ERROR',
                                          'Sólo disponible para XBMC/Kodi')
        return itemlist
    else:
        if not autoplay_node:
            # Obtiene el nodo AUTOPLAY desde el json
            autoplay_node = jsontools.get_node_from_data_json(
                'autoplay', 'AUTOPLAY')

        # Agrega servidores y calidades que no estaban listados a autoplay_node
        new_options = check_value(item.channel, itemlist)

        # Obtiene el nodo del canal desde autoplay_node
        channel_node = autoplay_node.get(item.channel, {})
        # Obtiene los ajustes des autoplay para este canal
        settings_node = channel_node.get('settings', {})

        if settings_node['active']:
            url_list_valid = []
            autoplay_list = []
            favorite_servers = []
            favorite_quality = []

            # Guarda el valor actual de "Accion al seleccionar vídeo:" en preferencias
            user_config_setting = config.get_setting("default_action")
            # Habilita la accion "Ver en calidad alta" (si el servidor devuelve más de una calidad p.e. gdrive)
            if user_config_setting != 2:
                config.set_setting("default_action", 2)

            # 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']:
                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', [])
            quality_list = channel_node.get('quality', [])

            # Se guardan los textos de cada servidor y calidad en listas p.e. favorite_servers = ['openload',
            # 'streamcloud']
            for num in range(1, 4):
                favorite_servers.append(
                    channel_node['servers'][settings_node['server_%s' % num]])
                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 item in itemlist:
                autoplay_elem = dict()

                # Comprobamos q se trata de un item de video
                if 'server' not in item:
                    continue

                # Agrega la opcion configurar AutoPlay al menu contextual
                if 'context' not in item:
                    item.context = list()
                if not filter(lambda x: x['action'] == 'autoplay_config',
                              context):
                    item.context.append({
                        "title": "Configurar AutoPlay",
                        "action": "autoplay_config",
                        "channel": "autoplay",
                        "from_channel": item.channel
                    })

                # 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 not in favorite_servers or item.quality not in favorite_quality \
                            or item.url in url_list_valid:
                        continue
                    autoplay_elem["indice_server"] = favorite_servers.index(
                        item.server)
                    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 not in favorite_servers or item.url in url_list_valid:
                        continue
                    autoplay_elem["indice_server"] = favorite_servers.index(
                        item.server)

                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:
                        continue
                    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)
                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_server'],
                                                      orden['indice_quality']))

            elif priority == 1:  # Calidades y servidores
                autoplay_list.sort(key=lambda orden: (orden['indice_quality'],
                                                      orden['indice_server']))

            elif priority == 2:  # Solo servidores
                autoplay_list.sort(key=lambda orden: orden['indice_server'])

            elif priority == 3:  # Solo calidades
                autoplay_list.sort(key=lambda orden: orden['indice_quality'])

            # Si hay elementos en la lista de autoplay se intenta reproducir cada elemento, hasta encontrar uno
            # funcional o fallen todos
            if autoplay_list:
                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:
                    if not platformtools.is_playing() and not played:
                        videoitem = autoplay_elem['videoitem']

                        if videoitem.server not in max_intentos_servers:
                            max_intentos_servers[
                                videoitem.server] = max_intentos

                        # Si se han alcanzado el numero maximo de intentos de este servidor saltamos al siguiente
                        if max_intentos_servers[videoitem.server] == 0:
                            continue

                        lang = " "
                        if hasattr(videoitem,
                                   'language') and videoitem.language != "":
                            lang = " '%s' " % videoitem.language

                        platformtools.dialog_notification(
                            "AutoPlay",
                            "%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
                        channel = __import__('channels.%s' % item.channel,
                                             None, None,
                                             ["channels.%s" % item.channel])
                        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
                        platformtools.play_video(videoitem)

                        try:
                            if platformtools.is_playing():
                                played = True
                                break
                        except:  # TODO evitar el informe de que el conector fallo o el video no se encuentra
                            logger.debug(str(len(autoplay_list)))

                        # Si hemos llegado hasta aqui es por q no se ha podido reproducir
                        max_intentos_servers[videoitem.server] -= 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] == 0:
                            text = "Parece que los enlaces de %s no estan funcionando." % videoitem.server.upper(
                            )
                            if not platformtools.dialog_yesno(
                                    "AutoPlay", text,
                                    "¿Desea ignorar todos los enlaces de este servidor?"
                            ):
                                max_intentos_servers[
                                    videoitem.server] = max_intentos

            else:
                platformtools.dialog_notification('AutoPlay No Fue Posible',
                                                  'No Hubo Coincidencias')
            if new_options:
                platformtools.dialog_notification(
                    "AutoPlay", "Nueva Calidad/Servidor disponible en la "
                    "configuracion",
                    sound=False)

            # Restaura si es necesario el valor previo de "Accion al seleccionar vídeo:" en preferencias
            if user_config_setting != 2:
                config.set_setting("default_action", user_config_setting)

        # devuelve la lista de enlaces para la eleccion manual
        return itemlist
Example #17
0
def autoplay_config(item):
    logger.info()
    global autoplay_node
    dict_values = {}
    list_controls = []
    channel_parameters = channeltools.get_channel_parameters(item.from_channel)
    channel_name = channel_parameters['title']

    if not autoplay_node:
        # Obtiene el nodo AUTOPLAY desde el json
        autoplay_node = jsontools.get_node_from_data_json(
            'autoplay', 'AUTOPLAY')

    channel_node = autoplay_node.get(item.from_channel, {})
    settings_node = channel_node.get('settings', {})

    allow_option = True

    active_settings = {
        "id": "active",
        "label": "AutoPlay (activar/desactivar la auto-reproduccion)",
        "color": "0xffffff99",
        "type": "bool",
        "default": False,
        "enabled": allow_option,
        "visible": allow_option
    }
    list_controls.append(active_settings)
    dict_values['active'] = settings_node.get('active', False)

    # Idioma
    status_language = config.get_setting("filter_languages", item.from_channel)
    if not status_language:
        status_language = 0

    set_language = {
        "id": "language",
        "label": "Idioma para AutoPlay (Opcional)",
        "color": "0xffffff99",
        "type": "list",
        "default": 0,
        "enabled": "eq(-1,true)",
        "visible": True,
        "lvalues": get_languages(item.from_channel)
    }

    list_controls.append(set_language)
    dict_values['language'] = status_language

    separador = {
        "id": "label",
        "label": "         "
        "_________________________________________________________________________________________",
        "type": "label",
        "enabled": True,
        "visible": True
    }
    list_controls.append(separador)

    # Seccion servidores Preferidos
    server_list = channel_node.get("servers", [])
    if not server_list:
        enabled = False
        server_list = ["No disponible"]
    else:
        enabled = "eq(-3,true)"

    custom_servers_settings = {
        "id": "custom_servers",
        "label": "      Servidores Preferidos",
        "color": "0xff66ffcc",
        "type": "bool",
        "default": False,
        "enabled": enabled,
        "visible": True
    }
    list_controls.append(custom_servers_settings)
    if dict_values['active'] and enabled:
        dict_values['custom_servers'] = settings_node.get(
            'custom_servers', False)
    else:
        dict_values['custom_servers'] = False

    for num in range(1, 4):
        pos1 = num + 3
        default = num - 1
        if default > len(server_list) - 1:
            default = 0
        set_servers = {
            "id": "server_%s" % num,
            "label": u"          \u2665 Servidor Favorito %s" % num,
            "color": "0xfffcab14",
            "type": "list",
            "default": default,
            "enabled": "eq(-%s,true)+eq(-%s,true)" % (pos1, num),
            "visible": True,
            "lvalues": server_list
        }
        list_controls.append(set_servers)

        dict_values["server_%s" % num] = settings_node.get(
            "server_%s" % num, 0)
        if settings_node.get("server_%s" % num, 0) > len(server_list) - 1:
            dict_values["server_%s" % num] = 0

    # Seccion Calidades Preferidas
    quality_list = channel_node.get("quality", [])
    if not quality_list:
        enabled = False
        quality_list = ["No disponible"]
    else:
        enabled = "eq(-7,true)"

    custom_quality_settings = {
        "id": "custom_quality",
        "label": "      Calidades Preferidas",
        "color": "0xff66ffcc",
        "type": "bool",
        "default": False,
        "enabled": enabled,
        "visible": True
    }
    list_controls.append(custom_quality_settings)
    if dict_values['active'] and enabled:
        dict_values['custom_quality'] = settings_node.get(
            'custom_quality', False)
    else:
        dict_values['custom_quality'] = False

    for num in range(1, 4):
        pos1 = num + 7
        default = num - 1
        if default > len(quality_list) - 1:
            default = 0

        set_quality = {
            "id": "quality_%s" % num,
            "label": u"          \u2665 Calidad Favorita %s" % num,
            "color": "0xfff442d9",
            "type": "list",
            "default": default,
            "enabled": "eq(-%s,true)+eq(-%s,true)" % (pos1, num),
            "visible": True,
            "lvalues": quality_list
        }
        list_controls.append(set_quality)
        dict_values["quality_%s" % num] = settings_node.get(
            "quality_%s" % num, 0)
        if settings_node.get("quality_%s" % num, 0) > len(quality_list) - 1:
            dict_values["quality_%s" % num] = 0

    # Seccion Prioridades
    priority_list = ["Servidor y Calidad", "Calidad y Servidor"]
    set_priority = {
        "id": "priority",
        "label": "   Prioridad (Indica el orden para Auto-Reproducir)",
        "color": "0xffffff99",
        "type": "list",
        "default": 0,
        "enabled": True,
        "visible": "eq(-4,true)+eq(-8,true)+eq(-11,true)",
        "lvalues": priority_list
    }
    list_controls.append(set_priority)
    dict_values["priority"] = settings_node.get("priority", 0)

    # Abrir cuadro de dialogo
    platformtools.show_channel_settings(list_controls=list_controls,
                                        dict_values=dict_values,
                                        callback='save',
                                        item=item,
                                        caption='%s - AutoPlay' % channel_name)
Example #18
0
def init(channel, list_servers, list_quality):
    '''
    Comprueba la existencia de canal en el archivo de configuracion de Autoplay y si no existe lo añade. 
    Es necesario llamar a esta funcion al entrar a cualquier canal que incluya la funcion Autoplay.
    
    :param channel: (str) id del canal
    :param list_servers: (list) lista inicial de servidores validos para el canal. No es necesario incluirlos todos, 
        ya que la lista de servidores validos se ira actualizando dinamicamente.
    :param list_quality: (list) lista inicial de calidades validas para el canal. No es necesario incluirlas todas, 
        ya que la lista de calidades validas se ira actualizando dinamicamente.
    :return: (bool) True si la inicializacion ha sido correcta.
    '''
    logger.info()
    change = False
    result = True

    if not config.is_xbmc():
        platformtools.dialog_notification('AutoPlay ERROR',
                                          'Sólo disponible para XBMC/Kodi')
        result = False
    else:
        autoplay_path = os.path.join(config.get_data_path(),
                                     "settings_channels", 'autoplay_data.json')
        if os.path.exists(autoplay_path):
            autoplay_node = jsontools.get_node_from_data_json(
                'autoplay', "AUTOPLAY")
        else:
            change = True
            autoplay_node = {"AUTOPLAY": {}}

        if channel not in autoplay_node:
            change = True

            # Se comprueba que no haya calidades ni servidores duplicados
            list_servers = list(set(list_servers))
            list_quality = list(set(list_quality))

            # Creamos el nodo del canal y lo añadimos
            channel_node = {
                "servers": list_servers,
                "quality": list_quality,
                "settings": {
                    "active": False,
                    "custom_servers": False,
                    "custom_quality": False,
                    "priority": 0
                }
            }
            for n in range(1, 4):
                s = c = 0
                if len(list_servers) >= n:
                    s = n - 1
                if len(list_quality) >= n:
                    c = n - 1

                channel_node["settings"]["server_%s" % n] = s
                channel_node["settings"]["quality_%s" % n] = c

            autoplay_node[channel] = channel_node

        if change:
            result, json_data = jsontools.update_json_data(
                autoplay_node, 'autoplay', 'AUTOPLAY')

            if result:
                heading = "AutoPlay Disponible"
                msj = "Seleccione '<Configurar AutoPlay>' para activarlo."
                icon = 0
            else:
                heading = "Error al iniciar AutoPlay"
                msj = "Consulte su log para obtener mas información."
                icon = 1

            platformtools.dialog_notification(heading, msj, icon, sound=False)

    return result
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 = jsontools.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)