Ejemplo n.º 1
0
def play_from_library(item):
    """
        The .strm files when played from kodi, this expects it to be a "playable" file so it cannot contain
        more items, at most a selection dialog can be placed.
        We solve this by "cheating kodi" and making him believe that something has been reproduced, so later by
        "Container.Update ()" we load the strm as if an item from inside the addon were treated, removing all
        the limitations and allowing to reproduce through the general function without having to create new methods to
        the video library.
        @type item: item
        @param item: item with information
    """
    import xbmcgui, xbmcplugin, xbmc
    from time import sleep

    itemlist = []
    item.fromLibrary = True
    logger.info()
    # logger.debug("item: \n" + item.tostring('\n'))

    # Try to reproduce an image (this does nothing and also does not give an error)
    xbmcplugin.setResolvedUrl(
        int(sys.argv[1]), True,
        xbmcgui.ListItem(path=os.path.join(config.get_runtime_path(),
                                           "resources", "kod.mp4")))
    xbmc.Player().stop()

    # Modify the action (currently the video library needs "findvideos" since this is where the sources are searched
    item.action = "findvideos"

    window_type = config.get_setting("window_type", "videolibrary")
    # and launch kodi again
    if xbmc.getCondVisibility('Window.IsMedia') and not window_type == 1:
        # Conventional window
        xbmc.executebuiltin("Container.Update(" + sys.argv[0] + "?" +
                            item.tourl() + ")")

    else:
        # Pop-up window
        from specials import videolibrary
        p_dialog = platformtools.dialog_progress_bg(
            config.get_localized_string(20000),
            config.get_localized_string(60683))
        p_dialog.update(0, '')
        item.play_from = 'window'
        itemlist = videolibrary.findvideos(item)
        p_dialog.update(100, '')
        sleep(0.5)
        p_dialog.close()
        while platformtools.is_playing():  # Conventional window
            sleep(1)
        play_time = platformtools.resume_playback(item, True)
        if not play_time and config.get_setting('autoplay'):
            return

        # The number of links to show is limited
        if config.get_setting("max_links", "videolibrary") != 0:
            itemlist = limit_itemlist(itemlist)
        # The list of links is slightly "cleaned"
        if config.get_setting("replace_VD", "videolibrary") == 1:
            itemlist = reorder_itemlist(itemlist)

        if len(itemlist) > 0:
            while not xbmc.Monitor().abortRequested():
                # The user chooses the mirror
                options = []
                selection_implementation = 0
                for item in itemlist:
                    item.thumbnail = config.get_online_server_thumb(
                        item.server)
                    quality = '[B][' + item.quality + '][/B]' if item.quality else ''
                    if item.server:
                        it = xbmcgui.ListItem(
                            '\n[B]%s[/B] %s - %s' %
                            (item.server, quality, item.contentTitle))
                        it.setArt({'thumb': item.thumbnail})
                        options.append(it)
                    else:
                        selection_implementation += 1
                # The selection window opens
                if (item.contentSerieName and item.contentSeason
                        and item.contentEpisodeNumber):
                    head = ("%s - %sx%s | %s" %
                            (item.contentSerieName, item.contentSeason,
                             item.contentEpisodeNumber,
                             config.get_localized_string(30163)))
                else:
                    head = config.get_localized_string(30163)
                selection = platformtools.dialog_select(head,
                                                        options,
                                                        preselect=-1,
                                                        useDetails=True)
                if selection == -1:
                    return
                else:
                    item = videolibrary.play(
                        itemlist[selection + selection_implementation])[0]
                    platformtools.play_video(item)
                if (platformtools.is_playing() and item.action
                    ) or item.server == 'torrent' or config.get_setting(
                        'autoplay'):
                    break
