add (almost) final download log logic

This commit is contained in:
Vxrtrauter
2026-01-07 23:07:08 +01:00
parent ad6fa428a0
commit 7e59fdc2d3
2 changed files with 22 additions and 6 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ from typing import List
class Download:
title: str
url: str
torrent_uri: str
magnet_uri: str
completed: bool
@dataclass
+21 -5
View File
@@ -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))
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