def update(folder_content=config.get_setting("folder_tvshows"), folder=""): """ Actualiza la libreria dependiendo del tipo de contenido y la ruta que se le pase. @type folder_content: str @param folder_content: tipo de contenido para actualizar, series o peliculas @type folder: str @param folder: nombre de la carpeta a escanear. """ logger.info(folder) payload = {"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": 1} if folder: folder = str(folder) videolibrarypath = config.get_videolibrary_config_path() if folder.endswith('/') or folder.endswith('\\'): folder = folder[:-1] update_path = None if videolibrarypath.startswith("special:"): if videolibrarypath.endswith('/'): videolibrarypath = videolibrarypath[:-1] update_path = videolibrarypath + "/" + folder_content + "/" + folder + "/" else: #update_path = filetools.join(videolibrarypath, folder_content, folder) + "/" # Problemas de encode en "folder" update_path = filetools.join(videolibrarypath, folder_content, ' ').rstrip() if not scrapertools.find_single_match(update_path, '(^\w+:\/\/)'): payload["params"] = {"directory": update_path} """while xbmc.getCondVisibility('Library.IsScanningVideo()'):
def verify_directories_created(): from dependencies import logger, filetools, xbmc_videolibrary config_paths = [["videolibrarypath", "videolibrary"], ["downloadpath", "downloads"], ["downloadlistpath", "downloads/list"], ["settings_path", "settings_channels"]] for path, default in config_paths: saved_path = get_setting(path) # videoteca if path == "videolibrarypath": if not saved_path: saved_path = xbmc_videolibrary.search_library_path() if saved_path: set_setting(path, saved_path) if not saved_path: saved_path = "special://profile/addon_data/plugin.video." + PLUGIN_NAME + "/" + default set_setting(path, saved_path) saved_path = xbmc.translatePath(saved_path) if not filetools.exists(saved_path): logger.debug("Creating %s: %s" % (path, saved_path)) filetools.mkdir(saved_path) config_paths = [["folder_movies", "CINE"], ["folder_tvshows", "SERIES"]] for path, default in config_paths: saved_path = get_setting(path) if not saved_path: saved_path = default set_setting(path, saved_path) content_path = filetools.join(get_videolibrary_path(), saved_path) if not filetools.exists(content_path): logger.debug("Creating %s: %s" % (path, content_path)) # si se crea el directorio filetools.mkdir(content_path) from dependencies import xbmc_videolibrary xbmc_videolibrary.update_sources(get_setting("videolibrarypath")) xbmc_videolibrary.update_sources(get_setting("downloadpath")) try: from dependencies import scrapertools # Buscamos el archivo addon.xml del skin activo skindir = filetools.join(xbmc.translatePath("special://home"), 'addons', xbmc.getSkinDir(), 'addon.xml') if not os.path.isdir(skindir): return # No hace falta mostrar error en el log si no existe la carpeta # Extraemos el nombre de la carpeta de resolución por defecto folder = "" data = filetools.read(skindir) res = scrapertools.find_multiple_matches(data, '(<res .*?>)') for r in res: if 'default="true"' in r: folder = scrapertools.find_single_match(r, 'folder="([^"]+)"') break # Comprobamos si existe en el addon y sino es así, la creamos default = filetools.join(get_runtime_path(), 'resources', 'skins', 'Default') if folder and not filetools.exists(filetools.join(default, folder)): filetools.mkdir(filetools.join(default, folder)) # Copiamos el archivo a dicha carpeta desde la de 720p si éste no existe o si el tamaño es diferente if folder and folder != '720p': for root, folders, files in filetools.walk( filetools.join(default, '720p')): for f in files: if not filetools.exists(filetools.join(default, folder, f)) or \ (filetools.getsize(filetools.join(default, folder, f)) != filetools.getsize(filetools.join(default, '720p', f))): filetools.copy(filetools.join(default, '720p', f), filetools.join(default, folder, f), True) except: import traceback logger.error("Al comprobar o crear la carpeta de resolución") logger.error(traceback.format_exc())
def updateFromZip(message=config.get_localized_string(80050)): dp = platformtools.dialog_progress_bg(config.get_localized_string(20000), message) dp.update(0) remotefilename = 'https://github.com/' + user + "/" + repo + "/archive/" + branch + ".zip" localfilename = filetools.join(xbmc.translatePath("special://home/addons/"), "plugin.video.kod.update.zip") destpathname = xbmc.translatePath("special://home/addons/") extractedDir = filetools.join(destpathname, "addon-" + branch) logger.info("remotefilename=%s" % remotefilename) logger.info("localfilename=%s" % localfilename) logger.info('extract dir: ' + extractedDir) # pulizia preliminare remove(localfilename) removeTree(extractedDir) try: urllib.urlretrieve(remotefilename, localfilename, lambda nb, bs, fs, url=remotefilename: _pbhook(nb, bs, fs, url, dp)) except Exception as e: platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(80031)) logger.info('Non sono riuscito a scaricare il file zip') logger.info(e) dp.close() return False # Lo descomprime logger.info("decompressione...") logger.info("destpathname=%s" % destpathname) if os.path.isfile(localfilename): logger.info('il file esiste') dp.update(80, config.get_localized_string(20000), config.get_localized_string(80032)) import zipfile try: hash = fixZipGetHash(localfilename) logger.info(hash) with zipfile.ZipFile(fOpen(localfilename, 'rb')) as zip: size = sum([zinfo.file_size for zinfo in zip.filelist]) cur_size = 0 for member in zip.infolist(): zip.extract(member, destpathname) cur_size += member.file_size dp.update(int(80 + cur_size * 15 / size)) except Exception as e: logger.info('Non sono riuscito ad estrarre il file zip') logger.error(e) import traceback logger.error(traceback.print_exc()) dp.close() remove(localfilename) return False dp.update(95) # puliamo tutto global addonDir if extractedDir != addonDir: removeTree(addonDir) xbmc.sleep(1000) rename(extractedDir, 'plugin.video.kod') addonDir = filetools.join(destpathname, 'plugin.video.kod') logger.info("Cancellando il file zip...") remove(localfilename) dp.update(100) xbmc.sleep(1000) dp.close() xbmc.executebuiltin("UpdateLocalAddons") # in run() # refreshLang() return hash
def ask_set_content(silent=False): logger.debug() logger.debug("videolibrary_kodi %s" % config.get_setting("videolibrary_kodi")) def do_config(custom=False): if set_content("movie", True, custom) and set_content( "tvshow", True, custom): platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(70104)) config.set_setting("videolibrary_kodi", True) update() else: platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(80024)) config.set_setting("videolibrary_kodi", False) # configuration during installation if not silent: # ask to configure Kodi video library if platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80015)): # ask for custom or default settings if not platformtools.dialog_yesno( config.get_localized_string(80026), config.get_localized_string(80016), config.get_localized_string(80017), config.get_localized_string(80018)): # input path and folders path = platformtools.dialog_browse( 3, config.get_localized_string(80019), config.get_setting("videolibrarypath")) movies_folder = platformtools.dialog_input( config.get_setting("folder_movies"), config.get_localized_string(80020)) tvshows_folder = platformtools.dialog_input( config.get_setting("folder_tvshows"), config.get_localized_string(80021)) if path != "" and movies_folder != "" and tvshows_folder != "": movies_path, tvshows_path = check_sources( filetools.join(path, movies_folder), filetools.join(path, tvshows_folder)) # configure later if movies_path or tvshows_path: platformtools.dialog_ok( config.get_localized_string(80026), config.get_localized_string(80029)) # set path and folders else: update_sources(path, config.get_setting("videolibrarypath")) config.set_setting("videolibrarypath", path) config.set_setting("folder_movies", movies_folder) config.set_setting("folder_tvshows", tvshows_folder) config.verify_directories_created() do_config(False) # default path and folders else: platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(80030)) do_config(False) # default settings else: platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(80027)) do_config(False) # configure later else: platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(80022)) # configuration from the settings menu else: platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(80023)) do_config(False)
def execute_sql_kodi(sql): """ Run sql query against kodi database @param sql: Valid sql query @type sql: str @return: Number of records modified or returned by the query @rtype nun_records: int @return: list with the query result @rtype records: list of tuples """ logger.info() file_db = "" nun_records = 0 records = None # We look for the archive of the video database according to the version of kodi video_db = config.get_platform(True)['video_db'] if video_db: file_db = filetools.join( xbmc.translatePath("special://userdata/Database"), video_db) # alternative method to locate the database if not file_db or not filetools.exists(file_db): file_db = "" for f in filetools.listdir( xbmc.translatePath("special://userdata/Database")): path_f = filetools.join( xbmc.translatePath("special://userdata/Database"), f) if filetools.isfile(path_f) and f.lower().startswith( 'myvideos') and f.lower().endswith('.db'): file_db = path_f break if file_db: logger.info("DB file: %s" % file_db) conn = None try: import sqlite3 conn = sqlite3.connect(file_db) cursor = conn.cursor() logger.info("Running sql: %s" % sql) cursor.execute(sql) conn.commit() records = cursor.fetchall() if sql.lower().startswith("select"): nun_records = len(records) if nun_records == 1 and records[0][0] is None: nun_records = 0 records = [] else: nun_records = conn.total_changes conn.close() logger.info("Query executed. Records: %s" % nun_records) except: logger.error("Error executing sql query") if conn: conn.close() else: logger.info("Database not found") return nun_records, records