mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from utils.logging.logs import consoleLog, add_download_log
|
|
from utils.data.state import state
|
|
from typing import Optional
|
|
|
|
|
|
from network.direct_download.handle import DirectDownloadHandle
|
|
from network.direct_download.utils import (
|
|
sanitize_filename,
|
|
extract_filename_from_url,
|
|
detect_filename_from_headers,
|
|
)
|
|
|
|
def add_direct_download(url: str, title: str, dl_path: Optional[str] = None, headers: Optional[dict] = None, single_threaded: bool = False):
|
|
|
|
if dl_path is None:
|
|
dl_path = state.download_path
|
|
|
|
with state.downloads_lock:
|
|
if url in state.active_downloads:
|
|
consoleLog(f"Download already active: {title}")
|
|
return
|
|
|
|
raw_filename = (
|
|
detect_filename_from_headers(url, DirectDownloadHandle.USER_AGENT)
|
|
or extract_filename_from_url(url)
|
|
or sanitize_filename(title) + ".zip"
|
|
)
|
|
|
|
filename = sanitize_filename(raw_filename)
|
|
|
|
handle = DirectDownloadHandle(url, filename, dl_path, headers, single_threaded)
|
|
with state.downloads_lock:
|
|
state.active_downloads[url] = handle
|
|
add_download_log(title, url, "", False)
|
|
handle.start()
|
|
consoleLog(f"Started direct download: {filename}")
|