Ejemplo n.º 2
0
def play_from_library(item):
    """
        The .strm files when played from kodi, this expects it to be a "playable" file so it cannot contain
        more items, at most a selection dialog can be placed.
        We solve this by "cheating kodi" and making him believe that something has been reproduced, so later by
        "Container.Update ()" we load the strm as if an item from inside the addon were treated, removing all
        the limitations and allowing to reproduce through the general function without having to create new methods to
        the video library.
        @type item: item
        @param item: item with information
    """
    def get_played_time(item):
        if item.contentType == 'movie': nfo_path = item.nfo
        else: nfo_path = item.strm_path.replace('strm', 'nfo')
        if nfo_path and filetools.isfile(nfo_path):
            from core import videolibrarytools
            head_nfo, item_nfo = videolibrarytools.read_nfo(nfo_path)
            sleep(1)
            played_time = platformtools.get_played_time(item_nfo)
        else:
            played_time = 0
        return played_time

    import xbmcgui, xbmcplugin, xbmc
    from time import sleep

    # logger.debug("item: \n" + item.tostring('\n'))
    platformtools.prevent_busy(item)

    itemlist = []
    item.fromLibrary = True
    item.window = True
    logger.debug()

    # Modify the action (currently the video library needs "findvideos" since this is where the sources are searched
    item.action = "findvideos"

    window_type = config.get_setting("window_type", "videolibrary")
    # and launch kodi again
    if xbmc.getCondVisibility('Window.IsMedia') and not window_type == 1:
        xbmc.executebuiltin("Container.Update(" + sys.argv[0] + "?" +
                            item.tourl() + ")")

    else:
        # Pop-up window
        from specials import videolibrary
        p_dialog = platformtools.dialog_progress_bg(
            config.get_localized_string(20000),
            config.get_localized_string(60683))
        p_dialog.update(0, '')
        item.play_from = 'window'
        itemlist = videolibrary.findvideos(item)
        p_dialog.update(100, '')
        sleep(0.5)
        p_dialog.close()
        played = False

        # The number of links to show is limited
        if config.get_setting("max_links", "videolibrary") != 0:
            itemlist = limit_itemlist(itemlist)
        # The list of links is slightly "cleaned"
        if config.get_setting("replace_VD", "videolibrary") == 1:
            itemlist = reorder_itemlist(itemlist)
        # from core.support import dbg;dbg()
        if len(itemlist) > 0:
            reopen = False
            while not xbmc.Monitor().abortRequested():
                played = True
                # The user chooses the mirror
                if not platformtools.is_playing():
                    # from core.support import dbg;dbg()
                    if config.get_setting('autoplay') or reopen:
                        played_time = get_played_time(item)
                        if not played_time and played:
                            return
                    options = []
                    selection_implementation = 0
                    for item in itemlist:
                        item.thumbnail = config.get_online_server_thumb(
                            item.server)
                        quality = '[B][' + item.quality + '][/B]' if item.quality else ''
                        if item.server:
                            path = filetools.join(
                                config.get_runtime_path(), 'servers',
                                item.server.lower() + '.json')
                            name = jsontools.load(open(path,
                                                       "r").read())['name']
                            if name.startswith('@'):
                                name = config.get_localized_string(
                                    int(name.replace('@', '')))
                            it = xbmcgui.ListItem(
                                '\n[B]%s[/B] %s - %s' %
                                (name, quality, item.contentTitle))
                            it.setArt({'thumb': item.thumbnail})
                            options.append(it)
                        else:
                            selection_implementation += 1
                    # The selection window opens
                    if (item.contentSerieName and item.contentSeason
                            and item.contentEpisodeNumber):
                        head = ("%s - %sx%s | %s" %
                                (item.contentSerieName, item.contentSeason,
                                 item.contentEpisodeNumber,
                                 config.get_localized_string(30163)))
                    else:
                        head = config.get_localized_string(30163)
                    selection = platformtools.dialog_select(head,
                                                            options,
                                                            preselect=-1,
                                                            useDetails=True)
                    if selection == -1:
                        return
                    else:
                        item = videolibrary.play(
                            itemlist[selection + selection_implementation])[0]
                        platformtools.play_video(item)
                        reopen = True
