mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bf2e9af81 | |||
| a6bb879db3 |
@@ -7,6 +7,7 @@ class Download:
|
||||
title: str
|
||||
url: str
|
||||
magnet_uri: str
|
||||
path: str
|
||||
completed: bool
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from core.utils.logging.logs import consoleLog
|
||||
from core.utils.logging.logs import consoleLog, remove_download_log
|
||||
from core.utils.network.download import run_download_direct
|
||||
|
||||
import os
|
||||
|
||||
def split_data(data):
|
||||
|
||||
count = data.count
|
||||
@@ -16,6 +18,11 @@ def check_completed(downloads, resume):
|
||||
run_download_direct(download.magnet_uri)
|
||||
consoleLog(f"Resuming {download.title}")
|
||||
|
||||
|
||||
|
||||
|
||||
def check_downloads(downloads):
|
||||
for download in downloads:
|
||||
if os.path.exists(download.path):
|
||||
consoleLog(f"Existing Download: {download.title}")
|
||||
else:
|
||||
consoleLog(f"Inexistent Download: {download.title}")
|
||||
remove_download_log(download.magnet_uri)
|
||||
|
||||
@@ -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")
|
||||
@@ -61,10 +77,12 @@ def remove_download_log(magnet_uri) -> DownloadList:
|
||||
else:
|
||||
downloads = []
|
||||
|
||||
|
||||
magnet_link = (magnet_uri or "").strip()
|
||||
title = next((getattr(d, 'title', 'Unknown') for d in downloads if (getattr(d, 'magnet_uri', None) or '').strip() == magnet_link or (getattr(d, 'url', None) or '').strip() == magnet_link))
|
||||
downloads = [d for d in downloads if (getattr(d, 'magnet_uri', None) or "").strip() != magnet_link and (getattr(d, 'url', None) or "").strip() != magnet_link]
|
||||
|
||||
consoleLog(f"Removed {magnet_link} from Log File")
|
||||
consoleLog(f"Removed {title} from Log File")
|
||||
|
||||
download_list = DownloadList(data=downloads, count=len(downloads))
|
||||
with open(downloads_file, "w") as file:
|
||||
|
||||
@@ -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)
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@ from core.network.libtorrent_misc import send_notification, update_log
|
||||
from core.utils.logging.logs import get_download_logs
|
||||
from core.utils.general.shutdown import closehelper, shutdown_event
|
||||
from core.utils.general.wrappers import run_thread
|
||||
from core.utils.logging.loghandler import split_data, check_completed
|
||||
from core.utils.logging.loghandler import split_data, check_completed, check_downloads
|
||||
from core.network.interface import list_interfaces, init_interfaces
|
||||
from core.utils.config.config import read_config
|
||||
from PySide6 import QtWidgets
|
||||
@@ -60,6 +60,7 @@ if __name__ == "__main__":
|
||||
consoleLog("Started Thread: update_log")
|
||||
run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume)))
|
||||
consoleLog("Started Thread: check_completed")
|
||||
check_downloads(downloads)
|
||||
elapsed = time.perf_counter() - start_time
|
||||
consoleLog(f"Initialization completed in {elapsed:.2f}s. Launching GUI")
|
||||
run_gui()
|
||||
|
||||
Reference in New Issue
Block a user