Пример #1
0
def check_for_update(overwrite=True):
    logger.debug("Update Series...")
    p_dialog = None
    serie_actualizada = False
    update_when_finished = False
    hoy = datetime.date.today()
    estado_verify_playcount_series = False
    local_ended = True

    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)
                if serie.local_episodes_path:
                    local_ended = True if serie.infoLabels[
                        'number_of_episodes'] == len(
                            serie.local_episodes_list) else False
                if serie.infoLabels['status'].lower(
                ) == 'ended' and local_ended:
                    serie.active = 0
                    filetools.write(tvshow_file, head_nfo + serie.tojson())
                path = filetools.dirname(tvshow_file)

                logger.debug("serie=" + serie.contentSerieName)
                p_dialog.update(int(math.ceil((i + 1) * t)), heading,
                                serie.contentSerieName)

                # Check the status of the series.library_playcounts of the Series in case it is incomplete
                try:
                    estado = False
                    # If we have not done the verification or do not have a playcount, we enter
                    estado = config.get_setting("verify_playcount",
                                                "videolibrary")
                    if not estado or estado == False or not serie.library_playcounts:  # If it hasn't happened before, we do it now
                        serie, estado = videolibrary.verify_playcount_series(
                            serie, path
                        )  # Also happens if a PlayCount is missing completely
                except:
                    logger.error(traceback.format_exc())
                else:
                    if estado:  # If the update was successful ...
                        estado_verify_playcount_series = True  # ... is checked to change the Video Library option

                interval = int(serie.active)  # Could be the bool type

                if not serie.active:
                    # if the series is not active discard
                    if not overwrite:
                        # Synchronize the episodes seen from the Kodi video library with that of Alpha, even if the series is deactivated
                        try:
                            if config.is_xbmc():  # If it's Kodi, we do it
                                from platformcode import xbmc_videolibrary
                                xbmc_videolibrary.mark_content_as_watched_on_kod(
                                    filetools.join(path, 'tvshow.nfo'))
                        except:
                            logger.error(traceback.format_exc())

                        continue

                # Obtain the update date and the next scheduled for this series
                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

                # if the series is active ...
                if overwrite or config.get_setting("updatetvshows_interval",
                                                   "videolibrary") == 0:
                    # ... force update regardless of interval
                    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:
                    # ...daily update
                    serie_actualizada = update(path, p_dialog, i, t, serie,
                                               overwrite)
                    if not serie_actualizada and update_last <= hoy - datetime.timedelta(
                            days=7):
                        # if it hasn't been updated for a week, change the interval to weekly
                        interval = 7
                        update_next = hoy + datetime.timedelta(days=interval)

                elif interval == 7 and update_next <= hoy:
                    # ... weekly update
                    serie_actualizada = update(path, p_dialog, i, t, serie,
                                               overwrite)
                    if not serie_actualizada:
                        if update_last <= hoy - datetime.timedelta(days=14):
                            # if it has not been updated for 2 weeks, change the interval to monthly
                            interval = 30

                        update_next += datetime.timedelta(days=interval)

                elif interval == 30 and update_next <= hoy:
                    # ... monthly update
                    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)  # Reread the .nfo, which has been modified
                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')
                    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:
                        # We update the Kodi video library: Find content in the series folder
                        if config.is_xbmc() and config.get_setting(
                                "videolibrary_kodi"):
                            from platformcode import xbmc_videolibrary
                            xbmc_videolibrary.update(
                                folder=filetools.basename(path))
                    else:
                        update_when_finished = True

            if estado_verify_playcount_series:  # If any playcount has been changed, ...
                estado = config.set_setting(
                    "verify_playcount", True,
                    "videolibrary")  # ... we update the Videolibrary option

            if config.get_setting(
                    "search_new_content",
                    "videolibrary") == 1 and update_when_finished:
                # We update the Kodi video library: Find content in all series
                if config.is_xbmc() and config.get_setting(
                        "videolibrary_kodi"):
                    from platformcode import xbmc_videolibrary
                    xbmc_videolibrary.update()

            p_dialog.close()

        else:
            logger.debug("Not update the video library, it is disabled")

    except Exception as ex:
        logger.error("An error occurred while updating the 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()

    from core.item import Item
    item_dummy = Item()
    videolibrary.list_movies(item_dummy, silent=True)

    if config.get_setting('trakt_sync'):
        from core import trakt_tools
        trakt_tools.update_all()
Пример #2
0
            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()

    from core.item import Item
    item_dummy = Item()
    videolibrary.list_movies(item_dummy, silent=True)


def start(thread=True):
    if thread:
        t = threading.Thread(target=start, args=[False])
        t.setDaemon(True)
        t.start()
    else:
        import time

        update_wait = [0, 10000, 20000, 30000, 60000]
        wait = update_wait[int(
            config.get_setting("update_wait", "videolibrary"))]
        if wait > 0:
            time.sleep(wait)
Пример #3
0
def check_for_update(overwrite=True):
    logger.info("Update Series...")
    p_dialog = None
    serie_actualizada = False
    update_when_finished = False
    hoy = datetime.date.today()
    estado_verify_playcount_series = False
    local_ended = True

    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)
                if serie.local_episodes_path:
                    local_ended = True if serie.infoLabels[
                        'number_of_episodes'] == len(
                            serie.local_episodes_list) else False
                if serie.infoLabels['status'].lower(
                ) == 'ended' and local_ended:
                    serie.active = 0
                    filetools.write(tvshow_file, head_nfo + serie.tojson())
                path = filetools.dirname(tvshow_file)

                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:
                    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 not overwrite:
                        #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_kod(
                                    filetools.join(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')
                    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() and config.get_setting(
                                "videolibrary_kodi"):
                            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() and config.get_setting(
                        "videolibrary_kodi"):
                    from platformcode import xbmc_videolibrary
                    xbmc_videolibrary.update()

            p_dialog.close()

        else:
            logger.info("Not update the video library, it is disabled")

    except Exception as ex:
        logger.error("An error occurred while updating the 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()

    from core.item import Item
    item_dummy = Item()
    videolibrary.list_movies(item_dummy, silent=True)

    if config.get_setting('trakt_sync'):
        from core import trakt_tools
        trakt_tools.update_all()