def start(): logger.info("server init...") config.verify_directories_created() try: HTTPAndWSServer.start(show_info) # Da por levantado el servicio logger.info("--------------------------------------------------------------------") logger.info("kod %s Iniciado" %version) logger.info("La URL para acceder es http://%s:%s" % (myip, http_port)) logger.info("--------------------------------------------------------------------") logger.info("Runtime Path : " + config.get_runtime_path()) logger.info("Data Path : " + config.get_data_path()) logger.info("Download Path : " + config.get_setting("downloadpath")) logger.info("DownloadList Path : " + config.get_setting("downloadlistpath")) logger.info("Bookmark Path : " + config.get_setting("bookmarkpath")) logger.info("VideoLibrary Path : " + config.get_setting("videolibrarypath")) logger.info("--------------------------------------------------------------------") show_info() # Identifica la dirección Proxy y la lista de alternativas from core import proxytools proxytools.get_proxy_list() flag = True while flag: time.sleep(1) except KeyboardInterrupt: print 'Deteniendo el servidor HTTP...' HTTPAndWSServer.stop() print 'kod Detenido' flag = False
def start(): logger.info("server init...") config.verify_directories_created() try: HTTPServer.start(MostrarInfo) WebSocket.start(MostrarInfo) # Da por levantado el servicio logger.info("--------------------------------------------------------------------") logger.info("Alfa Iniciado") logger.info("La URL para acceder es http://%s:%s" % (myip, http_port)) logger.info("WebSocket Server iniciado en ws://%s:%s" % (myip, websocket_port)) logger.info("--------------------------------------------------------------------") logger.info("Runtime Path : " + config.get_runtime_path()) logger.info("Data Path : " + config.get_data_path()) logger.info("Download Path : " + config.get_setting("downloadpath")) logger.info("DownloadList Path : " + config.get_setting("downloadlistpath")) logger.info("Bookmark Path : " + config.get_setting("bookmarkpath")) logger.info("VideoLibrary Path : " + config.get_setting("videolibrarypath")) logger.info("--------------------------------------------------------------------") MostrarInfo() start = True while start: time.sleep(1) except KeyboardInterrupt: print 'Deteniendo el servidor HTTP...' HTTPServer.stop() print 'Deteniendo el servidor WebSocket...' WebSocket.stop() print 'Alfa Detenido' start = False
def start(): """ Primera funcion que se ejecuta al entrar en el plugin. Dentro de esta funcion deberian ir todas las llamadas a las funciones que deseamos que se ejecuten nada mas abrir el plugin. """ logger.info() #config.set_setting('show_once', True) # Test if all the required directories are created config.verify_directories_created()
def start(): """ Primera funcion que se ejecuta al entrar en el plugin. Dentro de esta funcion deberian ir todas las llamadas a las funciones que deseamos que se ejecuten nada mas abrir el plugin. """ logger.info() # Test if all the required directories are created config.verify_directories_created() import videolibrary_service videolibrary_service.start()
def import_videolibrary(item): logger.info() zip_file = platformtools.dialog_browse(1, config.get_localized_string(80005)) if zip_file == "": return if not platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80006)): return p_dialog = platformtools.dialog_progress_bg( config.get_localized_string(20000), config.get_localized_string(80007)) p_dialog.update(0) if filetools.exists(temp_path): filetools.rmdirtree(temp_path) filetools.mkdir(temp_path) unzipper = ziptools.ziptools() unzipper.extract(zip_file, temp_path) p_dialog.update(25) filetools.rmdirtree(videolibrarytools.VIDEOLIBRARY_PATH) p_dialog.update(50) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc.sleep(5000) xbmc_videolibrary.clean() config.verify_directories_created() if filetools.exists(movies_path): copy_tree(movies_path, videolibrarytools.MOVIES_PATH) p_dialog.update(70) if filetools.exists(tvshows_path): copy_tree(tvshows_path, videolibrarytools.TVSHOWS_PATH) p_dialog.update(90) filetools.rmdirtree(temp_path) p_dialog.update(100) xbmc.sleep(2000) p_dialog.close() platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(80008)) if platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80009)): import service service.check_for_update(overwrite=True) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.update()
def import_videolibrary(item): logger.info() zip_file = unicode( platformtools.dialog_browse(1, config.get_localized_string(80005), mask=".zip")) if zip_file == "": return if not platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80006)): return p_dialog = platformtools.dialog_progress_bg( config.get_localized_string(20000), config.get_localized_string(80007)) # p_dialog.update(0) if filetools.exists(temp_path): shutil.rmtree(temp_path) filetools.mkdir(videolibrary_temp_path) unzip(videolibrary_temp_path, zip_file) p_dialog.update(20) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.clean() p_dialog.update(30) shutil.rmtree(videolibrary_movies_path) shutil.rmtree(videolibrary_tvshows_path) p_dialog.update(50) config.verify_directories_created() if filetools.exists(movies_path): copy_tree(movies_path, videolibrary_movies_path) p_dialog.update(70) if filetools.exists(tvshows_path): copy_tree(tvshows_path, videolibrary_tvshows_path) p_dialog.update(90) shutil.rmtree(temp_path) p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80008), time=5000, sound=False) videolibrary.update_videolibrary() if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.update()
def start(): logger.info("server init {}...".format(sys.version_info[0:2])) config.verify_directories_created() if PY3: from platformcode import custom_code custom_code.marshal_check() try: HTTPAndWSServer.start(show_info) # Da por levantado el servicio logger.info( "--------------------------------------------------------------------" ) logger.info("Alfa %s Iniciado" % version) logger.info("La URL para acceder es http://%s:%s" % (myip, http_port)) logger.info( "--------------------------------------------------------------------" ) logger.info("Runtime Path : " + config.get_runtime_path()) logger.info("Data Path : " + config.get_data_path()) logger.info("Download Path : " + config.get_setting("downloadpath")) logger.info("DownloadList Path : " + config.get_setting("downloadlistpath")) logger.info("Bookmark Path : " + config.get_setting("bookmarkpath")) logger.info("VideoLibrary Path : " + config.get_setting("videolibrarypath")) logger.info( "--------------------------------------------------------------------" ) show_info() # Identifica la dirección Proxy y la lista de alternativas if not PY3: from core import proxytools else: from core import proxytools_py3 as proxytools proxytools.get_proxy_list() flag = True while flag: time.sleep(1) except KeyboardInterrupt: print('Deteniendo el servidor HTTP...') HTTPAndWSServer.stop() print('Alfa Detenido') flag = False
def start(): """ Primera funcion que se ejecuta al entrar en el plugin. Dentro de esta funcion deberian ir todas las llamadas a las funciones que deseamos que se ejecuten nada mas abrir el plugin. """ logger.info() # if config.get_platform(True)['num_version'] >= 19: # from core import filetools # origin = filetools.join(config.get_runtime_path(), "resources", "settings_matrix.xml") # destination = filetools.join(config.get_runtime_path(), "resources", "settings.xml") # if filetools.exists(origin): # filetools.move(origin, destination, silent=True) #config.set_setting('show_once', True) # Test if all the required directories are created config.verify_directories_created()
def start(): """ Primera funcion que se ejecuta al entrar en el plugin. Dentro de esta funcion deberian ir todas las llamadas a las funciones que deseamos que se ejecuten nada mas abrir el plugin. """ logger.info() #config.set_setting('show_once', True) # Test if all the required directories are created config.verify_directories_created() # controlla se l'utente ha qualche problema di connessione # se lo ha: non lo fa entrare nell'addon # se ha problemi di DNS avvia ma lascia entrare # se tutto ok: entra nell'addon from specials.checkhost import test_conn import threading threading.Thread(target=test_conn, args=(True, True, True, [], [], True)).start()
def import_videolibrary(item): logger.info() zip_file = platformtools.dialog_browse(1, config.get_localized_string(80005)) if zip_file == "": return if not platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80006)): return p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80007)) p_dialog.update(0) if filetools.exists(temp_path): filetools.rmdirtree(temp_path) filetools.mkdir(temp_path) unzipper = ziptools.ziptools() unzipper.extract(zip_file, temp_path) p_dialog.update(20) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.clean() p_dialog.update(30) filetools.rmdirtree(videolibrarytools.MOVIES_PATH) filetools.rmdirtree(videolibrarytools.TVSHOWS_PATH) p_dialog.update(50) config.verify_directories_created() if filetools.exists(movies_path): copy_tree(movies_path, videolibrarytools.MOVIES_PATH) p_dialog.update(70) if filetools.exists(tvshows_path): copy_tree(tvshows_path, videolibrarytools.TVSHOWS_PATH) p_dialog.update(90) filetools.rmdirtree(temp_path) p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80008), time=5000, sound=False) videolibrary.update_videolibrary() if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.update()
def start(): """ First function that is executed when entering the plugin. Within this function all calls should go to functions that we want to execute as soon as we open the plugin. """ logger.debug() # config.set_setting('show_once', True) # Test if all the required directories are created config.verify_directories_created() # check if the user has any connection problems # if it has: it does not enter the addon # if it has DNS problems start but let in # if everything is ok: enter the addon from platformcode.checkhost import test_conn import threading threading.Thread(target=test_conn, args=(True, not config.get_setting('resolver_dns'), True, [], [], True)).start() if not config.dev_mode(): from platformcode import updater updater.showSavedChangelog()
def delete_videolibrary(item): logger.info() if not platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(80037)): return p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80038)) p_dialog.update(0) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): from platformcode import xbmc_videolibrary xbmc_videolibrary.clean() p_dialog.update(10) filetools.rmdirtree(videolibrarytools.MOVIES_PATH) p_dialog.update(50) filetools.rmdirtree(videolibrarytools.TVSHOWS_PATH) p_dialog.update(90) config.verify_directories_created() p_dialog.update(100) xbmc.sleep(1000) p_dialog.close() platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80039), time=5000, sound=False)
from core import scraper from core import scrapertools from core.item import Item from platformcode import config, logger from platformcode import platformtools from lib import generictools FOLDER_MOVIES = config.get_setting("folder_movies") FOLDER_TVSHOWS = config.get_setting("folder_tvshows") VIDEOLIBRARY_PATH = config.get_videolibrary_path() MOVIES_PATH = filetools.join(VIDEOLIBRARY_PATH, FOLDER_MOVIES) TVSHOWS_PATH = filetools.join(VIDEOLIBRARY_PATH, FOLDER_TVSHOWS) if not FOLDER_MOVIES or not FOLDER_TVSHOWS or not VIDEOLIBRARY_PATH \ or not filetools.exists(MOVIES_PATH) or not filetools.exists(TVSHOWS_PATH): config.verify_directories_created() addon_name = "plugin://plugin.video.%s/" % config.PLUGIN_NAME def read_nfo(path_nfo, item=None): """ Metodo para leer archivos nfo. Los arcivos nfo tienen la siguiente extructura: url_scraper | xml + item_json [url_scraper] y [xml] son opcionales, pero solo uno de ellos ha de existir siempre. @param path_nfo: ruta absoluta al archivo nfo @type path_nfo: str @param item: Si se pasa este parametro el item devuelto sera una copia de este con los valores de 'infoLabels', 'library_playcounts' y 'path' leidos del nfo @type: Item @return: Una tupla formada por la cabecera (head_nfo ='url_scraper'|'xml') y el objeto 'item_json'
def move_videolibrary(current_path, new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder): logger.info() backup_current_path = current_path backup_new_path = new_path logger.info('current_path: ' + current_path) logger.info('new_path: ' + new_path) logger.info('current_movies_folder: ' + current_movies_folder) logger.info('new_movies_folder: ' + new_movies_folder) logger.info('current_tvshows_folder: ' + current_tvshows_folder) logger.info('new_tvshows_folder: ' + new_tvshows_folder) notify = False progress = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80011)) current_path = u'' + xbmc.translatePath(current_path) new_path = u'' + xbmc.translatePath(new_path) current_movies_path = u'' + filetools.join(current_path, current_movies_folder) new_movies_path = u'' + filetools.join(new_path, new_movies_folder) current_tvshows_path = u'' + filetools.join(current_path, current_tvshows_folder) new_tvshows_path = u'' + filetools.join(new_path, new_tvshows_folder) logger.info('current_movies_path: ' + current_movies_path) logger.info('new_movies_path: ' + new_movies_path) logger.info('current_tvshows_path: ' + current_tvshows_path) logger.info('new_tvshows_path: ' + new_tvshows_path) from platformcode import xbmc_videolibrary movies_path, tvshows_path = xbmc_videolibrary.check_sources(new_movies_path, new_tvshows_path) logger.info('check_sources: ' + str(movies_path) + ', ' + str(tvshows_path)) if movies_path or tvshows_path: if not movies_path: filetools.rmdir(new_movies_path) if not tvshows_path: filetools.rmdir(new_tvshows_path) config.set_setting("videolibrarypath", backup_current_path) config.set_setting("folder_movies", current_movies_folder) config.set_setting("folder_tvshows", current_tvshows_folder) xbmc_videolibrary.update_sources(backup_current_path, backup_new_path) progress.update(100) xbmc.sleep(1000) progress.close() platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(80028)) return config.verify_directories_created() progress.update(10, config.get_localized_string(20000) + '\n' + config.get_localized_string(80012)) if current_movies_path != new_movies_path: if filetools.listdir(current_movies_path): dir_util.copy_tree(current_movies_path, new_movies_path) notify = True filetools.rmdirtree(current_movies_path) progress.update(40) if current_tvshows_path != new_tvshows_path: if filetools.listdir(current_tvshows_path): dir_util.copy_tree(current_tvshows_path, new_tvshows_path) notify = True filetools.rmdirtree(current_tvshows_path) progress.update(70) if current_path != new_path and not filetools.listdir(current_path) and not "plugin.video.kod\\videolibrary" in current_path: filetools.rmdirtree(current_path) xbmc_videolibrary.update_sources(backup_new_path, backup_current_path) if config.is_xbmc() and config.get_setting("videolibrary_kodi"): xbmc_videolibrary.update_db(backup_current_path, backup_new_path, current_movies_folder, new_movies_folder, current_tvshows_folder, new_tvshows_folder, progress) else: progress.update(100) xbmc.sleep(1000) progress.close() if notify: platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(80014), time=5000, sound=False)
def init(): logger.info() """ Todo el código añadido al add-on se borra con cada actualización. Esta función permite restaurarlo automáticamente con cada actualización. Esto permite al usuario tener su propio código, bajo su responsabilidad, y restaurarlo al add-on cada vez que se actualiza. El mecanismo funciona copiando el contenido de la carpeta-arbol "./userdata/addon_data/plugin.video.alfa/custom_code/..." sobre las carpetas de código del add-on. No verifica el contenido, solo vuelca(reemplaza) el contenido de "custom_code". El usuario almacenará en las subcarpetas de "custom_code" su código actualizado y listo para ser copiado en cualquier momento. Si no se desea que copie algo, simplemente se borra de "custom_code" y ya no se copiará en la próxima actualización. Los pasos que sigue esta función, son los siguientes: 1.- La función se llama desde videolibrary_service.py, desde la función inicial: # Copia Custom code a las carpetas de Alfa desde la zona de Userdata from platformcode import custom_code custom_code.init() 2.- En el inicio de Kodi, comprueba si existe la carpeta "custom_code" en "./userdata/addon_data/plugin.video.alfa/". Si no existe, la crea y sale sin más, dando al ususario la posibilidad de copiar sobre esa estructura su código, y que la función la vuelque sobre el add-on en el próximo inicio de Kodi. 3.- En el siguiente inicio de Kodi, comprueba si existe el custom_code.json en la carpeta root del add-on. Si no existe, lo crea con el número de versión del add-on vacío, para permitir que se copien los archivos en esta pasada. 4.- Verifica que el número de versión del add-on es diferente de el de custom_code.json. Si es la misma versión, se sale porque ya se realizo la copia anteriormente. Si la versión es distinta, se realiza el volcado de todos los archivos de la carpeta-árbol "custom_code" sobre el add-on. Si la carpeta de destino no existe, dará un error y se cancelará la copia. Se considera que no tienen sentido nuevas carpetas. 5.- Si la copia ha terminado con éxito, se actualiza el custom_code.json con el número de versión del add-on, para que en inicios sucesivos de Kodi no se realicen las copias, hasta que el add-on cambie de versión. En el número de versión del add-on no se considera el número de fix. Tiempos: Copiando 7 archivos de prueba, el proceso ha tardado una décima de segundo. """ try: #Limpiamos los mensajes de ayuda obsoletos y restauramos los que tienen "version": True. Por cada nueva versión if not filetools.exists(ADDON_CUSTOMCODE_JSON): from platformcode import help_window help_window.clean_watched_new_version() #Se realizan algunas funciones con cada nueva versión de Alfa if not filetools.exists(ADDON_CUSTOMCODE_JSON): config.set_setting('cf_assistant_ua', '') # Se limpia CF_UA. Mejora de rendimiento en httptools CF #Se verifica si están bien las rutas a la videoteca config.verify_directories_created() #Comprime la BD de cache de TMDB para evitar que crezca demasiado bd_tmdb_maintenance() if config.get_setting('tmdb_cache_expire', default=4) == 4: config.set_setting('tmdb_cache_expire', 2) #Borra el .zip de instalación de Alfa de la carpeta Packages, por si está corrupto, y que así se pueda descargar de nuevo #version = 'plugin.video.alfa-%s.zip' % ADDON_VERSION #filetools.remove(filetools.join('special://home', 'addons', 'packages', version), True) #Verifica si es necesario instalar script.alfa-update-helper verify_script_alfa_update_helper() #Borrar contenido de carpeta de Torrents y de Subtitles filetools.rmdirtree(filetools.join(config.get_videolibrary_path(), 'temp_torrents_arch'), silent=True) filetools.rmdirtree(filetools.join(config.get_videolibrary_path(), 'temp_torrents_Alfa'), silent=True) subtitle_path = config.get_kodi_setting("subtitles.custompath") if subtitle_path and filetools.exists(subtitle_path): for file in filetools.listdir(subtitle_path): if not file.endswith('.srt'): continue file_path = filetools.join(subtitle_path, file) ret = filetools.remove(file_path, silent=True) if not ret: logger.error('ERROR on REMOVING subtitle: ' + file_path) #Verifica si Kodi tiene algún achivo de Base de Datos de Vídeo de versiones anteriores, entonces los borra verify_Kodi_video_DB() #Verifica si la Base de Datos de Vídeo tiene la fuente de CINE con useFolderNames=1 try: threading.Thread(target=set_Kodi_video_DB_useFolderNames).start() # Creamos un Thread independiente por si la DB está Scanning time.sleep(1) # Dejamos terminar la inicialización... except: # Si hay problemas de threading, nos vamos logger.error(traceback.format_exc()) #LIBTORRENT: se descarga el binario de Libtorrent cada vez que se actualiza Alfa update_libtorrent() #TORREST: Modificaciones temporales if xbmc.getCondVisibility('System.HasAddon("plugin.video.torrest")'): try: __settings__ = xbmcaddon.Addon(id="plugin.video.torrest") if __settings__.getSetting("s:check_available_space") == 'true': __settings__.setSetting("s:check_available_space", "false") # No comprobar espacio disponible hasta que lo arreglen #if not filetools.exists(filetools.join(config.get_data_path(), "quasar.json")) \ # and not config.get_setting('addon_quasar_update', default=False): # question_update_external_addon("torrest") except: pass #QUASAR: Preguntamos si se hacen modificaciones a Quasar if not filetools.exists(filetools.join(config.get_data_path(), "quasar.json")) \ and not config.get_setting('addon_quasar_update', default=False): question_update_external_addon("quasar") #QUASAR: Hacemos las modificaciones a Quasar, si está permitido, y si está instalado if config.get_setting('addon_quasar_update', default=False) or \ (filetools.exists(filetools.join(config.get_data_path(), \ "quasar.json")) and xbmc.getCondVisibility('System.HasAddon("plugin.video.quasar")')): if not update_external_addon("quasar"): platformtools.dialog_notification("Actualización Quasar", "Ha fallado. Consulte el log") #Existe carpeta "custom_code" ? Si no existe se crea y se sale custom_code_dir = filetools.join(ADDON_USERDATA_PATH, 'custom_code') custom_code_json_path = ADDON_PATH custom_code_json = ADDON_CUSTOMCODE_JSON if not filetools.exists(custom_code_dir): create_folder_structure(custom_code_dir) #Existe "custom_code.json" ? Si no existe se crea if not filetools.exists(custom_code_json): create_json(custom_code_json_path) #Se verifica si la versión del .json y del add-on son iguales. Si es así se sale. Si no se copia "custom_code" al add-on verify_copy_folders(custom_code_dir, custom_code_json_path) #Si se han quedado "colgadas" descargas con archivos .RAR, se intenta identificarlos y reactivar el UnRar reactivate_unrar(init=True, mute=True) #Inicia un rastreo de vídeos decargados desde .torrent: marca los VISTOS y elimina los controles de los BORRADOS from servers.torrent import mark_torrent_as_watched try: threading.Thread(target=mark_torrent_as_watched).start() # Creamos un Thread independiente, hasta el fin de Kodi time.sleep(2) # Dejamos terminar la inicialización... except: # Si hay problemas de threading, nos vamos logger.error(traceback.format_exc()) #Ejecuta la sobrescritura de la videoteca para los canales seleccionados reset_videotlibrary_by_channel() except: logger.error(traceback.format_exc())