def do_download(mediaurl, file_name, parent_item, server_item): from core import downloadtools # Limpiar caracteres para nombre de fichero válido file_name = config.text_clean(file_name) # Guardar info del vídeo en json path_down_json = filetools.join(download_path, file_name + '.json') parent_item.server_item = server_item.tojson( ) # Guardar info del server por si hay que continuar la descarga write_download_json(path_down_json, parent_item) # Lanzamos la descarga down_stats = downloadtools.do_download(mediaurl, download_path, file_name) # Actualizar info de la descarga en json update_download_json(path_down_json, down_stats) if down_stats['downloadStatus'] == STATUS_CODES.error: return False else: if down_stats['downloadStatus'] == STATUS_CODES.completed: platformtools.dialog_ok( config.__addon_name, 'Descarga finalizada correctamente', file_name, config.format_bytes(down_stats['downloadSize'])) platformtools.itemlist_refresh() return True
def crear_lista(item): logger.info() titulo = platformtools.dialog_input(default='', heading='Nombre de la lista') if titulo is None or titulo == '': return False titulo = config.text_clean(titulo, blank_char='_') filename = titulo.replace('.sqlite', '') + '.sqlite' fullfilename = filetools.join(trackingtools.get_tracking_path(), filename) # Comprobar que el fichero no exista ya if filetools.exists(fullfilename): platformtools.dialog_ok(config.__addon_name, 'Error, ya existe una lista con este nombre!', filename) return False # Provocar que se guarde db = trackingtools.TrackingData(filename) db.close(commit=True) platformtools.itemlist_refresh() return True
def do_download(mediaurl, download_path, file_name, headers=[], silent=False, resume=True): # Crear carpeta de destino si no existe if not filetools.exists(download_path): filetools.mkdir(download_path) # Limpiar caracteres para nombre de fichero válido file_name = config.text_clean(file_name) # Lanzamos la descarga d = Downloader(mediaurl, download_path, file_name, headers=headers, resume=resume, max_connections=1 + int(config.get_setting("max_connections")), block_size=2**(17 + int(config.get_setting("block_size"))), part_size=2**(20 + int(config.get_setting("part_size"))), max_buffer=2 * int(config.get_setting("max_buffer"))) if silent: d.start() # bucle hasta terminar import xbmc while not xbmc.Monitor().abortRequested() and d.state not in [ d.states.error, d.states.stopped, d.states.completed ]: xbmc.sleep(100) else: d.start_dialog() # Descarga detenida, verificar estado: {"stopped": 0, "connecting": 1, "downloading": 2, "completed": 3, "error": 4, "saving": 5}) if d.state == d.states.error: logger.info('Error en la descarga %s' % mediaurl) status = STATUS_CODES.error elif d.state == d.states.stopped: logger.info("Descarga detenida") status = STATUS_CODES.canceled elif d.state == d.states.completed: logger.info("Descargada finalizada") status = STATUS_CODES.completed else: logger.error("Estado de descarga no previsto! %d" % d.state) status = STATUS_CODES.stopped params = { 'downloadStatus': status, # 3:error / 1:canceled / 2:completed 'downloadSize': d.size[0], # total bytes de la descarga 'downloadCompleted': d.downloaded[0], # bytes descargados 'downloadProgress': d.progress, # porcentaje descargado (float) 'downloadUrl': d.download_url, # url origen 'downloadFilename': d.filename # nombre del fichero (sin path) } return params