From 7e59fdc2d3d588d5408b5ff7e0ceb09279bee23b Mon Sep 17 00:00:00 2001 From: Vxrtrauter Date: Wed, 7 Jan 2026 23:07:08 +0100 Subject: [PATCH] add (almost) final download log logic --- core/utils/data/models.py | 2 +- core/utils/general/logs.py | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/utils/data/models.py b/core/utils/data/models.py index 9d273c3..339da08 100644 --- a/core/utils/data/models.py +++ b/core/utils/data/models.py @@ -6,7 +6,7 @@ from typing import List class Download: title: str url: str - torrent_uri: str + magnet_uri: str completed: bool @dataclass diff --git a/core/utils/general/logs.py b/core/utils/general/logs.py index 19b16da..c9d1dc0 100644 --- a/core/utils/general/logs.py +++ b/core/utils/general/logs.py @@ -1,16 +1,32 @@ from core.utils.data.models import Download, DownloadList +from core.utils.data.state import state +from dataclasses import asdict import json - - +import os def add_download_log(title, url, magnet_uri, completed) -> DownloadList: - downloads: list[Download] = [] + downloads_file = os.path.join(state.settings_path, "downloads.json") + + if os.path.exists(downloads_file) and os.path.getsize(downloads_file) > 0: + try: + with open(downloads_file, "r") as file: + existing_data = json.load(file) + downloads = [Download(**d) for d in existing_data.get("data", [])] + except json.JSONDecodeError: + downloads = [] + else: + downloads = [] + downloads.append(Download( title=title, url=url, magnet_uri=magnet_uri, completed=completed )) - - return DownloadList(data=downloads, count=len(downloads)) \ No newline at end of file + + download_list = DownloadList(data=downloads, count=len(downloads)) + with open(downloads_file, "w") as file: + json.dump(asdict(download_list), file, indent=4) + + return download_list \ No newline at end of file