mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
Merge pull request #4 from KeksPirates/main
Update Repository with latest SoftwareManager commits
This commit is contained in:
@@ -19,7 +19,7 @@ def get_active_interfaces():
|
|||||||
for addr in addr_list:
|
for addr in addr_list:
|
||||||
if addr.family == 2: # ipv4
|
if addr.family == 2: # ipv4
|
||||||
ipv4 = addr.address
|
ipv4 = addr.address
|
||||||
if not ipv4.startswith("127.") and not ipv4.startswith("169.254") and up == True:
|
if not ipv4.startswith("127.") and not ipv4.startswith("169.254") and up:
|
||||||
active.append(interface)
|
active.append(interface)
|
||||||
consoleLog(f"Found Active: {interface}")
|
consoleLog(f"Found Active: {interface}")
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ def list_interfaces() -> None:
|
|||||||
for addr in addr_list:
|
for addr in addr_list:
|
||||||
if addr.family == 2: # ipv4
|
if addr.family == 2: # ipv4
|
||||||
ipv4 = addr.address
|
ipv4 = addr.address
|
||||||
if not ipv4.startswith("127.") and not ipv4.startswith("169.254") and up == True:
|
if not ipv4.startswith("127.") and not ipv4.startswith("169.254") and up:
|
||||||
status = "ACTIVE"
|
status = "ACTIVE"
|
||||||
else:
|
else:
|
||||||
status = "INACTIVE"
|
status = "INACTIVE"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
|
import os
|
||||||
from core.utils.general.wrappers import run_thread
|
from core.utils.general.wrappers import run_thread
|
||||||
from core.network.interface import get_interface_ip
|
from core.network.interface import get_interface_ip
|
||||||
import threading
|
import threading
|
||||||
@@ -51,8 +52,26 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
init_session()
|
init_session()
|
||||||
|
|
||||||
if magnet_uri in state.active_downloads:
|
if magnet_uri in state.active_downloads:
|
||||||
consoleLog("Skipping Downloading, download already running...")
|
try:
|
||||||
return
|
handle = state.active_downloads[magnet_uri]
|
||||||
|
status = handle.status()
|
||||||
|
except RuntimeError as e:
|
||||||
|
consoleLog(f"Error in LibTorrent Handle: {e}")
|
||||||
|
|
||||||
|
if status.has_metadata:
|
||||||
|
filepath = os.path.join(status.save_path, status.name)
|
||||||
|
|
||||||
|
if not os.path.exists(filepath):
|
||||||
|
|
||||||
|
consoleLog(f"File Deleted, redownloading: {status.name}")
|
||||||
|
state.dl_session.remove_torrent(handle)
|
||||||
|
del state.active_downloads[magnet_uri]
|
||||||
|
else:
|
||||||
|
consoleLog("Skipping Downloading, download already running...")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
consoleLog("Skipping Downloading, download already running... ")
|
||||||
|
return False
|
||||||
|
|
||||||
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
||||||
magnetdl.save_path = dl_path
|
magnetdl.save_path = dl_path
|
||||||
@@ -62,8 +81,27 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
consoleLog(f"Added {magnet_uri} to downloads")
|
consoleLog(f"Added {magnet_uri} to downloads")
|
||||||
|
|
||||||
run_thread(threading.Thread(target=dl_status_loop))
|
run_thread(threading.Thread(target=dl_status_loop))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def add_seed(magnet_uri, file_path):
|
||||||
|
if state.active_downloads is None:
|
||||||
|
state.active_downloads = {}
|
||||||
|
|
||||||
|
init_session()
|
||||||
|
|
||||||
|
if magnet_uri in state.active_downloads:
|
||||||
|
consoleLog("Already seeding this torrent")
|
||||||
|
return False
|
||||||
|
|
||||||
|
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
||||||
|
magnetdl.save_path = os.path.dirname(file_path)
|
||||||
|
|
||||||
|
handle = state.dl_session.add_torrent(magnetdl)
|
||||||
|
state.active_downloads[magnet_uri] = handle
|
||||||
|
state.seeded_magnets.add(magnet_uri)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def dl_status_loop():
|
def dl_status_loop():
|
||||||
global loop_running
|
global loop_running
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from core.utils.logging.logs import update_download_completed_by_hash
|
|||||||
from core.utils.logging.logs import consoleLog
|
from core.utils.logging.logs import consoleLog
|
||||||
from plyer import notification
|
from plyer import notification
|
||||||
import libtorrent as lt
|
import libtorrent as lt
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ def update_log(shutdown_event):
|
|||||||
|
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
|
|
||||||
if status.state == lt.torrent_status.seeding and magnet_uri not in updated:
|
if status.state == lt.torrent_status.seeding and magnet_uri not in updated and magnet_uri not in state.seeded_magnets:
|
||||||
consoleLog(f"Marking {status.name} as completed")
|
consoleLog(f"Marking {status.name} as completed")
|
||||||
info_hash = str(status.info_hash)
|
info_hash = str(status.info_hash)
|
||||||
update_download_completed_by_hash(info_hash, True)
|
update_download_completed_by_hash(info_hash, True)
|
||||||
@@ -58,3 +59,24 @@ def update_log(shutdown_event):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
def check_deleted_files(shutdown_event):
|
||||||
|
while not shutdown_event.is_set():
|
||||||
|
try:
|
||||||
|
for magnet_uri, magnetdl in list(state.active_downloads.items()):
|
||||||
|
if isinstance(magnetdl, dict):
|
||||||
|
continue
|
||||||
|
|
||||||
|
status = magnetdl.status()
|
||||||
|
|
||||||
|
if status.state == lt.torrent_status.seeding and status.has_metadata:
|
||||||
|
file_path = os.path.join(status.save_path, status.name)
|
||||||
|
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
consoleLog(f"Registered File Deletion: {status.name}")
|
||||||
|
state.dl_session.remove_torrent(magnetdl)
|
||||||
|
del state.active_downloads[magnet_uri]
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
time.sleep(5)
|
||||||
@@ -30,6 +30,7 @@ class AppState(QObject):
|
|||||||
self.settings_path: str = ""
|
self.settings_path: str = ""
|
||||||
self.dl_session: Any = None
|
self.dl_session: Any = None
|
||||||
self.active_downloads: Dict = {}
|
self.active_downloads: Dict = {}
|
||||||
|
self.seeded_magnets: set = set()
|
||||||
self.window_transparency: bool = False
|
self.window_transparency: bool = False
|
||||||
self.interfaces: List = []
|
self.interfaces: List = []
|
||||||
self.active_interfaces: List = []
|
self.active_interfaces: List = []
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from core.utils.logging.logs import consoleLog, remove_download_log
|
from core.utils.logging.logs import consoleLog, remove_download_log
|
||||||
from core.utils.network.download import run_download_direct
|
from core.utils.network.download import run_download_direct, seed_magnet
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ def check_downloads(downloads):
|
|||||||
for download in downloads:
|
for download in downloads:
|
||||||
if os.path.exists(download.path):
|
if os.path.exists(download.path):
|
||||||
consoleLog(f"Existing Download: {download.title}")
|
consoleLog(f"Existing Download: {download.title}")
|
||||||
|
seed_magnet(download.magnet_uri, download.path)
|
||||||
else:
|
else:
|
||||||
consoleLog(f"Inexistent Download: {download.title}")
|
consoleLog(f"Inexistent Download: {download.title}")
|
||||||
remove_download_log(download.magnet_uri)
|
remove_download_log(download.magnet_uri)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from core.utils.data.tracker import get_magnet_link
|
|||||||
from core.network.libtorrent_wrapper import add_download
|
from core.network.libtorrent_wrapper import add_download
|
||||||
from core.utils.general.wrappers import run_thread
|
from core.utils.general.wrappers import run_thread
|
||||||
from core.utils.logging.logs import add_download_log
|
from core.utils.logging.logs import add_download_log
|
||||||
|
from core.network.libtorrent_int import add_seed
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
@@ -19,8 +20,14 @@ def run_download(item, posts, post_titles):
|
|||||||
consoleLog(f"Selected URL: {post_url}")
|
consoleLog(f"Selected URL: {post_url}")
|
||||||
magnet_uri = get_magnet_link(post_url)
|
magnet_uri = get_magnet_link(post_url)
|
||||||
|
|
||||||
add_download(magnet_uri)
|
if add_download(magnet_uri):
|
||||||
add_download_log(item, post_url, magnet_uri, False)
|
add_download_log(item, post_url, magnet_uri, False)
|
||||||
|
|
||||||
def run_download_direct(magnet_uri):
|
def run_download_direct(magnet_uri):
|
||||||
add_download(magnet_uri)
|
consoleLog(f"Direct download: {magnet_uri[:60]}")
|
||||||
|
add_download(magnet_uri)
|
||||||
|
add_download_log("Direct Download", "", magnet_uri, False)
|
||||||
|
|
||||||
|
def seed_magnet(magnet_uri, file_path):
|
||||||
|
consoleLog(f"Seeding: {magnet_uri[:60]}")
|
||||||
|
add_seed(magnet_uri, file_path)
|
||||||
+3
-1
@@ -1,7 +1,7 @@
|
|||||||
from core.interface.gui import MainWindow, windowCloseHelper
|
from core.interface.gui import MainWindow, windowCloseHelper
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
from core.utils.logging.logs import consoleLog
|
from core.utils.logging.logs import consoleLog
|
||||||
from core.network.libtorrent_misc import send_notification, update_log
|
from core.network.libtorrent_misc import send_notification, update_log, check_deleted_files
|
||||||
from core.utils.logging.logs import get_download_logs
|
from core.utils.logging.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
|
||||||
@@ -53,6 +53,8 @@ def main():
|
|||||||
consoleLog("Started Thread: update_log")
|
consoleLog("Started Thread: update_log")
|
||||||
run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume)))
|
run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume)))
|
||||||
consoleLog("Started Thread: check_completed")
|
consoleLog("Started Thread: check_completed")
|
||||||
|
run_thread(threading.Thread(target=check_deleted_files, args=(shutdown_event,), daemon=True))
|
||||||
|
consoleLog("Started Thread: check_deleted_files")
|
||||||
check_downloads(downloads)
|
check_downloads(downloads)
|
||||||
elapsed = time.perf_counter() - start_time
|
elapsed = time.perf_counter() - start_time
|
||||||
consoleLog(f"Initialization completed in {elapsed:.2f}s. Launching GUI")
|
consoleLog(f"Initialization completed in {elapsed:.2f}s. Launching GUI")
|
||||||
|
|||||||
Reference in New Issue
Block a user