Example #1
0
def action_download(params):
    plugintools.log("dandb.action_download "+repr(params))

    icon = os.path.join( plugintools.get_runtime_path() , "icon.png" )
    filename = plugintools.get_filename_from_url(params.get("file_url"))
    full_path_filename = os.path.join( plugintools.get_data_path() , filename )
    plugintools.download(params.get("file_url"),full_path_filename)

    plugintools.show_notification("D&B TV","File "+filename+"downloaded",icon)
Example #2
0
def action_download_and_execute(params):
    plugintools.log("dandb.action_download_and_execute "+repr(params))

    icon = os.path.join( plugintools.get_runtime_path() , "icon.png" )

    # Download file
    filename = plugintools.get_filename_from_url(params.get("file_url"))
    full_path_filename = os.path.join( plugintools.get_data_path() , filename )
    plugintools.download(params.get("file_url"),full_path_filename)
    plugintools.show_notification("D&B TV","File "+filename+"downloaded",icon)

    # Replace filename
    command = params.get("command")
    plugintools.log("dandb.action_download_and_execute command="+command)
    command = command.replace("$1",full_path_filename)
    plugintools.log("dandb.action_download_and_execute command="+command)

    # Execute command
    params["command"] = command
    action_execute(params)
Example #3
0
def action_execute(params):
    plugintools.log("dandb.action_execute "+repr(params))

    icon = os.path.join( plugintools.get_runtime_path() , "icon.png" )

    if params.get("command_type")=="system":
        os.system(params.get("command"))
        plugintools.show_notification("D&B TV","Command executed",icon)

    elif params.get("command_type")=="xbmc":
        import xbmc
        xbmc.executebuiltin(params.get("command"))
        plugintools.show_notification("D&B TV","Command executed",icon)
    else:
        plugintools.show_notification("D&B TV","Command *NOT* executed",icon)
