Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Added atexit exit handler for sql_helper so database connection is closed automatically at program exit
cowliquid6da98e21fd2e
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex a1b8adc39..435ee2415 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -75,7 +75,6 @@ async def download_all(args: argparse.Namespace):all_files = [str(f) for f in args.output_folder.glob("**/*") if f.is_file()]combined = '\t'.join(all_files)- # conn.commit() ?await log('Purging empty directories')deleted = await purge_dir(args.output_folder)diff --git a/cyberdrop_dl/utils/sql_helper.py b/cyberdrop_dl/utils/sql_helper.pyindex 30847f506..843b94aa0 100644--- a/cyberdrop_dl/utils/sql_helper.py+++ b/cyberdrop_dl/utils/sql_helper.py@@ -1,5 +1,7 @@import sqlite3-+import atexit+import logging+from tkinter import Eclass SQLHelper():def __init__(self, ignore_history, download_history):@@ -7,6 +9,7 @@ class SQLHelper():self.download_history = download_historyself.conn = Noneself.curs = None+ atexit.register(self.exit_handler) # Close the sql connection when the program exitsasync def sql_initialize(self):self.conn = sqlite3.connect(self.download_history)@@ -37,3 +40,13 @@ class SQLHelper():async def sql_update_file(self, filename, size, completed):self.curs.execute("""INSERT OR REPLACE INTO downloads VALUES ('%s', %d, %d)""" % (filename, size, completed))self.conn.commit()++ def exit_handler(self):+ try:+ self.conn.commit()+ self.conn.close()+ except Exception as e:+ logging.debug(f"Failed to close sqlite database connection: {str(e)}")+ else:+ logging.debug("Successfully closed sqlite database connection")+\ No newline at end of file