Beispiel #1
0
def move_to_libray(item):

    download_path = filetools.join(config.get_setting("downloadpath"), item.downloadFilename)
    library_path = filetools.join(config.get_library_path(), *filetools.split(item.downloadFilename))
    final_path = download_path
      
    if config.get_setting("library_add", "descargas") == True and config.get_setting("library_move", "descargas") == True:   
      if not filetools.isdir(filetools.dirname(library_path)):
        filetools.mkdir(filetools.dirname(library_path))
    
      if filetools.isfile(library_path) and filetools.isfile(download_path) :
        filetools.remove(library_path)

      if filetools.isfile(download_path):
        if filetools.move(download_path, library_path):
          final_path = library_path
          
        if len(filetools.listdir(filetools.dirname(download_path))) == 0: 
          filetools.rmdir(filetools.dirname(download_path))
          
    if config.get_setting("library_add", "descargas") == True: 
      if filetools.isfile(final_path):
        if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
          library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=final_path)
          library.save_library_movie(library_item)
          
        elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
          library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=final_path)
          tvshow = Item(channel= "descargas", contentType="tvshow", infoLabels = {"tmdb_id": item.infoLabels["tmdb_id"]})
          library.save_library_tvshow(tvshow, [library_item])
Beispiel #2
0
def move_to_libray(item):
    try:
      from core import library
    except:
      return
      
    # Copiamos el archivo a la biblioteca
    origen = filetools.join(config.get_setting("downloadpath"), item.downloadFilename)
    destino = filetools.join(config.get_library_path(), *filetools.split(item.downloadFilename))
    
    if not filetools.isdir(filetools.dirname(destino)):
      filetools.mkdir(filetools.dirname(destino))
    
    if filetools.isfile(destino) and filetools.isfile(origen) :
      filetools.remove(destino)

    if filetools.isfile(origen):
      filetools.move(origen, destino)
      if len(filetools.listdir(filetools.dirname(origen))) == 0: 
        filetools.rmdir(filetools.dirname(origen))
      
    else:
      logger.error("No se ha encontrado el archivo: %s" % origen)
    
    if filetools.isfile(destino):
      if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
        library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=item.downloadFilename)
        
        library.save_library_movie(library_item)
        
      elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
        library_item = Item(title="Descargado: %s" % item.downloadFilename, channel= "descargas", action="findvideos", infoLabels=item.infoLabels, url=item.downloadFilename)
        
        tvshow = Item(channel= "descargas", contentType="tvshow", infoLabels = {"tmdb_id": item.infoLabels["tmdb_id"]})
        library.save_library_tvshow(tvshow, [library_item])
Beispiel #3
0
def move_to_libray(item):
    if not config.get_setting("library_move", "descargas") == True:
        return

    try:
        from core import library
    except:
        return

    # Copiamos el archivo a la biblioteca
    origen = filetools.join(config.get_setting("downloadpath"),
                            item.downloadFilename)
    destino = filetools.join(config.get_library_path(),
                             *filetools.split(item.downloadFilename))

    if not filetools.isdir(filetools.dirname(destino)):
        filetools.mkdir(filetools.dirname(destino))

    if filetools.isfile(destino) and filetools.isfile(origen):
        filetools.remove(destino)

    if filetools.isfile(origen):
        filetools.move(origen, destino)
        if len(filetools.listdir(filetools.dirname(origen))) == 0:
            filetools.rmdir(filetools.dirname(origen))

    else:
        logger.error("No se ha encontrado el archivo: %s" % origen)

    if filetools.isfile(destino):
        if item.contentType == "movie" and item.infoLabels["tmdb_id"]:
            library_item = Item(title="Scaricato: %s" % item.downloadFilename,
                                channel="descargas",
                                action="findvideos",
                                infoLabels=item.infoLabels,
                                url=item.downloadFilename)

            library.save_library_movie(library_item)

        elif item.contentType == "episode" and item.infoLabels["tmdb_id"]:
            library_item = Item(title="Scaricato: %s" % item.downloadFilename,
                                channel="descargas",
                                action="findvideos",
                                infoLabels=item.infoLabels,
                                url=item.downloadFilename)

            tvshow = Item(channel="descargas",
                          contentType="tvshow",
                          infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]})
            library.save_library_tvshow(tvshow, [library_item])
