Skip to content

The only downloader you need. 下载器的集大成者。

fix(Browser Extension): Instagram DASH 解析失效与抖音 DASH 预加载兜底

XiaoYouChR25e67d477848
diff --git a/browser_extension/app/public/_locales/en_US/messages.json b/browser_extension/app/public/_locales/en_US/messages.json
index 8af010d7..11c27a79 100644
--- a/browser_extension/app/public/_locales/en_US/messages.json
+++ b/browser_extension/app/public/_locales/en_US/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "Download with Ghost Downloader"
},
+ "saveAsWithGhostDownloader": {
+ "message": "Save As with Ghost Downloader"
+ },
"downloading": {
"message": "Downloading"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "Waiting for Douyin audio/video separate tracks"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "Waiting for Instagram audio/video separate tracks"
+ },
"waitingForResource": {
"message": "Waiting for resource…"
},
diff --git a/browser_extension/app/public/_locales/ja/messages.json b/browser_extension/app/public/_locales/ja/messages.json
index 53c3184e..51b1e38d 100644
--- a/browser_extension/app/public/_locales/ja/messages.json
+++ b/browser_extension/app/public/_locales/ja/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "Ghost Downloader でダウンロード"
},
+ "saveAsWithGhostDownloader": {
+ "message": "Ghost Downloader で名前を付けて保存"
+ },
"downloading": {
"message": "ダウンロード中"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "Douyin の音声・動画トラックが揃うのを待機中"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "Instagram の音声・動画トラックが揃うのを待機中"
+ },
"waitingForResource": {
"message": "リソース待機中…"
},
diff --git a/browser_extension/app/public/_locales/pt_BR/messages.json b/browser_extension/app/public/_locales/pt_BR/messages.json
index 951dbdc4..4faf1b54 100644
--- a/browser_extension/app/public/_locales/pt_BR/messages.json
+++ b/browser_extension/app/public/_locales/pt_BR/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "Baixar com Ghost Downloader"
},
+ "saveAsWithGhostDownloader": {
+ "message": "Salvar como com Ghost Downloader"
+ },
"downloading": {
"message": "Baixando"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "Aguardando faixas de áudio e vídeo separadas do Douyin"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "Aguardando faixas de áudio e vídeo separadas do Instagram"
+ },
"waitingForResource": {
"message": "Aguardando recurso…"
},
diff --git a/browser_extension/app/public/_locales/ru/messages.json b/browser_extension/app/public/_locales/ru/messages.json
index 9221e209..3ed7d986 100644
--- a/browser_extension/app/public/_locales/ru/messages.json
+++ b/browser_extension/app/public/_locales/ru/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "Скачать через Ghost Downloader"
},
+ "saveAsWithGhostDownloader": {
+ "message": "Сохранить как через Ghost Downloader"
+ },
"downloading": {
"message": "Загрузка"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "Ожидание готовности раздельных аудио и видео дорожек Douyin"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "Ожидание готовности раздельных аудио и видео дорожек Instagram"
+ },
"waitingForResource": {
"message": "Ожидание ресурса…"
},
diff --git a/browser_extension/app/public/_locales/zh_CN/messages.json b/browser_extension/app/public/_locales/zh_CN/messages.json
index ea01dc1e..f9d48e96 100644
--- a/browser_extension/app/public/_locales/zh_CN/messages.json
+++ b/browser_extension/app/public/_locales/zh_CN/messages.json
@@ -107,6 +107,9 @@
"downloadWithGhostDownloader": {
"message": "使用 Ghost Downloader 下载"
},
+ "saveAsWithGhostDownloader": {
+ "message": "用 Ghost Downloader 另存为"
+ },
"downloading": {
"message": "下载中"
},
@@ -747,6 +750,9 @@
"waitingForDouyinSeparateTracks": {
"message": "等待 Douyin 音视频分轨齐全"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "等待 Instagram 音视频分轨齐全"
+ },
"waitingForResource": {
"message": "等待资源…"
},
diff --git a/browser_extension/app/public/_locales/zh_HK/messages.json b/browser_extension/app/public/_locales/zh_HK/messages.json
index 9417de09..8fc626f6 100644
--- a/browser_extension/app/public/_locales/zh_HK/messages.json
+++ b/browser_extension/app/public/_locales/zh_HK/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "使用 Ghost Downloader 下載"
},
+ "saveAsWithGhostDownloader": {
+ "message": "用 Ghost Downloader 另存為"
+ },
"downloading": {
"message": "下載中"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "等待 Douyin 音影片分軌齊全"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "等待 Instagram 音影片分軌齊全"
+ },
"waitingForResource": {
"message": "等待資源…"
},
diff --git a/browser_extension/app/public/_locales/zh_TW/messages.json b/browser_extension/app/public/_locales/zh_TW/messages.json
index b640c801..2d5dba48 100644
--- a/browser_extension/app/public/_locales/zh_TW/messages.json
+++ b/browser_extension/app/public/_locales/zh_TW/messages.json
@@ -91,6 +91,9 @@
"downloadWithGhostDownloader": {
"message": "使用 Ghost Downloader 下載"
},
+ "saveAsWithGhostDownloader": {
+ "message": "用 Ghost Downloader 另存為"
+ },
"downloading": {
"message": "下載中"
},
@@ -641,6 +644,9 @@
"waitingForDouyinSeparateTracks": {
"message": "等待 Douyin 音視訊分軌齊全"
},
+ "waitingForInstagramSeparateTracks": {
+ "message": "等待 Instagram 音視訊分軌齊全"
+ },
"waitingForResource": {
"message": "等待資源…"
},
diff --git a/browser_extension/app/src/page-media/attribution/attribution.ts b/browser_extension/app/src/page-media/attribution/attribution.ts
index cc915959..e89b5d44 100644
--- a/browser_extension/app/src/page-media/attribution/attribution.ts
+++ b/browser_extension/app/src/page-media/attribution/attribution.ts
@@ -1,5 +1,6 @@
import {isCatCatchMedia} from "../../shared/cat-catch";
import {fileExtension, filenameFromUrl, mimeFromUrl} from "../../shared/utils";
+import {instagramAssetId, isInstagramCdnUrl} from "../resolution/url-classify";
import {AttributionLedger} from "./attribution-ledger";
import {selectMediaForPage} from "../resolution/strategy";
@@ -53,6 +54,10 @@ function urlIdHints(url: string): Set<string> {
const value = parsed.searchParams.get(key);
if (value && value.length >= 4) { result.add(`${key}=${value}`); }
}
+ if (isInstagramCdnUrl(url)) {
+ const assetId = instagramAssetId(url);
+ if (assetId) { result.add(`xpv_asset_id=${assetId}`); }
+ }
return result;
}
diff --git a/browser_extension/app/src/page-media/resolution/strategies/douyin.ts b/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
index 37770c76..a4ce2caf 100644
--- a/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
+++ b/browser_extension/app/src/page-media/resolution/strategies/douyin.ts
@@ -18,9 +18,10 @@ export function selectDouyin(ctx: ResolveContext, findUrlsByIdHint: FindUrlsById
}
if (ctx.clicked.formKind === "dash") {
- const pair = selectMergePair(post, douyinKindOf);
- if (pair) {
- return { kind: "selection", selection: { kind: "merge", video: pair.video, audio: pair.audio } };
+ const video = newestMatching(post, (url) => douyinKindOf(url) === "video") ?? findByModalId(ctx, findUrlsByIdHint, "video");
+ const audio = newestMatching(post, (url) => douyinKindOf(url) === "audio") ?? findByModalId(ctx, findUrlsByIdHint, "audio");
+ if (video && audio) {
+ return { kind: "selection", selection: { kind: "merge", video, audio } };
}
return { kind: "pending", reason: chrome.i18n.getMessage("waitingForDouyinSeparateTracks") };
}
diff --git a/browser_extension/app/src/page-media/resolution/strategies/instagram.ts b/browser_extension/app/src/page-media/resolution/strategies/instagram.ts
new file mode 100644
index 00000000..18051382
--- /dev/null
+++ b/browser_extension/app/src/page-media/resolution/strategies/instagram.ts
@@ -0,0 +1,44 @@
+import {instagramAssetId, instagramKindOf, isInstagramCdnUrl, stripRangeParams} from "../url-classify";
+import {newestMatching, postBindAttributedUrls, selectMergePair} from "../strategy";
+import type {FindUrlsByIdHint, ResolveContext} from "../strategy";
+import type {Resolution} from "../../types";
+
+export function selectInstagram(ctx: ResolveContext, findUrlsByIdHint: FindUrlsByIdHint): Resolution {
+ const post = postBindAttributedUrls(ctx.clicked).filter((r) => isInstagramCdnUrl(r.url));
+
+ if (ctx.clicked.formKind === "dash") {
+ const pair = selectMergePair(post, instagramKindOf) ?? findPairByAssetId(post, findUrlsByIdHint);
+ if (pair) {
+ return { kind: "selection", selection: { kind: "merge", video: stripRangeParams(pair.video), audio: stripRangeParams(pair.audio) } };
+ }
+ return { kind: "pending", reason: chrome.i18n.getMessage("waitingForInstagramSeparateTracks") };
+ }
+
+ if (post.length === 0) {
+ return { kind: "pending", reason: chrome.i18n.getMessage("waitingForVideoResource") };
+ }
+ const pair = selectMergePair(post, instagramKindOf);
+ if (pair) {
+ return { kind: "selection", selection: { kind: "merge", video: stripRangeParams(pair.video), audio: stripRangeParams(pair.audio) } };
+ }
+ return { kind: "pending", reason: chrome.i18n.getMessage("waitingForInstagramSeparateTracks") };
+}
+
+// Extract xpv_asset_id from any URL we already have, then search all sessions for
+// sibling tracks with the same asset ID — rescues prefetched URLs still owned by a
+// sibling session.
+function findPairByAssetId(
+ post: ReturnType<typeof postBindAttributedUrls>,
+ findUrlsByIdHint: FindUrlsByIdHint,
+): { video: string; audio: string } | null {
+ let assetId = "";
+ for (const entry of post) {
+ assetId = instagramAssetId(entry.url);
+ if (assetId) { break; }
+ }
+ if (!assetId) { return null; }
+ const matches = findUrlsByIdHint(`xpv_asset_id=${assetId}`);
+ const video = newestMatching(matches, (url) => instagramKindOf(url) === "video");
+ const audio = newestMatching(matches, (url) => instagramKindOf(url) === "audio");
+ return video && audio ? { video, audio } : null;
+}
diff --git a/browser_extension/app/src/page-media/resolution/strategy.ts b/browser_extension/app/src/page-media/resolution/strategy.ts
index ae578211..e0091192 100644
--- a/browser_extension/app/src/page-media/resolution/strategy.ts
+++ b/browser_extension/app/src/page-media/resolution/strategy.ts
@@ -1,5 +1,6 @@
import {selectDouyin} from "./strategies/douyin";
import {selectGeneric} from "./strategies/generic";
+import {selectInstagram} from "./strategies/instagram";
import {selectX} from "./strategies/x";
import {selectYouTube} from "./strategies/youtube";
import type {Resolution, VideoSessionFormKind} from "../types";
@@ -44,6 +45,9 @@ export function selectMediaForPage(ctx: ResolveContext, findUrlsByIdHint: FindUr
if (host === "www.douyin.com" || host.endsWith(".douyin.com")) {
return selectDouyin(ctx, findUrlsByIdHint);
}
+ if (host === "www.instagram.com" || host.endsWith(".instagram.com")) {
+ return selectInstagram(ctx, findUrlsByIdHint);
+ }
if (host === "youtube.com" || host.endsWith(".youtube.com") || host === "youtu.be") {
return selectYouTube(ctx);
}
diff --git a/browser_extension/app/src/page-media/resolution/url-classify.ts b/browser_extension/app/src/page-media/resolution/url-classify.ts
index 642994c4..782ba62d 100644
--- a/browser_extension/app/src/page-media/resolution/url-classify.ts
+++ b/browser_extension/app/src/page-media/resolution/url-classify.ts
@@ -53,6 +53,44 @@ export function douyinKindOf(url: string): "video" | "audio" | "muxed" | "" {
return "";
}
+export function isInstagramCdnUrl(url: string): boolean {
+ return hostEndsWith(url, "cdninstagram.com") || hostEndsWith(url, "fbcdn.net");
+}
+
+function parseEfg(url: string): Record<string, unknown> | null {
+ try {
+ const efg = new URL(url).searchParams.get("efg");
+ if (!efg) { return null; }
+ return JSON.parse(atob(efg));
+ } catch {
+ return null;
+ }
+}
+
+export function instagramVencodeTag(url: string): string {
+ const efg = parseEfg(url);
+ if (!efg || typeof efg !== "object") { return ""; }
+ const tag = (efg as Record<string, unknown>).vencode_tag;
+ return typeof tag === "string" ? tag : "";
+}
+
+export function instagramAssetId(url: string): string {
+ const efg = parseEfg(url);
+ if (!efg || typeof efg !== "object") { return ""; }
+ const id = (efg as Record<string, unknown>).xpv_asset_id;
+ if (typeof id === "string") { return id; }
+ if (typeof id === "number") { return String(id); }
+ return "";
+}
+
+export function instagramKindOf(url: string): "video" | "audio" | "" {
+ const tag = instagramVencodeTag(url);
+ if (!tag) { return ""; }
+ if (tag.includes("_audio")) { return "audio"; }
+ if (tag.includes("dash_")) { return "video"; }
+ return "";
+}
+
export function classifyTrackRole(url: string, contentType: string): TrackRole {
const douyin = douyinKindOf(url);
if (douyin === "muxed") { return "muxed"; }