Example #4
0
def run(item=None):
    logger.info("tvalacarta.platformcode.launcher run")

    if item is None:
        # Extract item from sys.argv
        if sys.argv[2]:
            item = Item().fromurl(sys.argv[2])
            params = ""

        # If no item, this is mainlist
        else:
            item = Item(action="selectchannel")
            params = ""

    logger.info(item.tostring())

    # If item has no action, stops here
    if item.action == "":
        logger.info("Item sin accion")
        return

    try:
        # Action for main menu in channelselector
        if item.action == "selectchannel":

            import channelselector
            import plugintools

            # Check for updates only on first screen
            if config.get_setting("check_for_plugin_updates") == "true":
                logger.info(
                    "tvalacarta.platformcode.launcher Check for plugin updates enabled"
                )
                from core import updater

                try:
                    config.set_setting("plugin_updates_available", "0")
                    new_published_version_tag, number_of_updates = updater.get_available_updates(
                    )

                    config.set_setting("plugin_updates_available",
                                       str(number_of_updates))

                    # TODO: Que channelselector devuelva items, procesados por el mismo add_items_to_kodi_directory que el resto
                    itemlist = channelselector.mainlist(
                        params, item.url, item.category)

                    if new_published_version_tag != "":
                        plugintools.show_notification(
                            new_published_version_tag + " disponible",
                            "Ya puedes descargar la nueva versión del plugin\n"
                            "desde el menú Configuración")
                except:
                    import traceback
                    logger.error(traceback.format_exc())
                    plugintools.message("No se puede conectar",
                                        "No ha sido posible comprobar",
                                        "si hay actualizaciones")
                    logger.error("Fallo al verificar la actualización")
                    config.set_setting("plugin_updates_available", "0")
                    itemlist = channelselector.mainlist(
                        params, item.url, item.category)

            else:
                logger.info("Check for plugin updates disabled")
                config.set_setting("plugin_updates_available", "0")
                itemlist = channelselector.mainlist(params, item.url,
                                                    item.category)

            #xbmctools.add_items_to_kodi_directory(itemlist, item)

        # Action for updating plugin
        elif item.action == "update":

            from core import updater
            updater.update(item)
            if config.get_system_platform() != "xbox":
                import xbmc
                xbmc.executebuiltin("Container.Refresh")

        # Action for channel types on channelselector: movies, series, etc.
        elif item.action == "channeltypes":
            import channelselector
            # TODO: Que channelselector devuelva items, procesados por el mismo add_items_to_kodi_directory que el resto
            itemlist = channelselector.channeltypes(params, item.url,
                                                    item.category)

            #xbmctools.add_items_to_kodi_directory(itemlist, item)

        # Action for channel listing on channelselector
        elif item.action == "listchannels":
            import channelselector
            # TODO: Que channelselector devuelva items, procesados por el mismo add_items_to_kodi_directory que el resto
            itemlist = channelselector.listchannels(params, item.url,
                                                    item.category)

            #xbmctools.add_items_to_kodi_directory(itemlist, item)

        elif item.action == "player_directo":

            from core import window_player_background
            from channels import directos
            import plugintools

            window = window_player_background.PlayerWindowBackground(
                "player_background.xml", plugintools.get_runtime_path())
            window.setItemlist(directos.build_channel_list())
            window.setCurrentPosition(item.position)
            window.doModal()
            del window
            return

        # Action in certain channel specified in "action" and "channel" parameters
        else:

            # Checks if channel exists
            channel_file = os.path.join(config.get_runtime_path(), 'channels',
                                        item.channel + ".py")
            logger.info("tvalacarta.platformcode.launcher channel_file=%s" %
                        channel_file)

            channel = __import__('channels.%s' % item.channel,
                                 fromlist=["channels.%s" % item.channel])
            logger.info(
                "tvalacarta.platformcode.launcher running channel {0} {1}".
                format(channel.__name__, channel.__file__))

            # Special play action
            if item.action == "play":
                logger.info("tvalacarta.platformcode.launcher play")

                # First checks if channel has a "play" function
                if hasattr(channel, 'play'):
                    logger.info(
                        "tvalacarta.platformcode.launcher executing channel 'play' method"
                    )
                    itemlist = channel.play(item)

                    if len(itemlist) > 0:
                        item = itemlist[0]
                        xbmctools.play_video(item)
                    else:
                        import xbmcgui
                        ventana_error = xbmcgui.Dialog()
                        ok = ventana_error.ok("plugin",
                                              "No hay nada para reproducir")
                else:
                    logger.info(
                        "tvalacarta.platformcode.launcher executing core 'play' method"
                    )
                    xbmctools.play_video(item)

            elif item.action.startswith("serie_options##"):
                from core import suscription
                import xbmcgui
                dia = xbmcgui.Dialog()
                opciones = []

                suscription_item = Item(channel=item.channel,
                                        title=item.show,
                                        url=item.url,
                                        action=item.action.split("##")[1],
                                        extra=item.extra,
                                        plot=item.plot,
                                        show=item.show,
                                        thumbnail=item.thumbnail)

                if not suscription.already_suscribed(suscription_item):
                    opciones.append("Activar descarga automática")
                else:
                    opciones.append("Cancelar descarga automática")

                #opciones.append("Añadir esta serie a favoritos")
                opciones.append("Descargar todos los episodios")
                seleccion = dia.select("Elige una opción",
                                       opciones)  # "Elige una opción"

                if seleccion == 0:
                    if not suscription.already_suscribed(suscription_item):
                        suscription.append_suscription(suscription_item)

                        yes_pressed = xbmcgui.Dialog().yesno(
                            "Descarga automática activada",
                            "A partir de ahora los nuevos vídeos que se publiquen de este programa se descargarán automáticamente, podrás encontrarlos en la sección 'Descargas'."
                        )

                        if yes_pressed:
                            download_all_episodes(suscription_item, channel)

                    else:
                        suscription.remove_suscription(suscription_item)
                        xbmcgui.Dialog().ok(
                            "Descarga automática cancelada",
                            "Los vídeos que hayas descargado se mantienen, pero los nuevos ya no se descargarán ellos solos."
                        )

                elif seleccion == 1:
                    downloadtools.download_all_episodes(item, channel)
                '''
                elif seleccion==1:
                    from core import favoritos
                    from core import downloadtools
                    import xbmc

                    keyboard = xbmc.Keyboard(downloadtools.limpia_nombre_excepto_1(item.show)+" ["+item.channel+"]")
                    keyboard.doModal()
                    if keyboard.isConfirmed():
                        title = keyboard.getText()
                        favoritos.savebookmark(titulo=title,url=item.url,thumbnail=item.thumbnail,server="",plot=item.plot,fulltitle=title)
                        advertencia = xbmcgui.Dialog()
                        resultado = advertencia.ok(config.get_localized_string(30102) , title , config.get_localized_string(30108)) # 'se ha añadido a favoritos'
                    return
                '''

            elif item.action == "search":
                logger.info("tvalacarta.platformcode.launcher search")

                import xbmc
                keyboard = xbmc.Keyboard("")
                keyboard.doModal()

                itemlist = []
                if (keyboard.isConfirmed()):
                    tecleado = keyboard.getText()
                    #tecleado = tecleado.replace(" ", "+")
                    itemlist = channel.search(item, tecleado)
                    if itemlist is None:
                        itemlist = []

                xbmctools.add_items_to_kodi_directory(itemlist, item)

            else:
                logger.info(
                    "tvalacarta.platformcode.launcher executing channel '" +
                    item.action + "' method")
                exec "itemlist = channel." + item.action + "(item)"
                if itemlist is None:
                    itemlist = []

                # Activa el modo biblioteca para todos los canales genéricos, para que se vea el argumento
                handle = sys.argv[1]
                xbmcplugin.setContent(int(handle), "movies")

                # Añade los items a la lista de XBMC
                xbmctools.add_items_to_kodi_directory(itemlist, item)

    except UserException, e:
        import xbmcgui
        xbmcgui.Dialog().ok("Se ha producido un error", e.value)