pub struct DownloadManager { /* private fields */ }Expand description
High level manager responsible for evaluating and running downloads.
DownloadManager coordinates concurrency (via an internal semaphore),
constructs HTTP clients using Config, resolves conflicts (save/server),
and orchestrates the multi-part downloader.
Typical usage (illustrative):
// Create manager and evaluate a URL to receive a `Download` instruction.
// The manager will perform an HTTP probe and return a populated
// `Download` value which can then be passed to `DownloadManager::download`.
//
// let cfg = Config::default();
// let manager = DownloadManager::new(cfg);
// let instruction = manager
// .evaluate(EvaluateRequest::new(url, save_dir, &save_resolver))
// .await?;
// let path = manager
// .download(DownloadRequest::new(instruction, &server_resolver))
// .await?;Implementations§
Source§impl DownloadManager
impl DownloadManager
pub fn new(config: Config) -> DownloadManager
pub fn config(&self) -> &Config
pub async fn set_config(&mut self, value: Config) -> Result<(), AcquireError>
Sourcepub async fn list_downloads(&self) -> Result<Vec<DownloadStatus>, OdlError>
pub async fn list_downloads(&self) -> Result<Vec<DownloadStatus>, OdlError>
Enumerate downloads tracked in the manager’s download_dir.
Each tracked download lives in its own subdirectory containing a
metadata.pb. Subdirectories without a readable metadata file are
skipped silently (they may be mid-write or unrelated). Bytes
downloaded are summed from the part files actually present on
disk, so the figure reflects resumable progress even for
interrupted downloads.
Sourcepub async fn engine_for(
&self,
url: &Url,
preference: EnginePreference,
) -> Engine
pub async fn engine_for( &self, url: &Url, preference: EnginePreference, ) -> Engine
Which engine Self::evaluate would use for url, without
evaluating it.
Answers the question a queue row needs before anything is downloaded: “will this go through an external tool?” It accounts for both the host rules and whether that tool is actually usable, so the answer matches what evaluating would really do rather than what it would prefer.
Cheap to call repeatedly: the host check is a string comparison, and
the tool’s version check is memoized for the life of the process. Still
async because deciding whether a tool is usable means running it once.
Sourcepub async fn evaluate<CR>(
&self,
req: EvaluateRequest<'_, CR>,
) -> Result<Download, OdlError>where
CR: SaveConflictResolver,
pub async fn evaluate<CR>(
&self,
req: EvaluateRequest<'_, CR>,
) -> Result<Download, OdlError>where
CR: SaveConflictResolver,
Probe the remote URL and resolve save conflicts, returning a
Download ready for Self::download.
All inputs are bundled in EvaluateRequest. Optional fields
(credentials, ctx, options) default to None; when options
is None the manager’s own config.download is used.
Sourcepub async fn quick_evaluate<CR>(
&self,
req: EvaluateRequest<'_, CR>,
) -> Result<Download, OdlError>where
CR: SaveConflictResolver,
pub async fn quick_evaluate<CR>(
&self,
req: EvaluateRequest<'_, CR>,
) -> Result<Download, OdlError>where
CR: SaveConflictResolver,
Build a Download without contacting the server.
Derives filename from the URL (path/query) and resolves save
conflicts against save_dir, but skips the HTTP probe entirely.
Server-derived fields are left empty: size, etag,
last_modified, and checksums are None/empty, and
is_resumable is false.
Intended for callers that need a fast filename/conflict decision
(e.g. UI previews, batch planning) before committing to a full
Self::evaluate. A download manager can use it to accept a pasted
link into a queue immediately, and evaluate it when the user actually
starts it.
The returned instruction is marked
DownloadEngine::Unresolved
and cannot be downloaded: which engine handles a URL, and the
filename it will produce, are only known after a real evaluation.
Passing one to Self::download is an error rather than a guess —
guessing would, for a media link, quietly fetch the web page instead of
the video. Call Self::evaluate with the same URL when ready.
credentials is preserved on the returned instruction; ctx is
used only for phase emission and cancellation checks; options
supplies max_connections and use_server_time (no network knobs
are read since no request is made).
Sourcepub async fn download<CR>(
&self,
req: DownloadRequest<'_, CR>,
) -> Result<PathBuf, OdlError>where
CR: ServerConflictResolver,
pub async fn download<CR>(
&self,
req: DownloadRequest<'_, CR>,
) -> Result<PathBuf, OdlError>where
CR: ServerConflictResolver,
Run a download for an evaluated Download instruction.
All inputs are bundled in DownloadRequest. Optional fields
(ctx, options) default to None; when options is None the
manager’s own config.download is used.
Note: max_concurrent_downloads is a manager-only setting and is
not part of DownloadOptions — the semaphore that enforces it
is shared across all jobs.
Sourcepub async fn acquire_download_permit(
&self,
) -> Result<DownloadPermit, AcquireError>
pub async fn acquire_download_permit( &self, ) -> Result<DownloadPermit, AcquireError>
acquire a permit from this download manager’s semaphore. Only up to max_concurrent_downloads are permitted at the same time.