def mainlist(item): logger.info() item.category = 'Descargas' itemlist = [] if download_path.startswith('smb://'): fichs = sorted(filetools.listdir(download_path)) ficheros = [ filetools.join(download_path, fit) for fit in fichs if fit.endswith('.json') ] else: path = filetools.join(download_path, '*.json') ficheros = glob.glob(path) ficheros.sort(key=os.path.getmtime, reverse=False) for down_path in ficheros: # ~ it = Item().fromjson(path=down_path) # falla con smb:// it = Item().fromjson(filetools.read(down_path)) it.from_channel = it.channel it.from_action = it.action it.channel = item.channel it.action = 'acciones_enlace' it.jsonfile = down_path it.folder = False if it.downloadStatus == STATUS_CODES.completed: it.title = '[B][COLOR gold][Ok] %s [%s][/COLOR][/B]' % ( it.downloadFilename, config.format_bytes(it.downloadSize)) elif it.downloadStatus == STATUS_CODES.canceled: it.title = '[COLOR red][%s%%] %s [%s de %s][/COLOR]' % ( int(it.downloadProgress), it.downloadFilename, config.format_bytes(it.downloadCompleted), config.format_bytes(it.downloadSize)) elif it.downloadStatus == STATUS_CODES.error: it.title = '[I][COLOR gray][Error] %s[/COLOR][/I]' % it.downloadFilename else: it.title = '[I][COLOR gray][???] %s[/COLOR][/I]' % it.downloadFilename itemlist.append(it) return itemlist
def clean_db_cache(item): logger.info() import sqlite3, time from core import filetools fecha_caducidad = time.time() - (31 * 24 * 60 * 60) # al cabo de 31 días fname = filetools.join(config.get_data_path(), "tmdb.sqlite") conn = sqlite3.connect(fname) c = conn.cursor() c.execute('SELECT COUNT() FROM tmdb_cache') numregs = c.fetchone()[0] c.execute('SELECT COUNT() FROM tmdb_cache WHERE added < ?', (fecha_caducidad, )) numregs_expired = c.fetchone()[0] txt = 'El caché de Tmdb ocupa [COLOR gold]%s[/COLOR]' % config.format_bytes( filetools.getsize(fname)) txt += ' y contiene [COLOR gold]%s[/COLOR] registros.' % numregs txt += ' ¿ Borrar los [COLOR blue]%s[/COLOR] registros que tienen más de un mes de antiguedad ?' % numregs_expired if platformtools.dialog_yesno('Limpiar caché Tmdb', txt): c.execute('DELETE FROM tmdb_cache WHERE added < ?', (fecha_caducidad, )) conn.commit() conn.execute('VACUUM') platformtools.dialog_notification(config.__addon_name, 'Limpiado caché Tmdb', time=2000, sound=False) conn.close()
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 informacion_lista(item): logger.info() fullfilename = filetools.join(trackingtools.get_tracking_path(), item.lista) if not filetools.exists(fullfilename): platformtools.dialog_ok(config.__addon_name, 'Error, no se encuentra la lista!', item.lista) return False db = trackingtools.TrackingData(item.lista) count_movies = db.get_movies_count() count_shows = db.get_shows_count() count_episodes = db.get_episodes_count() db.close() txt = 'Nombre: [COLOR gold]%s[/COLOR]' % item.lista txt += '[CR][CR]Número de películas: [B]%d[/B]' % count_movies txt += '[CR][CR]Número de series: [B]%d[/B]' % count_shows txt += '[CR][CR]Número de episodios: [B]%d[/B]' % count_episodes txt += '[CR][CR]Tamaño de la base de datos: [B]%s[/B]' % config.format_bytes(filetools.getsize(fullfilename)) platformtools.dialog_textviewer('Información de la lista', txt) return True