diff --git a/src/core/utils/data/models.py b/src/core/utils/data/models.py index 339da08..2c959c7 100644 --- a/src/core/utils/data/models.py +++ b/src/core/utils/data/models.py @@ -7,6 +7,7 @@ class Download: title: str url: str magnet_uri: str + path: str completed: bool @dataclass diff --git a/src/core/utils/logging/logs.py b/src/core/utils/logging/logs.py index 49f0ae1..7fd0ca9 100644 --- a/src/core/utils/logging/logs.py +++ b/src/core/utils/logging/logs.py @@ -5,6 +5,7 @@ from datetime import datetime import json import os import re +import time _log_buffer = [] @@ -21,7 +22,21 @@ def add_download_log(title, url, magnet_uri, completed) -> DownloadList: downloads = [] else: downloads = [] - + + magnetdl = state.active_downloads.get(magnet_uri) + if magnetdl: + status = magnetdl.status() + timeout = 60 + start = time.time() + while not status.has_metadata and (time.time() - start) < timeout: + time.sleep(0.5) + status = magnetdl.status() + torrent_name = status.name + save_path = status.save_path + consoleLog(f"Torrent name (has_metadata={status.has_metadata}): {torrent_name}") + path = os.path.join(save_path, torrent_name) + else: + path = os.path.join(state.download_path, title) if any(d.magnet_uri == magnet_uri or d.url == url for d in downloads): if magnet_uri in state.active_downloads: @@ -37,7 +52,8 @@ def add_download_log(title, url, magnet_uri, completed) -> DownloadList: title=title, url=url, magnet_uri=magnet_uri, - completed=completed, + path=path, + completed=completed )) consoleLog(f"Added {title} to Log File") diff --git a/src/core/utils/network/download.py b/src/core/utils/network/download.py index 1bb49b9..31b6bf0 100644 --- a/src/core/utils/network/download.py +++ b/src/core/utils/network/download.py @@ -5,6 +5,7 @@ from core.utils.data.tracker import get_magnet_link from core.network.libtorrent_wrapper import add_download from core.utils.general.wrappers import run_thread from core.utils.logging.logs import add_download_log +import time import threading @@ -21,8 +22,8 @@ def run_download(item, posts, post_titles): consoleLog(f"Selected URL: {post_url}") magnet_uri = get_magnet_link(post_url) - add_download_log(item, post_url, magnet_uri, False) add_download(magnet_uri) + add_download_log(item, post_url, magnet_uri, False) def run_download_direct(magnet_uri): add_download(magnet_uri)