Skip to main content

DownloadManager

Struct DownloadManager 

Source
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

Source

pub fn new(config: Config) -> DownloadManager

Source

pub fn config(&self) -> &Config

Source

pub async fn set_config(&mut self, value: Config) -> Result<(), AcquireError>

Source

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.

Source

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.

Source

pub async fn evaluate<CR>( &self, req: EvaluateRequest<'_, CR>, ) -> Result<Download, OdlError>

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.

Source

pub async fn quick_evaluate<CR>( &self, req: EvaluateRequest<'_, CR>, ) -> Result<Download, OdlError>

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).

Source

pub async fn download<CR>( &self, req: DownloadRequest<'_, CR>, ) -> Result<PathBuf, OdlError>

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.

Source

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.

Trait Implementations§

Source§

impl Debug for DownloadManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more