Update to artist credit handling
This commit is contained in:
@@ -11,5 +11,5 @@ pub mod ytdlp;
|
|||||||
|
|
||||||
pub use backend::{AudioFormat, BackendConfig, DownloadBackend, DownloadResult, DownloadTarget, SearchResult};
|
pub use backend::{AudioFormat, BackendConfig, DownloadBackend, DownloadResult, DownloadTarget, SearchResult};
|
||||||
pub use error::{DlError, DlResult};
|
pub use error::{DlError, DlResult};
|
||||||
pub use queue::{DlStats, SyncStats, download_single, run_queue, sync_wanted_to_queue};
|
pub use queue::{DlStats, ProgressFn, SyncStats, download_single, run_queue, run_queue_with_progress, sync_wanted_to_queue};
|
||||||
pub use ytdlp::{SearchSource, YtDlpBackend};
|
pub use ytdlp::{SearchSource, YtDlpBackend};
|
||||||
|
|||||||
28
src/queue.rs
28
src/queue.rs
@@ -39,15 +39,39 @@ const RETRY_DELAYS: [Duration; 3] = [
|
|||||||
Duration::from_secs(600),
|
Duration::from_secs(600),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// Progress callback: (current, total, message).
|
||||||
|
pub type ProgressFn = Box<dyn Fn(u64, u64, &str) + Send + Sync>;
|
||||||
|
|
||||||
/// Process all pending items in the download queue.
|
/// Process all pending items in the download queue.
|
||||||
pub async fn run_queue(
|
pub async fn run_queue(
|
||||||
conn: &DatabaseConnection,
|
conn: &DatabaseConnection,
|
||||||
backend: &impl DownloadBackend,
|
backend: &impl DownloadBackend,
|
||||||
config: &BackendConfig,
|
config: &BackendConfig,
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
|
) -> DlResult<DlStats> {
|
||||||
|
run_queue_with_progress(conn, backend, config, dry_run, None).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process all pending items in the download queue, with optional progress reporting.
|
||||||
|
pub async fn run_queue_with_progress(
|
||||||
|
conn: &DatabaseConnection,
|
||||||
|
backend: &impl DownloadBackend,
|
||||||
|
config: &BackendConfig,
|
||||||
|
dry_run: bool,
|
||||||
|
on_progress: Option<ProgressFn>,
|
||||||
) -> DlResult<DlStats> {
|
) -> DlResult<DlStats> {
|
||||||
let mut stats = DlStats::default();
|
let mut stats = DlStats::default();
|
||||||
|
|
||||||
|
// Count total for progress reporting
|
||||||
|
let total = queries::downloads::list(conn, Some(DownloadStatus::Pending))
|
||||||
|
.await
|
||||||
|
.map(|v| v.len() as u64)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
if let Some(ref cb) = on_progress {
|
||||||
|
cb(0, total, "Starting downloads...");
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let item = match queries::downloads::get_next_pending(conn).await? {
|
let item = match queries::downloads::get_next_pending(conn).await? {
|
||||||
Some(item) => item,
|
Some(item) => item,
|
||||||
@@ -56,6 +80,10 @@ pub async fn run_queue(
|
|||||||
|
|
||||||
stats.downloads_attempted += 1;
|
stats.downloads_attempted += 1;
|
||||||
|
|
||||||
|
if let Some(ref cb) = on_progress {
|
||||||
|
cb(stats.downloads_attempted, total, &format!("Downloading: {}", item.query));
|
||||||
|
}
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
id = item.id,
|
id = item.id,
|
||||||
query = %item.query,
|
query = %item.query,
|
||||||
|
|||||||
Reference in New Issue
Block a user