mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
add basic libtorrent integration
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
import subprocess
|
||||||
|
import libtorrent as lt
|
||||||
|
from core.utils.data.state import state
|
||||||
|
from core.utils.general.logs import consoleLog
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def init_session():
|
||||||
|
if state.dl_session is not None:
|
||||||
|
return
|
||||||
|
|
||||||
|
state.dl_session = lt.session()
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"upload_rate_limit": 0,
|
||||||
|
"download_rate_limit": 0,
|
||||||
|
"enable_dht": True,
|
||||||
|
"enable_lsd": True,
|
||||||
|
"enable_upnp": True,
|
||||||
|
"enable_natpmp": True,
|
||||||
|
"dht_bootstrap_nodes": "router.bittorrent.com:6881,dht.transmissionbt.com:6881",
|
||||||
|
"connections_limit": 200,
|
||||||
|
"active_downloads": 10
|
||||||
|
}
|
||||||
|
|
||||||
|
state.dl_session.apply_settings(settings)
|
||||||
|
|
||||||
|
|
||||||
|
def add_download(magnet_uri, dl_path=state.download_path):
|
||||||
|
|
||||||
|
init_session()
|
||||||
|
|
||||||
|
if magnet_uri in state.active_downloads:
|
||||||
|
consoleLog("Skipping, download already running...")
|
||||||
|
return
|
||||||
|
|
||||||
|
consoleLog(f"Adding {magnet_uri} to downloads...")
|
||||||
|
|
||||||
|
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
||||||
|
magnetdl.save_path = dl_path
|
||||||
|
|
||||||
|
download = state.dl_session.add_torrent(magnetdl)
|
||||||
|
state.active_downloads[magnet_uri] = magnetdl
|
||||||
@@ -26,6 +26,8 @@ class AppState(QObject):
|
|||||||
self.aria2p: Any = None
|
self.aria2p: Any = None
|
||||||
self.aria2_threads: int = 4
|
self.aria2_threads: int = 4
|
||||||
self.settings_path: str = None
|
self.settings_path: str = None
|
||||||
|
self.dl_session: Any = None
|
||||||
|
self.active_downloads: Any = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def image_path(self) -> str:
|
def image_path(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user