Ejemplo n.º 3
0
def play_from_library(item):
    """
        Los .strm al reproducirlos desde kodi, este espera que sea un archivo "reproducible" asi que no puede contener
        más items, como mucho se puede colocar un dialogo de seleccion.
        Esto lo solucionamos "engañando a kodi" y haciendole creer que se ha reproducido algo, asi despues mediante
        "Container.Update()" cargamos el strm como si un item desde dentro del addon se tratara, quitando todas
        las limitaciones y permitiendo reproducir mediante la funcion general sin tener que crear nuevos métodos para
        la videoteca.
        @type item: item
        @param item: elemento con información
    """
    logger.info()
    #logger.debug("item: \n" + item.tostring('\n'))

    import xbmcgui
    import xbmcplugin
    import xbmc
    from time import sleep

    # Intentamos reproducir una imagen (esto no hace nada y ademas no da error)
    xbmcplugin.setResolvedUrl(
        int(sys.argv[1]), True,
        xbmcgui.ListItem(path=os.path.join(config.get_runtime_path(),
                                           "resources", "kod.mp4")))

    # Por si acaso la imagen hiciera (en futuras versiones) le damos a stop para detener la reproduccion
    # sleep(0.5)              ### Si no se pone esto se bloquea Kodi
    xbmc.Player().stop()

    # modificamos el action (actualmente la videoteca necesita "findvideos" ya que es donde se buscan las fuentes
    item.action = "findvideos"

    window_type = config.get_setting("window_type", "videolibrary")

    # y volvemos a lanzar kodi
    if xbmc.getCondVisibility('Window.IsMedia') and not window_type == 1:
        # Ventana convencional
        xbmc.executebuiltin("Container.Update(" + sys.argv[0] + "?" +
                            item.tourl() + ")")

    else:
        # Ventana emergente
        from specials import videolibrary
        p_dialog = platformtools.dialog_progress_bg(
            config.get_localized_string(20000),
            config.get_localized_string(70004))
        p_dialog.update(0, '')

        itemlist = videolibrary.findvideos(item)

        while platformtools.is_playing():
            # Ventana convencional
            sleep(5)
        p_dialog.update(50, '')
        '''# Se filtran los enlaces segun la lista negra
        if config.get_setting('filter_servers', "servers"):
            itemlist = servertools.filter_servers(itemlist)'''

        # Se limita la cantidad de enlaces a mostrar
        if config.get_setting("max_links", "videolibrary") != 0:
            itemlist = limit_itemlist(itemlist)

        # Se "limpia" ligeramente la lista de enlaces
        if config.get_setting("replace_VD", "videolibrary") == 1:
            itemlist = reorder_itemlist(itemlist)

        import time
        p_dialog.update(100, '')
        time.sleep(0.5)
        p_dialog.close()

        if len(itemlist) > 0:
            while not xbmc.Monitor().abortRequested():
                # El usuario elige el mirror
                opciones = []
                for item in itemlist:
                    opciones.append(item.title)

                # Se abre la ventana de seleccion
                if (item.contentSerieName != "" and item.contentSeason != ""
                        and item.contentEpisodeNumber != ""):
                    cabecera = ("%s - %sx%s -- %s" %
                                (item.contentSerieName, item.contentSeason,
                                 item.contentEpisodeNumber,
                                 config.get_localized_string(30163)))
                else:
                    cabecera = config.get_localized_string(30163)

                seleccion = platformtools.dialog_select(cabecera, opciones)

                if seleccion == -1:
                    return
                else:
                    item = videolibrary.play(itemlist[seleccion])[0]
                    platformtools.play_video(item)

                from specials import autoplay
                if (platformtools.is_playing() and item.action
                    ) or item.server == 'torrent' or autoplay.is_active(
                        item.contentChannel):
                    break