Beispiel #4
0
def update(path, p_dialog, i, t, serie, overwrite):
    logger.info("Actualizando " + path)
    insertados_total = 0

    # logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) ))
    for channel, url in serie.library_urls.items():
        serie.channel = channel
        serie.url = url

        #channel_active = channeltools.is_active(channel)

        #if channel_active:

        heading = 'Actualizando biblioteca....'
        p_dialog.update(
            int(math.ceil((i + 1) * t)), heading,
            "%s: %s" % (serie.contentSerieName, serie.channel.capitalize()))
        try:
            pathchannels = filetools.join(config.get_runtime_path(),
                                          "channels", serie.channel + '.py')
            logger.info("Cargando canal: " + pathchannels + " " +
                        serie.channel)

            if serie.library_filter_show:
                serie.show = serie.library_filter_show.get(
                    channel, serie.contentSerieName)

            obj = imp.load_source(serie.channel, pathchannels)
            itemlist = obj.episodios(serie)

            try:
                if int(overwrite) == 3:
                    # Sobrescribir todos los archivos (tvshow.nfo, 1x01.nfo, 1x01 [canal].json, 1x01.strm, etc...)
                    insertados, sobreescritos, fallidos = library.save_library_tvshow(
                        serie, itemlist)
                else:
                    insertados, sobreescritos, fallidos = library.save_library_episodes(
                        path,
                        itemlist,
                        serie,
                        silent=True,
                        overwrite=overwrite)
                insertados_total += insertados

            except Exception, ex:
                logger.error("Error al guardar los capitulos de la serie")
                template = "An exception of type %s occured. Arguments:\n%r"
                message = template % (type(ex).__name__, ex.args)
                logger.error(message)

        except Exception, ex:
            logger.error("Error al obtener los episodios de: %s" % serie.show)
            template = "An exception of type %s occured. Arguments:\n%r"
            message = template % (type(ex).__name__, ex.args)
            logger.error(message)
Beispiel #5
0
def update(path, p_dialog, i, t, serie, overwrite):
    logger.info("Actualizando " + path)
    insertados_total = 0

    # logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) ))
    for channel, url in serie.library_urls.items():
        serie.channel = channel
        serie.url = url

        heading = 'Aggiornamento della libreria...'
        p_dialog.update(int(math.ceil((i + 1) * t)), heading, "%s: %s" % (serie.contentSerieName,
                                                                          serie.channel.capitalize()))
        pathchannels = filetools.join(config.get_runtime_path(), "channels", serie.channel + '.py')
        logger.info("Caricando il canale: " + pathchannels + " " +
                    serie.channel)

        if serie.library_filter_show:
            serie.show = serie.library_filter_show.get(channel, serie.contentSerieName)

        obj = imp.load_source(serie.channel, pathchannels)

        itemlist = ""
        try:
            itemlist = obj.episodios(serie)
        except Exception as ex:
            pass
        try:
            if itemlist == "":
                itemlist = obj.serietv(serie)

            try:
                if int(overwrite) == 3:
                    # Overwrite all files (tvshow.nfo, 1x01.nfo, 1x01 [canal].json, 1x01.strm, etc...)
                    insertados, sobreescritos, fallidos = library.save_library_tvshow(serie, itemlist)
                else:
                    insertados, sobreescritos, fallidos = library.save_library_episodes(path, itemlist, serie,
                                                                                        silent=True,
                                                                                        overwrite=overwrite)
                insertados_total += insertados

            except Exception as ex:
                logger.error("Errore nei capitoli delle serie")
                template = "An exception of type %s occured. Arguments:\n%r"
                message = template % (type(ex).__name__, ex.args)
                logger.error(message)

        except Exception as ex:
            pass

        if itemlist == "":
            logger.error("Errore nel ricavare gli episodi di %s. Verificare il metodo utilizzato dal canale %s." % (
            serie.show, serie.channel))

    return insertados_total > 0
