mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
add: direct http download, fix libtorrent speed limit settings
This commit is contained in:
@@ -16,8 +16,13 @@ def check_completed(downloads, resume):
|
||||
consoleLog(f"Found unfinished download: {download.title}")
|
||||
if resume == True:
|
||||
dl_dir = os.path.dirname(download.path)
|
||||
run_download_direct(download.magnet_uri, dl_dir)
|
||||
consoleLog(f"Resuming {download.title}")
|
||||
if download.magnet_uri:
|
||||
run_download_direct(download.magnet_uri, dl_dir, download.title)
|
||||
consoleLog(f"Resuming Magnet: {download.title}")
|
||||
elif download.url:
|
||||
from core.network.direct_download import add_direct_download
|
||||
add_direct_download(download.url, download.title, dl_dir)
|
||||
consoleLog(f"Resuming Direct Download: {download.title}")
|
||||
|
||||
def check_downloads(downloads):
|
||||
for download in downloads:
|
||||
|
||||
@@ -6,11 +6,10 @@ from core.utils.general.wrappers import run_thread
|
||||
from core.utils.logging.logs import add_download_log
|
||||
from core.network.libtorrent_int import add_seed
|
||||
from core.utils.data.state import state
|
||||
from urllib.parse import urlparse, unquote
|
||||
from core.network.direct_download import add_direct_download
|
||||
import threading
|
||||
import re
|
||||
import requests
|
||||
import random
|
||||
|
||||
|
||||
|
||||
|
||||
def download_selected(items: list[QTableWidgetItem]):
|
||||
@@ -31,37 +30,6 @@ def download_selected(items: list[QTableWidgetItem]):
|
||||
consoleLog(f"Downloading {post.get('title', 'Unknown')}")
|
||||
run_thread(threading.Thread(target=run_download, args=(post,)))
|
||||
|
||||
def get_direct_filename(url: str, headers) -> str:
|
||||
cd = headers.get('content-disposition', '')
|
||||
if cd:
|
||||
match = re.search(r'filename\*=UTF-8\'\'(.+)', cd) # RFC 5987 encoded
|
||||
if match:
|
||||
return unquote(match.group(1))
|
||||
match = re.search(r'filename="?([^";\n]+)"?', cd)
|
||||
if match:
|
||||
return match.group(1).strip()
|
||||
|
||||
path = urlparse(url).path
|
||||
name = path.split('/')[-1]
|
||||
if name:
|
||||
return unquote(name)
|
||||
|
||||
return f"download{random.randint(1,9999)}" #avoid collision
|
||||
|
||||
def filedownload(url):
|
||||
try:
|
||||
with requests.get(url, stream=True, timeout=30) as r:
|
||||
r.raise_for_status()
|
||||
name = get_direct_filename(url, r.headers)
|
||||
|
||||
with open(state.download_path + f"/{name}", 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
consoleLog(f"Finished downloading {name}")
|
||||
except Exception as e:
|
||||
consoleLog(f"Error downloading: {e}")
|
||||
|
||||
def run_download(post):
|
||||
linkfunc = state.trackers[state.currenttracker]["linkFunc"]
|
||||
ismagnet = state.trackers[state.currenttracker]["isMagnet"]
|
||||
@@ -71,12 +39,12 @@ def run_download(post):
|
||||
add_magnet(link)
|
||||
add_download_log(post.get("title", "Unknown"), "", link, False)
|
||||
else:
|
||||
filedownload(link)
|
||||
add_direct_download(link, post.get("title", "Unknown"))
|
||||
|
||||
def run_download_direct(magnet_uri, dl_path=None):
|
||||
consoleLog(f"Direct download: {magnet_uri[:60]}")
|
||||
def run_download_direct(magnet_uri, dl_path=None, title="Direct Download"):
|
||||
consoleLog(f"Magnet: {title}")
|
||||
add_magnet(magnet_uri, dl_path)
|
||||
add_download_log("Direct Download", "", magnet_uri, False)
|
||||
add_download_log(title, "", magnet_uri, False)
|
||||
|
||||
def seed_magnet(magnet_uri, file_path):
|
||||
consoleLog(f"Seeding: {magnet_uri[:60]}")
|
||||
|
||||
Reference in New Issue
Block a user