Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: enhance downloaded file retrieval logic and add timeout handling for fetching video info

Tonho320f93fd1f22
diff --git a/src-tauri/omniget-core/src/core/ytdlp.rs b/src-tauri/omniget-core/src/core/ytdlp.rs
index aed5afb1..6095fc34 100644
--- a/src-tauri/omniget-core/src/core/ytdlp.rs
+++ b/src-tauri/omniget-core/src/core/ytdlp.rs
@@ -1718,10 +1718,39 @@ async fn find_downloaded_file(output_dir: &Path, url: &str) -> anyhow::Result<Pa
candidates.sort_by(|a, b| b.2.cmp(&a.2).then_with(|| b.1.cmp(&a.1)));
- candidates
- .into_iter()
- .next()
- .map(|(p, _, _)| p)
+ if let Some((p, _, _)) = candidates.into_iter().next() {
+ return Ok(p);
+ }
+
+ let fallback_limit = std::time::Duration::from_secs(120);
+ let mut newest: Option<(PathBuf, std::time::SystemTime)> = None;
+ if let Ok(entries) = std::fs::read_dir(output_dir) {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if !path.is_file() {
+ continue;
+ }
+ let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
+ if name.ends_with(".part") || name.ends_with(".ytdl") || name.starts_with('.') {
+ continue;
+ }
+ if let Ok(meta) = entry.metadata() {
+ if meta.len() == 0 {
+ continue;
+ }
+ if let Ok(modified) = meta.modified() {
+ if now.duration_since(modified).unwrap_or_default() < fallback_limit {
+ if newest.as_ref().map_or(true, |(_, t)| modified > *t) {
+ newest = Some((path, modified));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ newest
+ .map(|(p, _)| p)
.ok_or_else(|| anyhow!("Downloaded file not found in {:?}", output_dir))
}
diff --git a/src-tauri/src/core/queue.rs b/src-tauri/src/core/queue.rs
index 82132cfc..17c9e2af 100644
--- a/src-tauri/src/core/queue.rs
+++ b/src-tauri/src/core/queue.rs
@@ -555,9 +555,14 @@ async fn spawn_download_inner(
phase: "fetching_info".to_string(),
});
- match fetch_and_cache_info(&url, &*downloader, &platform_name, ytdlp_path.as_deref()).await {
- Ok(i) => i,
- Err(e) => {
+ let info_result = tokio::time::timeout(
+ std::time::Duration::from_secs(60),
+ fetch_and_cache_info(&url, &*downloader, &platform_name, ytdlp_path.as_deref())
+ ).await;
+
+ match info_result {
+ Ok(Ok(i)) => i,
+ Ok(Err(e)) => {
let state = {
let mut q = queue.lock().await;
q.mark_complete(item_id, false, Some(e.to_string()), None, None);
@@ -567,6 +572,17 @@ async fn spawn_download_inner(
try_start_next(app, queue).await;
return;
}
+ Err(_) => {
+ tracing::warn!("[queue] info fetch timed out for {} after 60s", item_id);
+ let state = {
+ let mut q = queue.lock().await;
+ q.mark_complete(item_id, false, Some("Timed out fetching video info".to_string()), None, None);
+ q.get_state()
+ };
+ emit_queue_state_from_state(&app, state);
+ try_start_next(app, queue).await;
+ return;
+ }
}
}
};
@@ -921,13 +937,31 @@ pub async fn try_start_next(app: tauri::AppHandle, queue: Arc<tokio::sync::Mutex
emit_queue_state_from_state(&app, state);
}
+ let batch_size = next_ids.len();
for (i, nid) in next_ids.into_iter().enumerate() {
+ let _ = app.emit("queue-item-progress", &QueueItemProgress {
+ id: nid,
+ title: String::new(),
+ platform: String::new(),
+ percent: 0.0,
+ speed_bytes_per_sec: 0.0,
+ downloaded_bytes: 0,
+ total_bytes: None,
+ phase: "queued_starting".to_string(),
+ });
+
if i > 0 {
let item_platform = {
let q = queue.lock().await;
q.items.iter().find(|item| item.id == nid).map(|item| item.platform.clone())
};
- let delay_ms = if item_platform.as_deref() == Some("youtube") { 2000 } else { stagger };
+ let delay_ms = if item_platform.as_deref() == Some("youtube") {
+ 2000
+ } else if batch_size > 3 {
+ stagger.max(1000)
+ } else {
+ stagger
+ };
if delay_ms > 0 {
tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
}
diff --git a/src-tauri/src/platforms/instagram/mod.rs b/src-tauri/src/platforms/instagram/mod.rs
index 3265bb9c..7a582dd0 100644
--- a/src-tauri/src/platforms/instagram/mod.rs
+++ b/src-tauri/src/platforms/instagram/mod.rs
@@ -88,7 +88,7 @@ impl InstagramDownloader {
let segments: Vec<&str> = parsed.path().split('/').filter(|s| !s.is_empty()).collect();
match segments.first() {
- Some(&"p") | Some(&"reel") | Some(&"tv") => {
+ Some(&"p") | Some(&"reel") | Some(&"reels") | Some(&"tv") => {
segments.get(1).map(|s| s.to_string())
}
_ => None,