mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
integrate libtorrent for download status notifications and update logging
This commit is contained in:
@@ -2,6 +2,7 @@ from core.utils.data.state import state
|
|||||||
from core.utils.general.logs import update_download_completed_by_hash
|
from core.utils.general.logs import update_download_completed_by_hash
|
||||||
from core.utils.general.logs import consoleLog
|
from core.utils.general.logs import consoleLog
|
||||||
from plyer import notification
|
from plyer import notification
|
||||||
|
import libtorrent as lt
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
@@ -22,17 +23,19 @@ def send_notification(shutdown_event):
|
|||||||
notified = set()
|
notified = set()
|
||||||
while not shutdown_event.is_set():
|
while not shutdown_event.is_set():
|
||||||
try:
|
try:
|
||||||
for d in state.aria2.get_downloads():
|
for magnet_uri, magnetdl in list(state.active_downloads.items()):
|
||||||
if d.is_metadata:
|
if isinstance(magnetdl, dict):
|
||||||
continue
|
continue
|
||||||
if d.progress == 100 and d.gid not in notified:
|
|
||||||
|
status = magnetdl.status()
|
||||||
|
|
||||||
|
if status.state == lt.torrent_status.seeding and magnet_uri not in notified:
|
||||||
notification.notify(
|
notification.notify(
|
||||||
title="Download finished",
|
title="Download finished",
|
||||||
message=f"{d.name} has finished downloading.",
|
message=f"{status.name} has finished downloading.",
|
||||||
timeout=4
|
timeout=4
|
||||||
)
|
)
|
||||||
notified.add(d.gid)
|
notified.add(magnet_uri)
|
||||||
state.downloads = [d for d in state.aria2.get_downloads() if d.is_active and not d.is_metadata]
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
@@ -41,14 +44,17 @@ def update_log(shutdown_event):
|
|||||||
updated = set()
|
updated = set()
|
||||||
while not shutdown_event.is_set():
|
while not shutdown_event.is_set():
|
||||||
try:
|
try:
|
||||||
for d in state.aria2.get_downloads():
|
for magnet_uri, magnetdl in list(state.active_downloads.items()):
|
||||||
if d.is_metadata:
|
if isinstance(magnetdl, dict):
|
||||||
continue
|
continue
|
||||||
if d.progress == 100 and d.gid not in updated:
|
|
||||||
consoleLog(f"Marking {d.name} as completed")
|
status = magnetdl.status()
|
||||||
update_download_completed_by_hash(d.info_hash, True)
|
|
||||||
updated.add(d.gid)
|
if status.state == lt.torrent_status.seeding and magnet_uri not in updated:
|
||||||
state.downloads = [d for d in state.aria2.get_downloads() if d.is_active and not d.is_metadata]
|
consoleLog(f"Marking {status.name} as completed")
|
||||||
|
info_hash = str(status.info_hash)
|
||||||
|
update_download_completed_by_hash(info_hash, True)
|
||||||
|
updated.add(magnet_uri)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from core.interface.gui import MainWindow
|
from core.interface.gui import MainWindow
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
from core.utils.general.logs import consoleLog
|
from core.utils.general.logs import consoleLog
|
||||||
|
from core.network.libtorrent_misc import send_notification, update_log
|
||||||
from core.utils.general.logs import get_download_logs
|
from core.utils.general.logs import get_download_logs
|
||||||
from core.utils.general.shutdown import closehelper, shutdown_event
|
from core.utils.general.shutdown import closehelper, shutdown_event
|
||||||
from core.utils.general.wrappers import run_thread
|
from core.utils.general.wrappers import run_thread
|
||||||
@@ -43,9 +44,9 @@ if __name__ == "__main__":
|
|||||||
if args.debug:
|
if args.debug:
|
||||||
state.debug = args.debug # override of read_config
|
state.debug = args.debug # override of read_config
|
||||||
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
||||||
# run_thread(threading.Thread(target=send_notification, args=(shutdown_event,), daemon=True))
|
run_thread(threading.Thread(target=send_notification, args=(shutdown_event,), daemon=True))
|
||||||
consoleLog("Started send_notification thread")
|
consoleLog("Started send_notification thread")
|
||||||
# run_thread(threading.Thread(target=update_log, args=(shutdown_event,), daemon=True))
|
run_thread(threading.Thread(target=update_log, args=(shutdown_event,), daemon=True))
|
||||||
consoleLog("Started update_log thread")
|
consoleLog("Started update_log thread")
|
||||||
run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume)))
|
run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume)))
|
||||||
consoleLog("Started check_completed thread")
|
consoleLog("Started check_completed thread")
|
||||||
|
|||||||
Reference in New Issue
Block a user