def move_to_libray(item): download_path = filetools.join(config.get_setting("downloadpath"), item.downloadFilename) library_path = filetools.join(config.get_videolibrary_path(), *filetools.split(item.downloadFilename)) final_path = download_path if config.get_setting("library_add", "downloads") == True and config.get_setting("library_move", "downloads") == 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", "downloads") == True: if filetools.isfile(final_path): if item.contentType == "movie" and item.infoLabels["tmdb_id"]: library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", action="findvideos", infoLabels=item.infoLabels, url=final_path) videolibrarytools.save_movie(library_item) elif item.contentType == "episode" and item.infoLabels["tmdb_id"]: library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", action="findvideos", infoLabels=item.infoLabels, url=final_path) tvshow = Item(channel="downloads", contentType="tvshow", infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]}) videolibrarytools.save_tvshow(tvshow, [library_item])
def add_file_cine_library(item): from core import videolibrarytools new_item = item.clone(title=item.show, action="play_from_library") videolibrarytools.save_movie(new_item) itemlist = [] itemlist.append( Item(title='El vídeo ' + item.show + ' se ha añadido a la videoteca')) # xbmctools.renderItems(itemlist, "", "", "") platformtools.render_items(itemlist, "") return
def overwrite_tools(item): import videolibrary_service from core import videolibrarytools seleccion = platformtools.dialog_yesno(config.get_localized_string(60581), config.get_localized_string(60582), config.get_localized_string(60583)) if seleccion == 1: # tvshows heading = config.get_localized_string(60584) p_dialog = platformtools.dialog_progress_bg( config.get_localized_string(60585), 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) path = filetools.dirname(tvshow_file) if not serie.active: # si la serie no esta activa descartar continue # Eliminamos la carpeta con la serie ... filetools.rmdirtree(path) # ... y la volvemos a añadir videolibrary_service.update(path, p_dialog, i, t, serie, 3) p_dialog.close() # movies heading = config.get_localized_string(60586) p_dialog2 = platformtools.dialog_progress_bg( config.get_localized_string(60585), heading) p_dialog2.update(0, '') movies_list = [] for path, folders, files in filetools.walk( videolibrarytools.MOVIES_PATH): movies_list.extend([ filetools.join(path, f) for f in files if f.endswith(".json") ]) logger.debug("movies_list %s" % movies_list) if movies_list: t = float(100) / len(movies_list) for i, movie_json in enumerate(movies_list): try: from core import jsontools path = filetools.dirname(movie_json) movie = Item().fromjson(filetools.read(movie_json)) # Eliminamos la carpeta con la pelicula ... filetools.rmdirtree(path) import math heading = config.get_localized_string(60587) p_dialog2.update( int(math.ceil((i + 1) * t)), heading, "%s: %s" % (movie.contentTitle, movie.channel.capitalize())) # ... y la volvemos a añadir videolibrarytools.save_movie(movie) except Exception, ex: logger.error("Error al crear de nuevo la película") template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(message) p_dialog2.close()
def move_to_libray(item): if item.contentType == 'movie': FOLDER = FOLDER_MOVIES path_title = "%s [%s]" % (item.contentTitle.strip(), item.infoLabels['IMDBNumber']) move_path = filetools.join(config.get_videolibrary_path(), FOLDER, path_title) else: FOLDER = FOLDER_TVSHOWS path_title = "%s [%s]" % (item.contentSerieName, item.infoLabels['IMDBNumber']) move_path = filetools.join(config.get_videolibrary_path(), FOLDER) download_path = filetools.join(config.get_setting("downloadpath"), item.downloadFilename) library_path = filetools.join(move_path, *filetools.split(item.downloadFilename)) final_path = download_path if config.get_setting("library_add", "downloads") == True and config.get_setting( "library_move", "downloads") == 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)) logger.info('ITEM = ' + str(item)) name = item.contentTitle if item.contentType == 'movie' else str( item.infoLabels['season']) + 'x' + str( item.infoLabels['episode']).zfill(2) list_item = os.listdir( filetools.join(config.get_videolibrary_path(), FOLDER, path_title)) clean = False for File in list_item: filename = File.lower() name = name.lower() if filename.startswith(name) and (filename.endswith('.strm') or filename.endswith('.json') or filename.endswith('.nfo')): clean = True logger.info('Delete File: ' + str( os.path.join(config.get_videolibrary_path(), FOLDER, path_title, File))) os.remove( os.path.join(config.get_videolibrary_path(), FOLDER, path_title, File)) from platformcode import xbmc_videolibrary xbmc_videolibrary.update(FOLDER) if clean == True: import xbmc while xbmc.getCondVisibility('Library.IsScanningVideo()'): xbmc.sleep(500) xbmc_videolibrary.clean() if config.get_setting("library_add", "downloads") == True and config.get_setting( "library_move", "downloads") == False: if filetools.isfile(final_path): if item.contentType == "movie" and item.infoLabels["tmdb_id"]: library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", action="findvideos", infoLabels=item.infoLabels, url=final_path) videolibrarytools.save_movie(library_item) elif item.contentType == "episode" and item.infoLabels["tmdb_id"]: library_item = Item(title=config.get_localized_string(70228) % item.downloadFilename, channel="downloads", action="findvideos", infoLabels=item.infoLabels, url=final_path) tvshow = Item( channel="downloads", contentType="tvshow", infoLabels={"tmdb_id": item.infoLabels["tmdb_id"]}) videolibrarytools.save_tvshow(tvshow, [library_item])