def update(path, p_dialog, i, t, serie, overwrite):
    logger.info("Actualizando " + path)
    insertados_total = 0

    # logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) ))
    for channel, url in serie.library_urls.items():
        serie.channel = channel
        serie.url = url

        heading = 'Actualizando biblioteca....'
        p_dialog.update(int(math.ceil((i + 1) * t)), heading, "%s: %s" % (serie.contentSerieName,
                                                                          serie.channel.capitalize()))
        try:
            pathchannels = filetools.join(config.get_runtime_path(), "channels", serie.channel + '.py')
            logger.info("Cargando canal: " + pathchannels + " " +
                        serie.channel)

            if serie.library_filter_show:
                serie.show = serie.library_filter_show.get(channel, serie.contentSerieName)

            obj = imp.load_source(serie.channel, pathchannels)
            itemlist = obj.episodios(serie)

            try:
                if int(overwrite) == 3:
                    # Sobrescribir todos los archivos (tvshow.nfo, 1x01.nfo, 1x01 [canal].json, 1x01.strm, etc...)
                    insertados, sobreescritos, fallidos = library.save_library_tvshow(serie, itemlist)
                else:
                    insertados, sobreescritos, fallidos = library.save_library_episodes(path, itemlist, serie,
                                                                                        silent=True,
                                                                                        overwrite=overwrite)
                insertados_total += insertados

            except Exception as ex:
                logger.error("Error al guardar los capitulos de la serie")
                template = "An exception of type %s occured. Arguments:\n%r"
                message = template % (type(ex).__name__, ex.args)
                logger.error(message)

        except Exception as ex:
            logger.error("Error al obtener los episodios de: %s" % serie.show)
            template = "An exception of type %s occured. Arguments:\n%r"
            message = template % (type(ex).__name__, ex.args)
            logger.error(message)

    return insertados_total > 0
