Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
feat: add context menu for downloading media and enhance media detection capabilities
Tonho4de7e8b13da7
diff --git a/browser-extension/chrome/manifest.json b/browser-extension/chrome/manifest.jsonindex ac50765d..b081cd11 100644--- a/browser-extension/chrome/manifest.json+++ b/browser-extension/chrome/manifest.json@@ -10,7 +10,8 @@"tabs","cookies","webRequest",- "storage"+ "storage",+ "contextMenus"],"host_permissions": ["*://*/*"diff --git a/browser-extension/chrome/popup/popup.js b/browser-extension/chrome/popup/popup.jsindex b2e634d7..e1ead359 100644--- a/browser-extension/chrome/popup/popup.js+++ b/browser-extension/chrome/popup/popup.js@@ -84,11 +84,12 @@ function renderMediaDetected(container) {const directVideo = nonHls.filter(m => m.contentLength > 500 * 1024);const totalVideos = groups.length + directVideo.filter(m => m.mediaType === "video").length;- const domain = getDomainFromUrl(best.url);+ const domain = getDomainFromUrl(currentData.tabUrl || best.url);+ const title = pageTitle ? truncate(pageTitle, 40) : domain;const countText = totalVideos > 1 ? `${totalVideos} videos found` : "Video found";- const label = best.mediaType === "audio" ? "Download audio" : "Download video";+ const label = best.mediaType === "audio" ? "Send audio" : "Send to OmniGet";- appendPrimaryButton(container, label, domain + " \u00b7 " + countText, (btn) => {+ appendPrimaryButton(container, label, title + " \u00b7 " + countText, (btn) => {handleDownload(btn, best.url, "generic", best);});@@ -97,8 +98,8 @@ function renderMediaDetected(container) {function renderListening(container) {container.innerHTML = `- <div class="state-empty">- <div class="listening-dot"></div>+ <div class="state-empty" role="status">+ <div class="listening-dot" aria-hidden="true"></div><span class="state-title">Listening for media\u2026</span><span class="state-hint">Videos and audio will appear here<br>as pages load them.</span></div>@@ -107,7 +108,7 @@ function renderListening(container) {function renderSnifferOff(container) {container.innerHTML = `- <div class="state-empty">+ <div class="state-empty" role="status"><span class="state-title">Media detection is paused</span><span class="state-hint">Turn on the toggle above to<br>detect videos on this page.</span></div>@@ -147,11 +148,11 @@ function appendMediaControls(container, media) {const btn = document.createElement("button");btn.className = "secondary-btn";- btn.setAttribute("aria-label", `Download all ${groups.length} videos`);+ btn.setAttribute("aria-label", `Send all ${groups.length} videos`);btn.innerHTML = `<span class="btn-icon">${SVG.download}</span><div class="btn-content">- <span class="btn-label">Download all (${groups.length} videos)</span>+ <span class="btn-label">Send all (${groups.length} videos)</span></div>`;@@ -254,7 +255,7 @@ async function handleDownload(btn, url, platform, mediaEntry) {btn.classList.remove("sending");btn.classList.add("success");btn.querySelector(".btn-icon").innerHTML = SVG.check;- btn.querySelector(".btn-label").textContent = "Downloaded!";+ btn.querySelector(".btn-label").textContent = "Sent!";setTimeout(() => window.close(), 1000);} else {showError(btn.closest(".primary-action"));@@ -274,7 +275,7 @@ async function handleBatchDownload(btn, groups) {btn.classList.remove("sending");btn.classList.add("success");btn.querySelector(".btn-icon").innerHTML = SVG.check;- btn.querySelector(".btn-label").textContent = `${result.sent} videos downloaded!`;+ btn.querySelector(".btn-label").textContent = `${result.sent} videos sent!`;setTimeout(() => window.close(), 1200);} else if (result.sent > 0) {btn.classList.remove("sending");@@ -309,6 +310,7 @@ function sendToApp(url, platform, mediaEntry) {return new Promise((resolve) => {const msg = { type: "sendToOmniGet", url, platform };+ if (pageTitle) msg.title = pageTitle;if (currentData?.tabUrl) msg.referer = currentData.tabUrl;if (mediaEntry?.mediaType) msg.mediaType = mediaEntry.mediaType;if (mediaEntry?.contentType) msg.contentType = mediaEntry.contentType;@@ -419,9 +421,9 @@ function pickBestMedia(media) {function getDownloadLabel(contentType) {switch (contentType) {- case "course": return "Download this course";- case "playlist": return "Download playlist";- default: return "Download this video";+ case "course": return "Send to OmniGet";+ case "playlist": return "Send playlist";+ default: return "Send to OmniGet";}}diff --git a/browser-extension/chrome/src/background.js b/browser-extension/chrome/src/background.jsindex 0ab88ec0..6c390c44 100644--- a/browser-extension/chrome/src/background.js+++ b/browser-extension/chrome/src/background.js@@ -1,8 +1,9 @@import { extractCookiesForPlatform } from "./cookies.js";import { detectSupportedMediaUrl } from "./detect.js";import { createActionFeedbackController } from "./action-feedback.js";-import { registerSnifferListeners, getMediaCount, getDetectedMedia } from "./media-sniffer.js";+import { registerSnifferListeners, getMediaCount, getDetectedMedia, restoreMedia } from "./media-sniffer.js";import { loadSnifferState, isSnifferEnabled, setSnifferEnabled } from "./sniffer-toggle.js";+import { registerContextMenu, getContextMenuId } from "./context-menu.js";const HOST_NAME = "wtf.tonho.omniget";const INSTALL_URL = "https://github.com/tonhowtf/omniget/releases/latest";@@ -37,7 +38,8 @@ const actionFeedback = createActionFeedbackController({let snifferRegistered = false;-loadSnifferState().then((enabled) => {+loadSnifferState().then(async (enabled) => {+ await restoreMedia();if (enabled) {registerSnifferListeners(onMediaDetected);snifferRegistered = true;@@ -45,9 +47,28 @@ loadSnifferState().then((enabled) => {});chrome.runtime.onInstalled.addListener(() => {+ registerContextMenu();refreshActiveTab().catch(() => {});});+chrome.contextMenus.onClicked.addListener(async (info, tab) => {+ if (info.menuItemId !== getContextMenuId()) return;++ const url = info.linkUrl || info.srcUrl;+ if (!url) return;++ const result = await handleSendToApp({+ type: "sendToOmniGet",+ url,+ platform: "generic",+ referer: tab?.url || "",+ });++ if (result.ok) {+ actionFeedback.showSuccessBadge(tab?.id);+ }+});+chrome.runtime.onStartup.addListener(() => {refreshActiveTab().catch(() => {});});@@ -134,6 +155,12 @@ async function handleSendToApp(msg) {const url = msg.url;const platform = msg.platform || "generic";+ let pageTitle = "";+ try {+ const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });+ pageTitle = tab?.title || "";+ } catch {}+let cookies = null;try {const platformCookies = await extractCookiesForPlatform(platform);@@ -159,6 +186,8 @@ async function handleSendToApp(msg) {const message = { type: "enqueue", url };if (cookies) message.cookies = cookies;if (msg.referer) message.referer = msg.referer;+ if (msg.title) message.title = msg.title;+ else if (pageTitle) message.title = pageTitle;if (msg.mediaType) message.mediaType = msg.mediaType;if (msg.contentType) message.contentType = msg.contentType;if (msg.headers) message.headers = msg.headers;diff --git a/browser-extension/chrome/src/context-menu.js b/browser-extension/chrome/src/context-menu.jsnew file mode 100644index 00000000..4adf4dc2--- /dev/null+++ b/browser-extension/chrome/src/context-menu.js@@ -0,0 +1,15 @@+const MENU_ID = "omniget-download";++export function registerContextMenu() {+ chrome.contextMenus.removeAll(() => {+ chrome.contextMenus.create({+ id: MENU_ID,+ title: "Download with OmniGet",+ contexts: ["link", "video", "audio", "image"],+ });+ });+}++export function getContextMenuId() {+ return MENU_ID;+}diff --git a/browser-extension/chrome/src/cookies.js b/browser-extension/chrome/src/cookies.jsindex f4fe56cc..8306b223 100644--- a/browser-extension/chrome/src/cookies.js+++ b/browser-extension/chrome/src/cookies.js@@ -1,12 +1,15 @@const PLATFORM_COOKIE_DOMAINS = Object.freeze({youtube: [".youtube.com", ".google.com"],- instagram: [".instagram.com"],- tiktok: [".tiktok.com"],+ instagram: [".instagram.com", ".cdninstagram.com", ".fbcdn.net"],+ tiktok: [".tiktok.com", ".tiktokcdn.com"],twitter: [".twitter.com", ".x.com"],reddit: [".reddit.com"],- twitch: [".twitch.tv"],- vimeo: [".vimeo.com"],- bilibili: [".bilibili.com"],+ twitch: [".twitch.tv", ".jtvnw.net"],+ vimeo: [".vimeo.com", ".vimeocdn.com"],+ bilibili: [".bilibili.com", ".bilivideo.com"],+ pinterest: [".pinterest.com"],+ hotmart: [".hotmart.com"],+ udemy: [".udemy.com"],});export async function extractCookiesForPlatform(platform, getAllCookies = defaultGetAllCookies) {diff --git a/browser-extension/chrome/src/media-sniffer.js b/browser-extension/chrome/src/media-sniffer.jsindex 5134fab8..b046bd18 100644--- a/browser-extension/chrome/src/media-sniffer.js+++ b/browser-extension/chrome/src/media-sniffer.js@@ -3,18 +3,37 @@ const MEDIA_CONTENT_TYPES = ["video/webm","video/x-flv","video/ogg",+ "video/x-matroska",+ "video/3gpp",+ "video/mpeg",+ "video/x-msvideo",+ "video/x-ms-wmv",+ "video/quicktime","audio/mpeg","audio/ogg","audio/mp4",+ "audio/webm",+ "audio/aac",+ "audio/wav",+ "audio/x-wav",+ "audio/flac",+ "audio/x-flac",+ "audio/x-m4a",+ "audio/x-ms-wma",+ "audio/opus","application/vnd.apple.mpegurl","application/x-mpegurl","application/dash+xml",+ "application/f4m+xml",];const MEDIA_EXTENSIONS = [".mp4", ".webm", ".m3u8", ".mpd",".flv", ".ogg", ".mp3", ".m4a", ".m4v",- ".mkv", ".avi", ".mov",+ ".mkv", ".avi", ".mov", ".wmv",+ ".wav", ".flac", ".aac", ".opus",+ ".3gp", ".mpg", ".mpeg", ".divx",+ ".f4m", ".f4v", ".ts",];const BLOCKED_HOSTS = [@@ -23,9 +42,36 @@ const BLOCKED_HOSTS = ["facebook.com","doubleclick.net","analytics",+ "ads.google.com",+ "ad.doubleclick.net",+ "adservice.google.com",+ "pagead2.googlesyndication.com",+ "cdn.mxpnl.com",+ "stats.wp.com",+ "pixel.facebook.com",+ "connect.facebook.net",+ "scorecardresearch.com",+ "hotjar.com",+ "sentry.io",+ "newrelic.com",+ "nr-data.net",+ "segment.io",+ "segment.com",+ "amplitude.com",+ "mixpanel.com",+ "cdn.heapanalytics.com",];-const MIN_CONTENT_LENGTH = 100 * 1024;+const PLATFORM_CDN_HOSTS = [+ "cdninstagram.com",+ "fbcdn.net",+ "instagram.fna.fbcdn.net",+ "tiktokcdn.com",+ "musical.ly",+ "tiktokcdn-us.com",+];++const MIN_CONTENT_LENGTH = 50 * 1024;const detectedMedia = new Map();const pendingRequests = new Map();@@ -91,26 +137,67 @@ function formatSize(bytes) {function isHlsSegment(url, contentType) {const ct = contentType.toLowerCase();- if (ct.includes("mp2t") || ct.includes("mpeg2-ts") || ct.includes("mpeg-ts")) {+ if (ct.includes("mp2t") || ct.includes("mpeg2-ts") || ct.includes("mpeg-ts") || ct.includes("video/mp2t")) {return true;}try {const path = new URL(url).pathname.toLowerCase();- if (path.endsWith(".ts") || path.match(/\.ts\?/)) {- return true;- }- if (/\/video\d+\.ts/.test(path)) {- return true;+ if (path.match(/\/seg-\d+/)) return true;+ if (path.match(/\/segment\d+/)) return true;+ if (path.match(/\/chunk-/)) return true;+ if (path.match(/\/media_\d+/)) return true;+ if (path.endsWith(".ts") && !path.endsWith(".m3u8.ts")) {+ const parts = path.split("/");+ const filename = parts[parts.length - 1];+ if (/^\d+\.ts$/.test(filename) || /^seg[-_]\d+\.ts$/.test(filename)) return true;+ if (/video\d+\.ts/.test(filename)) return true;}} catch {}return false;}+function isPlatformCdnFragment(url, contentType, contentLength) {+ try {+ const host = new URL(url).hostname;+ const isPlatformCdn = PLATFORM_CDN_HOSTS.some(cdn => host.includes(cdn));+ if (!isPlatformCdn) return false;+ if (contentLength > 0 && contentLength < 5 * 1024 * 1024) return true;+ const ct = contentType.toLowerCase();+ if (ct.includes("octet-stream")) return true;+ return false;+ } catch { return false; }+}++function persistMedia(tabId) {+ const media = detectedMedia.get(tabId);+ if (!media || media.size === 0) return;+ const arr = Array.from(media.entries());+ chrome.storage.session.set({ [`media_${tabId}`]: arr }).catch(() => {});+}++export async function restoreMedia() {+ try {+ const data = await chrome.storage.session.get(null);+ for (const [key, value] of Object.entries(data)) {+ if (!key.startsWith("media_")) continue;+ const tabId = parseInt(key.replace("media_", ""));+ if (isNaN(tabId)) continue;+ const map = new Map(value);+ detectedMedia.set(tabId, map);+ }+ } catch {}+}+export function registerSnifferListeners(onMediaDetected) {chrome.webRequest.onSendHeaders.addListener((details) => {if (details.tabId < 0) return;- if (details.method !== "GET") return;+ if (details.method !== "GET") {+ try {+ const host = new URL(details.url).hostname;+ if (!host.includes("googlevideo")) return;+ } catch { return; }+ }pendingRequests.set(details.requestId, {requestHeaders: details.requestHeaders || [],@@ -131,9 +218,10 @@ export function registerSnifferListeners(onMediaDetected) {const contentType = getContentType(details.responseHeaders);const contentLength = getContentLength(details.responseHeaders);+ const isOctetStream = contentType.toLowerCase().includes("application/octet-stream");const isMedia = isMediaByContentType(contentType) || isMediaByExtension(url);- if (!isMedia) {+ if (!isMedia && !(isOctetStream && isMediaByExtension(url))) {pendingRequests.delete(details.requestId);return;}@@ -144,7 +232,8 @@ export function registerSnifferListeners(onMediaDetected) {}if (contentLength > 0 && contentLength < MIN_CONTENT_LENGTH) {- if (!url.includes(".m3u8") && !contentType.includes("mpegurl")) {+ if (!url.includes(".m3u8") && !url.includes(".mpd") &&+ !contentType.includes("mpegurl") && !contentType.includes("dash")) {pendingRequests.delete(details.requestId);return;}@@ -171,6 +260,7 @@ export function registerSnifferListeners(onMediaDetected) {detectedMedia.set(details.tabId, new Map());}detectedMedia.get(details.tabId).set(url, entry);+ persistMedia(details.tabId);onMediaDetected(details.tabId, entry);},@@ -185,11 +275,13 @@ export function registerSnifferListeners(onMediaDetected) {chrome.tabs.onRemoved.addListener((tabId) => {detectedMedia.delete(tabId);+ chrome.storage.session.remove(`media_${tabId}`).catch(() => {});});chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {if (changeInfo.url) {detectedMedia.delete(tabId);+ chrome.storage.session.remove(`media_${tabId}`).catch(() => {});}});}