Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Media list: X's videos named after the tab, not their random file name (part of #493) (#505)

Ahmed Nefzaouib0b34d49de15
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b744b0c..3ae83d06 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- X (Twitter) videos sent from the browser's media list are named after the tab, not the random name of their file on X's video server ([#493](https://github.com/anefzaoui/misterdownloadmanager/issues/493)).
- Windows: **Open folder** on a download opens the folder with the file manager set up to open folders (Directory Opus, for example), instead of always starting Windows Explorer. With Explorer it still selects the file ([#446](https://github.com/anefzaoui/misterdownloadmanager/issues/446)).
## [0.5.2] - 2026-11-09
diff --git a/ROADMAP.md b/ROADMAP.md
index c0274edd..a503db70 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -543,6 +543,8 @@ These ship in a later version, when they're ready.
([#321](https://github.com/anefzaoui/misterdownloadmanager/issues/321)): fix in review
- πŸ”„ **Open folder** on a torrent still downloading
([#354](https://github.com/anefzaoui/misterdownloadmanager/issues/354)): fix in review
+- πŸ”„ X (Twitter) videos from the media list named after the tab instead of a random file name
+ ([#493](https://github.com/anefzaoui/misterdownloadmanager/issues/493)): fix in review
- πŸ”„ **Open folder** on Windows always starting Explorer, even with another file manager set up
to open folders ([#446](https://github.com/anefzaoui/misterdownloadmanager/issues/446)): fix in review
- πŸ”„ Alt and F10 opening the menu bar with a control focused
diff --git a/extension/background.js b/extension/background.js
index e19b6b59..e51bcf77 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -917,16 +917,18 @@ async function mediaList(tabId) {
return out;
}
-// A file's name from the tab's title when its address ends in a long hash (#345); else, with the
-// popup's switch on (`includeOriginal`), the title before the address's own name; else none: the
-// app names it from the address, as for any download.
+// A file's name from the tab's title when its address ends in a long hash (#345) or is on a
+// server whose names are all random ids (#493: X's video.twimg.com, too short for the hash test);
+// else, with the popup's switch on (`includeOriginal`), the title before the address's own name;
+// else none: the app names it from the address, as for any download.
function titledName(url, title, includeOriginal = false) {
const last = pathOf(url).split("/").pop() || "";
const dot = last.lastIndexOf(".");
const stem = dot > 0 ? last.slice(0, dot) : last;
const name = String(title || "").replace(/[\\/:*?"<>|]/g, " ").trim().slice(0, 150);
const hash = stem.length >= 24 && /^[A-Za-z0-9=_-]+$/.test(stem) && (stem.match(/[-_]/g) || []).length <= 2;
- if (hash && name) return `${name}${dot > 0 ? last.slice(dot) : ""}`;
+ const randomServer = siteOf(url).toLowerCase() === "video.twimg.com";
+ if ((hash || randomServer) && name) return `${name}${dot > 0 ? last.slice(dot) : ""}`;
if (!includeOriginal || !name) return "";
const original = addressName(url).replace(/[\\/:*?"<>|\x00-\x1f]/g, " ").trim();
return original && original !== "." && original !== ".." ? `${name} - ${original}` : "";
diff --git a/tools/extension/test.mjs b/tools/extension/test.mjs
index 39d09795..76a33fea 100644
--- a/tools/extension/test.mjs
+++ b/tools/extension/test.mjs
@@ -819,6 +819,12 @@ const MPD = (protect) => `<?xml version="1.0"?>
assert.equal(natives(calls).filter((m) => m.url === hashed).at(-1).filename, "A film.mp4");
await api.storage.local.set({ mediaTitleName: false });
assert.equal(natives(calls).find((m) => m.url === hashed).filename, "A film.mp4");
+ // #493: X's video server names each file with a short random id: the tab's title names it.
+ const random = "https://video.twimg.com/ext_tw_video/1900000000000000000/pu/vid/avc1/720x1280/7HbL0kYxzF-fGjqd.mp4?tag=12";
+ listeners.responseStarted({ tabId: 9, frameId: 0, type: "media", url: random, responseHeaders: [{ name: "Content-Type", value: "video/mp4" }, { name: "Content-Length", value: "52428800" }] });
+ await settle();
+ await popupAsk(listeners, { type: "media-download", tab: 9, url: random });
+ assert.equal(natives(calls).find((m) => m.url === random).filename, "A film.mp4");
const before = natives(calls).length;
assert.deepEqual(await popupAsk(listeners, { type: "media-download", tab: 9, url: "https://drm.test/p/manifest.mpd" }), { ok: false, why: "drm" });
assert.deepEqual(await popupAsk(listeners, { type: "media-download", tab: 9, url: "https://evil.test/x.mp4" }), { ok: false, why: "gone" });
@@ -828,7 +834,7 @@ const MPD = (protect) => `<?xml version="1.0"?>
// A move within the page keeps the list; another page clears it; so does closing the tab.
listeners.tabUpdated(9, { url: "https://watch.test/v/1#t=30" });
await settle();
- assert.equal((await popupAsk(listeners, { type: "media", tab: 9 })).media.length, 10);
+ assert.equal((await popupAsk(listeners, { type: "media", tab: 9 })).media.length, 11);
listeners.tabUpdated(9, { url: "https://watch.test/v/2" });
await settle();
assert.equal((await popupAsk(listeners, { type: "media", tab: 9 })).media.length, 0);