def convert_old_to_v4():
    logger.info()
    path_series_xml = filetools.join(config.get_data_path(), "series.xml")
    path_series_json = filetools.join(config.get_data_path(), "series.json")
    series_insertadas = 0
    series_fallidas = 0
    version = 'v?'

    # Renombrar carpeta Series y crear una vacia
    import time
    new_name = str(time.time())
    path_series_old = filetools.join(library.LIBRARY_PATH, "SERIES_OLD_" + new_name)
    if filetools.rename(library.TVSHOWS_PATH, "SERIES_OLD_" + new_name):
        if not filetools.mkdir(library.TVSHOWS_PATH):
            logger.error("ERROR, no se ha podido crear la nueva carpeta de SERIES")
            return False
    else:
        logger.error("ERROR, no se ha podido renombrar la antigua carpeta de SERIES")
        return False

    path_cine_old = filetools.join(library.LIBRARY_PATH, "CINE_OLD_" + new_name)
    if filetools.rename(library.MOVIES_PATH,  "CINE_OLD_" + new_name):
        if not filetools.mkdir(library.MOVIES_PATH):
            logger.error("ERROR, no se ha podido crear la nueva carpeta de CINE")
            return False
    else:
        logger.error("ERROR, no se ha podido renombrar la antigua carpeta de CINE")
        return False

    # Convertir libreria de v1(xml) a v4
    if filetools.exists(path_series_xml):
        try:
            data = filetools.read(path_series_xml)
            for line in data.splitlines():
                try:
                    aux = line.rstrip('\n').split(",")
                    tvshow = aux[0].strip()
                    url = aux[1].strip()
                    channel = aux[2].strip()

                    serie = Item(contentSerieName=tvshow, url=url, channel=channel, action="episodios",
                                 title=tvshow, active=True)

                    patron = "^(.+)[\s]\((\d{4})\)$"
                    matches = re.compile(patron, re.DOTALL).findall(serie.contentSerieName)

                    if matches:
                        serie.infoLabels['title'] = matches[0][0]
                        serie.infoLabels['year'] = matches[0][1]
                    else:
                        serie.infoLabels['title'] = tvshow

                    insertados, sobreescritos, fallidos = library.save_library_tvshow(serie, list())
                    if fallidos == 0:
                        series_insertadas += 1
                        platformtools.dialog_notification("Serie actualizada", serie.infoLabels['title'])
                    else:
                        series_fallidas += 1
                except:
                    series_fallidas += 1

            filetools.rename(path_series_xml, "series.xml.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_xml)
            return False

    # Convertir libreria de v2(json) a v4
    if filetools.exists(path_series_json):
        try:
            data = jsontools.load_json(filetools.read(path_series_json))
            for tvshow in data:
                for channel in data[tvshow]["channels"]:
                    try:
                        serie = Item(contentSerieName=data[tvshow]["channels"][channel]["tvshow"],
                                     url=data[tvshow]["channels"][channel]["url"], channel=channel, action="episodios",
                                     title=data[tvshow]["name"], active=True)
                        if not tvshow.startswith("t_"):
                            serie.infoLabels["tmdb_id"] = tvshow

                        insertados, sobreescritos, fallidos = library.save_library_tvshow(serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification("Serie actualizada", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

            filetools.rename(path_series_json, "series.json.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_json)
            return False

    # Convertir libreria de v3 a v4
    if version != 'v4':
        # Obtenemos todos los tvshow.json de la biblioteca de SERIES_OLD recursivamente
        for raiz, subcarpetas, ficheros in filetools.walk(path_series_old):
            for f in ficheros:
                if f == "tvshow.json":
                    try:
                        serie = Item().fromjson(filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_tvshow(serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification("Serie actualizada", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

        movies_insertadas = 0
        movies_fallidas = 0
        for raiz, subcarpetas, ficheros in filetools.walk(path_cine_old):
            for f in ficheros:
                if f.endswith(".strm.json"):
                    try:
                        movie = Item().fromjson(filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_movie(movie)
                        if fallidos == 0:
                            movies_insertadas += 1
                            platformtools.dialog_notification("Película actualizada", movie.infoLabels['title'])
                        else:
                            movies_fallidas += 1
                    except:
                        movies_fallidas += 1

    config.set_setting("library_version", 'v4')

    platformtools.dialog_notification("Biblioteca actualizada al nuevo formato",
                                      "%s series convertidas y %s series descartadas.\n"
                                      "%s peliculas convertidas y %s peliculas descartadas."
                                      "A continuación se va a obtener la información de todos los episodios" %
                                      (series_insertadas, series_fallidas, movies_insertadas, movies_fallidas),
                                      time=12000)

    # Por ultimo limpia la libreria, por que las rutas anteriores ya no existen
    if config.is_xbmc():
      from platformcode import xbmc_library
      xbmc_library.clean()

    return True
Beispiel #8
0
def convert_old_to_v4():
    logger.info()
    path_series_xml = filetools.join(config.get_data_path(), "series.xml")
    path_series_json = filetools.join(config.get_data_path(), "series.json")
    series_insertadas = 0
    series_fallidas = 0
    version = 'v?'

    # Renombrar carpeta Series y crear una vacia
    import time
    new_name = str(time.time())
    path_series_old = filetools.join(library.LIBRARY_PATH,
                                     "SERIES_OLD_" + new_name)
    if filetools.rename(library.TVSHOWS_PATH, "SERIES_OLD_" + new_name):
        if not filetools.mkdir(library.TVSHOWS_PATH):
            logger.error(
                "ERROR, no se ha podido crear la nueva carpeta de SERIES")
            return False
    else:
        logger.error(
            "ERROR, no se ha podido renombrar la antigua carpeta de SERIES")
        return False

    path_cine_old = filetools.join(library.LIBRARY_PATH,
                                   "CINE_OLD_" + new_name)
    if filetools.rename(library.MOVIES_PATH, "CINE_OLD_" + new_name):
        if not filetools.mkdir(library.MOVIES_PATH):
            logger.error(
                "ERROR, no se ha podido crear la nueva carpeta de CINE")
            return False
    else:
        logger.error(
            "ERROR, no se ha podido renombrar la antigua carpeta de CINE")
        return False

    # Convertir libreria de v1(xml) a v4
    if filetools.exists(path_series_xml):
        try:
            data = filetools.read(path_series_xml)
            for line in data.splitlines():
                try:
                    aux = line.rstrip('\n').split(",")
                    tvshow = aux[0].strip()
                    url = aux[1].strip()
                    channel = aux[2].strip()

                    serie = Item(contentSerieName=tvshow,
                                 url=url,
                                 channel=channel,
                                 action="episodios",
                                 title=tvshow,
                                 active=True)

                    patron = "^(.+)[\s]\((\d{4})\)$"
                    matches = re.compile(patron, re.DOTALL).findall(
                        serie.contentSerieName)

                    if matches:
                        serie.infoLabels['title'] = matches[0][0]
                        serie.infoLabels['year'] = matches[0][1]
                    else:
                        serie.infoLabels['title'] = tvshow

                    insertados, sobreescritos, fallidos = library.save_library_tvshow(
                        serie, list())
                    if fallidos == 0:
                        series_insertadas += 1
                        platformtools.dialog_notification(
                            "Serie actualizada", serie.infoLabels['title'])
                    else:
                        series_fallidas += 1
                except:
                    series_fallidas += 1

            filetools.rename(path_series_xml, "series.xml.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_xml)
            return False

    # Convertir libreria de v2(json) a v4
    if filetools.exists(path_series_json):
        try:
            data = jsontools.load_json(filetools.read(path_series_json))
            for tvshow in data:
                for channel in data[tvshow]["channels"]:
                    try:
                        serie = Item(
                            contentSerieName=data[tvshow]["channels"][channel]
                            ["tvshow"],
                            url=data[tvshow]["channels"][channel]["url"],
                            channel=channel,
                            action="episodios",
                            title=data[tvshow]["name"],
                            active=True)
                        if not tvshow.startswith("t_"):
                            serie.infoLabels["tmdb_id"] = tvshow

                        insertados, sobreescritos, fallidos = library.save_library_tvshow(
                            serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification(
                                "Serie actualizada", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

            filetools.rename(path_series_json, "series.json.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_json)
            return False

    # Convertir libreria de v3 a v4
    if version != 'v4':
        # Obtenemos todos los tvshow.json de la biblioteca de SERIES_OLD recursivamente
        for raiz, subcarpetas, ficheros in filetools.walk(path_series_old):
            for f in ficheros:
                if f == "tvshow.json":
                    try:
                        serie = Item().fromjson(
                            filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_tvshow(
                            serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification(
                                "Serie actualizada", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

        movies_insertadas = 0
        movies_fallidas = 0
        for raiz, subcarpetas, ficheros in filetools.walk(path_cine_old):
            for f in ficheros:
                if f.endswith(".strm.json"):
                    try:
                        movie = Item().fromjson(
                            filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_movie(
                            movie)
                        if fallidos == 0:
                            movies_insertadas += 1
                            platformtools.dialog_notification(
                                "Película actualizada",
                                movie.infoLabels['title'])
                        else:
                            movies_fallidas += 1
                    except:
                        movies_fallidas += 1

    config.set_setting("library_version", 'v4')

    platformtools.dialog_notification(
        "Biblioteca actualizada al nuevo formato",
        "%s series convertidas y %s series descartadas.\n"
        "%s peliculas convertidas y %s peliculas descartadas."
        "A continuación se va a obtener la información de todos los episodios"
        % (series_insertadas, series_fallidas, movies_insertadas,
           movies_fallidas),
        time=12000)

    # Por ultimo limpia la libreria, por que las rutas anteriores ya no existen
    if config.is_xbmc():
        from platformcode import xbmc_library
        xbmc_library.clean()

    return True
Beispiel #9
0
def convert_old_to_v4():
    logger.info()
    path_series_xml = filetools.join(config.get_data_path(), "series.xml")
    path_series_json = filetools.join(config.get_data_path(), "series.json")
    series_insertadas = 0
    series_fallidas = 0
    version = 'v?'

    # Rename and create Series directory
    import time
    new_name = str(time.time())
    path_series_old = filetools.join(library.LIBRARY_PATH,
                                     "SERIES_OLD_" + new_name)
    if filetools.rename(library.TVSHOWS_PATH, "SERIES_OLD_" + new_name):
        if not filetools.mkdir(library.TVSHOWS_PATH):
            logger.error("ERROR, impossibile creare la directory SERIES")
            return False
    else:
        logger.error("ERROR,impossibile rinominare la directory SERIES")
        return False

    path_cine_old = filetools.join(library.LIBRARY_PATH,
                                   "CINE_OLD_" + new_name)
    if filetools.rename(library.MOVIES_PATH, "CINE_OLD_" + new_name):
        if not filetools.mkdir(library.MOVIES_PATH):
            logger.error("ERROR, impossibile creare la directory CINE")
            return False
    else:
        logger.error("ERROR, impossibile rinominare la directory CINE")
        return False

    # Convert library from v1 to v4 (xml)
    if filetools.exists(path_series_xml):
        try:
            data = filetools.read(path_series_xml)
            for line in data.splitlines():
                try:
                    aux = line.rstrip('\n').split(",")
                    tvshow = aux[0].strip()
                    url = aux[1].strip()
                    channel = aux[2].strip()

                    serie = Item(contentSerieName=tvshow,
                                 url=url,
                                 channel=channel,
                                 action="episodios",
                                 title=tvshow,
                                 active=True)

                    patron = "^(.+)[\s]\((\d{4})\)$"
                    matches = re.compile(patron, re.DOTALL).findall(
                        serie.contentSerieName)

                    if matches:
                        serie.infoLabels['title'] = matches[0][0]
                        serie.infoLabels['year'] = matches[0][1]
                    else:
                        serie.infoLabels['title'] = tvshow

                    insertados, sobreescritos, fallidos = library.save_library_tvshow(
                        serie, list())
                    if fallidos == 0:
                        series_insertadas += 1
                        platformtools.dialog_notification(
                            "Serie aggiornata", serie.infoLabels['title'])
                    else:
                        series_fallidas += 1
                except:
                    series_fallidas += 1

            filetools.rename(path_series_xml, "series.xml.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_xml)
            return False

    # Convert library from v2 to v4 (json)
    if filetools.exists(path_series_json):
        try:
            data = jsontools.load_json(filetools.read(path_series_json))
            for tvshow in data:
                for channel in data[tvshow]["channels"]:
                    try:
                        serie = Item(
                            contentSerieName=data[tvshow]["channels"][channel]
                            ["tvshow"],
                            url=data[tvshow]["channels"][channel]["url"],
                            channel=channel,
                            action="episodios",
                            title=data[tvshow]["name"],
                            active=True)
                        if not tvshow.startswith("t_"):
                            serie.infoLabels["tmdb_id"] = tvshow

                        insertados, sobreescritos, fallidos = library.save_library_tvshow(
                            serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification(
                                "Serie aggiornata", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

            filetools.rename(path_series_json, "series.json.old")
            version = 'v4'

        except EnvironmentError:
            logger.error("ERROR al leer el archivo: %s" % path_series_json)
            return False

    # Convert library from v2 to v4
    if version != 'v4':
        # Get old Series recursively
        for raiz, subcarpetas, ficheros in filetools.walk(path_series_old):
            for f in ficheros:
                if f == "tvshow.json":
                    try:
                        serie = Item().fromjson(
                            filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_tvshow(
                            serie, list())
                        if fallidos == 0:
                            series_insertadas += 1
                            platformtools.dialog_notification(
                                "Serie aggiornata", serie.infoLabels['title'])
                        else:
                            series_fallidas += 1
                    except:
                        series_fallidas += 1

        movies_insertadas = 0
        movies_fallidas = 0
        for raiz, subcarpetas, ficheros in filetools.walk(path_cine_old):
            for f in ficheros:
                if f.endswith(".strm.json"):
                    try:
                        movie = Item().fromjson(
                            filetools.read(filetools.join(raiz, f)))
                        insertados, sobreescritos, fallidos = library.save_library_movie(
                            movie)
                        if fallidos == 0:
                            movies_insertadas += 1
                            platformtools.dialog_notification(
                                "Film aggiornato", movie.infoLabels['title'])
                        else:
                            movies_fallidas += 1
                    except:
                        movies_fallidas += 1

    config.set_setting("library_version", 'v4')

    platformtools.dialog_notification(
        "Libreria aggiornata con il nuovo formato",
        "%s serie convertite e %s serie scaricate. Continuare per"
        "ottenere le info sugli episodi" %
        (series_insertadas, series_fallidas),
        time=12000)

    # Cleanup library of empty records
    if config.is_xbmc():
        from platformcode import xbmc_library
        xbmc_library.clean()

    return True