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.

fix(plugins): load installed plugins before network bootstrap; add bulk media downloads

Antonio Leandro6951b53a2ae0
diff --git a/src-tauri/src/commands/plugins.rs b/src-tauri/src/commands/plugins.rs
index aa96e163..97a4aea6 100644
--- a/src-tauri/src/commands/plugins.rs
+++ b/src-tauri/src/commands/plugins.rs
@@ -366,7 +366,10 @@ pub async fn install_plugin_zip_from_repo(
}
let client = crate::core::http_client::apply_global_proxy(
- reqwest::Client::builder().user_agent("OmniGet"),
+ reqwest::Client::builder()
+ .user_agent("OmniGet")
+ .timeout(std::time::Duration::from_secs(60))
+ .connect_timeout(std::time::Duration::from_secs(15)),
)
.build()
.map_err(|e| e.to_string())?;
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index c45d15b5..5e7a24bb 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -207,6 +207,9 @@ pub fn run() {
tracing_subscriber::fmt::init();
let mut registry = core::registry::PlatformRegistry::new();
+ // gallery-dl first: it claims bulk-listing URLs (profiles, subreddits)
+ // that the single-post Twitter/Reddit downloaders would otherwise match
+ registry.register(Arc::new(platforms::gallerydl::GalleryDlDownloader::new()));
registry.register(Arc::new(omniget_core::platforms::InstagramDownloader::new()));
registry.register(Arc::new(omniget_core::platforms::PinterestDownloader::new()));
registry.register(Arc::new(omniget_core::platforms::TikTokDownloader::new()));
@@ -226,7 +229,6 @@ pub fn run() {
torrent_session.clone(),
)));
registry.register(Arc::new(omniget_core::platforms::P2pDownloader::new()));
- registry.register(Arc::new(platforms::gallerydl::GalleryDlDownloader::new()));
registry.register(Arc::new(
omniget_core::platforms::DirectFileDownloader::new(),
));
@@ -605,12 +607,21 @@ pub fn run() {
std::thread::Builder::new()
.name("plugins-bootstrap".into())
.spawn(move || {
+ use tauri::Emitter;
+
+ // Load already-installed plugins first so they are
+ // usable immediately (and offline), without waiting
+ // on any of the network calls below.
+ {
+ let mut mgr = mgr_for_plugins.blocking_write();
+ mgr.load_all(std::sync::Arc::clone(&host));
+ }
+ let _ = app_emit.emit("plugins-changed", ());
+
let rt = match tokio::runtime::Runtime::new() {
Ok(rt) => rt,
Err(e) => {
tracing::warn!("plugins-bootstrap runtime failed: {}", e);
- let mut mgr = mgr_for_plugins.blocking_write();
- mgr.load_all(host);
return;
}
};
@@ -621,12 +632,22 @@ pub fn run() {
std::sync::Arc::clone(&mgr_for_plugins),
));
+ // Load anything newly installed above. load_all is
+ // not idempotent (re-inserting drops the previously
+ // loaded plugin and its dylib), so only load entries
+ // that are not loaded yet.
{
let mut mgr = mgr_for_plugins.blocking_write();
- mgr.load_all(host);
+ let to_load: Vec<String> = mgr
+ .installed_plugins()
+ .iter()
+ .filter(|p| p.enabled && !mgr.is_loaded(&p.id))
+ .map(|p| p.id.clone())
+ .collect();
+ for id in &to_load {
+ let _ = mgr.load_one(id, std::sync::Arc::clone(&host));
+ }
}
-
- use tauri::Emitter;
let _ = app_emit.emit("plugins-changed", ());
})
.ok();
diff --git a/src-tauri/src/platforms/gallerydl/mod.rs b/src-tauri/src/platforms/gallerydl/mod.rs
index 0cc3eaa5..9e9cea22 100644
--- a/src-tauri/src/platforms/gallerydl/mod.rs
+++ b/src-tauri/src/platforms/gallerydl/mod.rs
@@ -57,6 +57,55 @@ pub fn is_gallery_url(url: &str) -> bool {
.any(|h| host == *h || host.ends_with(&format!(".{}", h)))
}
+/// Twitter path segments that are app routes, not usernames.
+const TWITTER_RESERVED: &[&str] = &[
+ "home", "explore", "notifications", "messages", "settings", "search",
+ "hashtag", "intent", "share", "login", "logout", "signup", "i", "about",
+ "tos", "privacy", "compose", "jobs",
+];
+
+/// Bulk-listing URLs (profiles, subreddits) that the single-post platform
+/// downloaders can't handle but gallery-dl can enumerate and download.
+pub fn is_bulk_media_url(url: &str) -> bool {
+ let Ok(parsed) = url::Url::parse(url) else {
+ return false;
+ };
+ let Some(host) = parsed
+ .host_str()
+ .map(|h| h.trim_start_matches("www.").to_lowercase())
+ else {
+ return false;
+ };
+ let segments: Vec<&str> = parsed
+ .path_segments()
+ .map(|s| s.filter(|p| !p.is_empty()).collect())
+ .unwrap_or_default();
+
+ if host == "reddit.com" || host.ends_with(".reddit.com") {
+ return match segments.as_slice() {
+ // subreddit root or its listing sorts, but never a post
+ ["r", _] => true,
+ ["r", _, sort] => matches!(*sort, "hot" | "new" | "top" | "rising" | "best"),
+ // user profile / submitted media
+ ["user" | "u", _] => true,
+ ["user" | "u", _, tail] => matches!(*tail, "submitted" | "posts"),
+ _ => false,
+ };
+ }
+
+ if host == "twitter.com" || host == "x.com" {
+ return match segments.as_slice() {
+ [user] => !TWITTER_RESERVED.contains(user),
+ [user, tail] => {
+ !TWITTER_RESERVED.contains(user) && matches!(*tail, "media" | "likes")
+ }
+ _ => false,
+ };
+ }
+
+ false
+}
+
pub struct GalleryDlDownloader;
impl GalleryDlDownloader {
@@ -100,7 +149,7 @@ impl PlatformDownloader for GalleryDlDownloader {
}
fn can_handle(&self, url: &str) -> bool {
- is_gallery_url(url)
+ is_gallery_url(url) || is_bulk_media_url(url)
}
async fn get_media_info(&self, url: &str) -> anyhow::Result<MediaInfo> {
@@ -302,7 +351,7 @@ fn collect_new_files(dir: &Path, since: SystemTime) -> (PathBuf, u64) {
#[cfg(test)]
mod tests {
- use super::is_gallery_url;
+ use super::{is_bulk_media_url, is_gallery_url};
#[test]
fn matches_curated_gallery_hosts() {
@@ -322,4 +371,27 @@ mod tests {
assert!(!is_gallery_url("https://example.com/image.jpg"));
assert!(!is_gallery_url("not a url"));
}
+
+ #[test]
+ fn bulk_matches_subreddits_and_profiles() {
+ assert!(is_bulk_media_url("https://www.reddit.com/r/pics"));
+ assert!(is_bulk_media_url("https://www.reddit.com/r/pics/top"));
+ assert!(is_bulk_media_url("https://reddit.com/user/spez"));
+ assert!(is_bulk_media_url("https://www.reddit.com/u/spez/submitted"));
+ assert!(is_bulk_media_url("https://twitter.com/nasa"));
+ assert!(is_bulk_media_url("https://x.com/nasa/media"));
+ }
+
+ #[test]
+ fn bulk_ignores_single_posts_and_app_routes() {
+ assert!(!is_bulk_media_url(
+ "https://www.reddit.com/r/pics/comments/abc123/title/"
+ ));
+ assert!(!is_bulk_media_url("https://v.redd.it/abc"));
+ assert!(!is_bulk_media_url("https://x.com/nasa/status/123456"));
+ assert!(!is_bulk_media_url("https://x.com/home"));
+ assert!(!is_bulk_media_url("https://twitter.com/i/web/status/1"));
+ assert!(!is_bulk_media_url("https://x.com/search?q=foo"));
+ assert!(!is_bulk_media_url("https://www.reddit.com/"));
+ }
}
diff --git a/src/routes/convert/+page.svelte b/src/routes/convert/+page.svelte
index e7156394..23bec5e7 100644
--- a/src/routes/convert/+page.svelte
+++ b/src/routes/convert/+page.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
+ import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { open } from "@tauri-apps/plugin-dialog";
import { onMount } from "svelte";
import { t } from "$lib/i18n";
@@ -38,7 +39,7 @@
let pluginStatus = $state<PluginStatus>("checking");
let loadError = $state<PluginLoadError | null>(null);
- onMount(async () => {
+ async function checkPluginStatus() {
try {
const plugins = await invoke<{
id: string;
@@ -64,10 +65,33 @@
}
return;
}
+ loadError = null;
pluginStatus = "ready";
} catch {
pluginStatus = "ready";
}
+ }
+
+ onMount(() => {
+ let pluginsUnlisten: UnlistenFn | null = null;
+ let destroyed = false;
+
+ checkPluginStatus();
+ listen("plugins-changed", () => {
+ checkPluginStatus();
+ }).then((unlisten) => {
+ if (destroyed) {
+ unlisten();
+ } else {
+ pluginsUnlisten = unlisten;
+ }
+ });
+
+ return () => {
+ destroyed = true;
+ pluginsUnlisten?.();
+ pluginsUnlisten = null;
+ };
});
let files = $derived(getFiles());
diff --git a/src/routes/telegram/+page.svelte b/src/routes/telegram/+page.svelte
index 719d3f43..65dbf322 100644
--- a/src/routes/telegram/+page.svelte
+++ b/src/routes/telegram/+page.svelte
@@ -252,7 +252,7 @@
}
}
- onMount(async () => {
+ async function checkPluginStatus() {
try {
const plugins = await invoke<{
id: string;
@@ -278,10 +278,33 @@
}
return;
}
+ loadError = null;
pluginStatus = "ready";
} catch {
pluginStatus = "ready";
}
+ }
+
+ onMount(() => {
+ let pluginsUnlisten: UnlistenFn | null = null;
+ let destroyed = false;
+
+ checkPluginStatus();
+ listen("plugins-changed", () => {
+ checkPluginStatus();
+ }).then((unlisten) => {
+ if (destroyed) {
+ unlisten();
+ } else {
+ pluginsUnlisten = unlisten;
+ }
+ });
+
+ return () => {
+ destroyed = true;
+ pluginsUnlisten?.();
+ pluginsUnlisten = null;
+ };
});
$effect(() => {