feat(ddownload): resolve metadata before queueing
Inspect public ddownload.com and ddl.to links before download startup to resolve canonical filenames, exact sizes and availability without consuming a debrid account. Keep removed files offline, protected pages retryable, restored queues recheckable and previously resolved names safe from later download.bin responses. Reuse the metadata path in the link collector, queue import and direct DDownload login flow.
This commit is contained in:
@@ -62,11 +62,11 @@ describe("collector inspection", () => {
|
||||
"https://example.com/a",
|
||||
"https://example.com/a",
|
||||
"# Package: Staffel B",
|
||||
"https://example.com/b"
|
||||
"https://example.com/abcdef1234567890abcdef12"
|
||||
].join("\n");
|
||||
|
||||
const result = await inspectCollectorText({ rawText, addedAt: 2000 }, defaultSettings(), {
|
||||
resolveFilenames: async () => new Map([["https://example.com/b", "episode.part02.rar"]])
|
||||
resolveFilenames: async () => new Map([["https://example.com/abcdef1234567890abcdef12", "episode.part02.rar"]])
|
||||
});
|
||||
|
||||
expect(result.packages.map((pkg) => pkg.name)).toEqual(["Staffel A", "Staffel B"]);
|
||||
@@ -100,6 +100,34 @@ describe("collector inspection", () => {
|
||||
}));
|
||||
});
|
||||
|
||||
it("resolves DDownload metadata before grouping without using a debrid account", async () => {
|
||||
const link = "https://ddownload.com/ntwscdw62gyb";
|
||||
let genericResolverCalls = 0;
|
||||
const result = await inspectCollectorText({ rawText: link, addedAt: 3500 }, defaultSettings(), {
|
||||
checkDdownload: async () => ({
|
||||
online: true,
|
||||
fileName: "SBS14HD.part02.rar",
|
||||
fileSizeBytes: 526_385_152
|
||||
}),
|
||||
resolveFilenames: async () => {
|
||||
genericResolverCalls += 1;
|
||||
return new Map();
|
||||
}
|
||||
});
|
||||
|
||||
expect(genericResolverCalls).toBe(0);
|
||||
expect(result.packages).toHaveLength(1);
|
||||
expect(result.packages[0].name).toBe("SBS14HD");
|
||||
expect(result.packages[0].links).toEqual([expect.objectContaining({
|
||||
url: link,
|
||||
fileName: "SBS14HD.part02.rar",
|
||||
fileSizeBytes: 526_385_152,
|
||||
hoster: "ddownload",
|
||||
availability: "online",
|
||||
status: "ready"
|
||||
})]);
|
||||
});
|
||||
|
||||
it("infers archive package names and serializes inspected metadata for the existing queue parser", () => {
|
||||
expect(inferCollectorPackageName("SBS14HD.part01.rar", "1fichier")).toBe("SBS14HD");
|
||||
expect(inferCollectorPackageName("Archive.7z.001", "1fichier")).toBe("Archive");
|
||||
|
||||
+54
-1
@@ -5,7 +5,7 @@ import { getMegaDebridAccountId } from "../src/shared/mega-debrid-accounts";
|
||||
import { serializeRealDebridApiAccounts } from "../src/shared/real-debrid-accounts";
|
||||
import { getProviderUsageDayKey } from "../src/shared/provider-daily-limits";
|
||||
import { isMegaDebridTransientResolveFailure } from "../src/shared/mega-debrid-errors";
|
||||
import { checkOneFichierLinks, checkRapidgatorOnline, classifyMegaDebridAccountFailureForTests, clearMegaDebridEmptyResponseStreak, DebridService, extractRapidgatorFilenameFromHtml, fetchAllDebridHostInfo, fetchDebridLinkHostLimits, filenameFromRapidgatorUrlPath, getAvailableRealDebridAccounts, getDebridLinkKeyCooldownStateForTests, getDebridLinkKeyRuntimeStateForTests, getMegaDebridAccountCooldownState, getProviderRuntimeSnapshot, isOneFichierLink, leadProviderChainWith, MEGA_DEBRID_EMPTY_STREAK_UNTIL_RESTART, MEGA_DEBRID_STICKY_LINKS, normalizeResolvedFilename, parseRapidgatorFileSize, primeMegaDebridRuntimeCooldownForTests, primeMegaDebridUntilRestartForTests, recordMegaDebridEmptyResponseStreak, resetDebridLinkRuntimeStateForTests, resetMegaDebridRuntimeStateForTests, resetRealDebridRuntimeStateForTests } from "../src/main/debrid";
|
||||
import { checkDdownloadOnline, checkOneFichierLinks, checkRapidgatorOnline, classifyMegaDebridAccountFailureForTests, clearMegaDebridEmptyResponseStreak, DebridService, extractDdownloadFilenameFromHtml, extractRapidgatorFilenameFromHtml, fetchAllDebridHostInfo, fetchDebridLinkHostLimits, filenameFromDdownloadUrlPath, filenameFromRapidgatorUrlPath, getAvailableRealDebridAccounts, getDebridLinkKeyCooldownStateForTests, getDebridLinkKeyRuntimeStateForTests, getMegaDebridAccountCooldownState, getProviderRuntimeSnapshot, isDdownloadLink, isOneFichierLink, leadProviderChainWith, MEGA_DEBRID_EMPTY_STREAK_UNTIL_RESTART, MEGA_DEBRID_STICKY_LINKS, normalizeResolvedFilename, parseDdownloadFileSize, parseRapidgatorFileSize, primeMegaDebridRuntimeCooldownForTests, primeMegaDebridUntilRestartForTests, recordMegaDebridEmptyResponseStreak, resetDebridLinkRuntimeStateForTests, resetMegaDebridRuntimeStateForTests, resetRealDebridRuntimeStateForTests } from "../src/main/debrid";
|
||||
import { getAccountRuntimeSessionStats } from "../src/main/account-runtime";
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
@@ -2831,6 +2831,59 @@ describe("checkRapidgatorOnline", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("DDownload public metadata", () => {
|
||||
it("recognizes canonical and short domains without treating unrelated pages as files", () => {
|
||||
expect(isDdownloadLink("https://ddownload.com/ntwscdw62gyb")).toBe(true);
|
||||
expect(isDdownloadLink("https://ddl.to/ntwscdw62gyb/Archive.part02.rar")).toBe(true);
|
||||
expect(isDdownloadLink("https://ddownload.com/login.html")).toBe(false);
|
||||
expect(isDdownloadLink("https://example.com/ntwscdw62gyb")).toBe(false);
|
||||
});
|
||||
|
||||
it("uses a real filename from the URL but rejects a bare file code", () => {
|
||||
expect(filenameFromDdownloadUrlPath("https://ddownload.com/ntwscdw62gyb/Archive.part02.rar")).toBe("Archive.part02.rar");
|
||||
expect(filenameFromDdownloadUrlPath("https://ddownload.com/ntwscdw62gyb")).toBe("");
|
||||
});
|
||||
|
||||
it("parses the current public page name and binary size", () => {
|
||||
const html = [
|
||||
'<div class="dk-dl-icon" data-fn="Show.S01E02.German.DL.part02.rar">',
|
||||
'<h2 class="dk-dl-name">Show.S01E02.German.DL.part02.rar</h2>',
|
||||
'<p class="dk-dl-size">502.00 MB</p>'
|
||||
].join("");
|
||||
|
||||
expect(extractDdownloadFilenameFromHtml(html)).toBe("Show.S01E02.German.DL.part02.rar");
|
||||
expect(parseDdownloadFileSize("502.00 MB")).toBe(526_385_152);
|
||||
});
|
||||
|
||||
it("returns exact metadata for an online file and explicit offline state for a removed file", async () => {
|
||||
const responses = [
|
||||
new Response('<div class="dk-dl-icon" data-fn="Show.S01E02.mkv"><h2 class="dk-dl-name">Show.S01E02.mkv</h2><p class="dk-dl-size">840.02 MB</p>', { status: 200, headers: { "Content-Type": "text/html" } }),
|
||||
new Response('<main><h1>File Not Found</h1></main>', { status: 200, headers: { "Content-Type": "text/html" } })
|
||||
];
|
||||
globalThis.fetch = vi.fn(async () => responses.shift() || new Response("", { status: 500 })) as typeof fetch;
|
||||
|
||||
await expect(checkDdownloadOnline("https://ddownload.com/3nq8wruijuh4")).resolves.toEqual({
|
||||
online: true,
|
||||
fileName: "Show.S01E02.mkv",
|
||||
fileSizeBytes: 880_824_812
|
||||
});
|
||||
await expect(checkDdownloadOnline("https://ddownload.com/missing1234")).resolves.toEqual({
|
||||
online: false,
|
||||
fileName: "",
|
||||
fileSizeBytes: null
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps challenge and malformed pages unknown instead of marking them online", async () => {
|
||||
globalThis.fetch = vi.fn(async () => new Response("<html><title>Just a moment...</title></html>", {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/html" }
|
||||
})) as typeof fetch;
|
||||
|
||||
await expect(checkDdownloadOnline("https://ddownload.com/unknown1234")).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkOneFichierLinks", () => {
|
||||
it("checks at most 100 links per request and maps exact metadata", async () => {
|
||||
const links = Array.from({ length: 101 }, (_unused, index) => `https://1fichier.com/?id${String(index).padStart(5, "0")}`);
|
||||
|
||||
@@ -959,6 +959,156 @@ describe("download manager", () => {
|
||||
expect(item.onlineStatus).toBe("online");
|
||||
});
|
||||
|
||||
it("resolves DDownload names, sizes and availability after import", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-ddownload-metadata-"));
|
||||
tempDirs.push(root);
|
||||
const link = "https://ddownload.com/ntwscdw62gyb";
|
||||
let checkCalls = 0;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL): Promise<Response> => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
if (url === link) {
|
||||
checkCalls += 1;
|
||||
return new Response('<div class="dk-dl-icon" data-fn="Show.S01E02.German.DL.part02.rar"><h2 class="dk-dl-name">Show.S01E02.German.DL.part02.rar</h2><p class="dk-dl-size">502.00 MB</p>', {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/html" }
|
||||
});
|
||||
}
|
||||
return new Response("not-found", { status: 404 });
|
||||
}) as typeof fetch;
|
||||
|
||||
const manager = new DownloadManager(defaultSettings(), emptySession(), createStoragePaths(path.join(root, "state")));
|
||||
manager.addPackages([{ name: "ddownload", links: [link] }]);
|
||||
|
||||
await waitFor(() => Object.values(manager.getSnapshot().session.items)[0]?.onlineStatus === "online", 2_000);
|
||||
const downloadedItem = Object.values(manager.getSnapshot().session.items)[0];
|
||||
|
||||
expect(checkCalls).toBe(1);
|
||||
expect(downloadedItem.fileName).toBe("Show.S01E02.German.DL.part02.rar");
|
||||
expect(downloadedItem.totalBytes).toBe(526_385_152);
|
||||
expect(path.basename(downloadedItem.targetPath)).toBe("Show.S01E02.German.DL.part02.rar");
|
||||
});
|
||||
|
||||
it("rechecks unresolved DDownload metadata when a queued session is restored", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-ddownload-startup-"));
|
||||
tempDirs.push(root);
|
||||
const link = "https://ddownload.com/startup1234";
|
||||
const session = emptySession();
|
||||
const paths = createStoragePaths(path.join(root, "state"));
|
||||
let page = "<html><title>Just a moment...</title></html>";
|
||||
globalThis.fetch = (async (input: RequestInfo | URL): Promise<Response> => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
if (url === link) return new Response(page, { status: 200, headers: { "Content-Type": "text/html" } });
|
||||
return new Response("not-found", { status: 404 });
|
||||
}) as typeof fetch;
|
||||
|
||||
const firstManager = new DownloadManager(defaultSettings(), session, paths);
|
||||
firstManager.addPackages([{ name: "startup", links: [link] }]);
|
||||
await waitFor(() => Object.values(session.items)[0]?.onlineStatus !== "checking", 2_000);
|
||||
const restoredItem = Object.values(session.items)[0];
|
||||
restoredItem.fileName = "download.bin";
|
||||
restoredItem.targetPath = path.join(session.packages[restoredItem.packageId].outputDir, restoredItem.fileName);
|
||||
restoredItem.totalBytes = null;
|
||||
restoredItem.onlineStatus = undefined;
|
||||
page = '<h2 class="dk-dl-name">Restored.Show.S01E01.mkv</h2><p class="dk-dl-size">1.50 GB</p>';
|
||||
|
||||
const restoredManager = new DownloadManager(defaultSettings(), session, paths);
|
||||
await waitFor(() => Object.values(restoredManager.getSnapshot().session.items)[0]?.onlineStatus === "online", 2_000);
|
||||
const checkedItem = Object.values(restoredManager.getSnapshot().session.items)[0];
|
||||
|
||||
expect(checkedItem.fileName).toBe("Restored.Show.S01E01.mkv");
|
||||
expect(checkedItem.totalBytes).toBe(1_610_612_736);
|
||||
expect(path.basename(checkedItem.targetPath)).toBe("Restored.Show.S01E01.mkv");
|
||||
});
|
||||
|
||||
it("fails removed DDownload files while keeping protected pages queued as unknown", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-ddownload-status-"));
|
||||
tempDirs.push(root);
|
||||
const missing = "https://ddownload.com/missing1234";
|
||||
const protectedLink = "https://ddownload.com/protect1234";
|
||||
globalThis.fetch = (async (input: RequestInfo | URL): Promise<Response> => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
if (url === missing) return new Response("<h1>File Not Found</h1>", { status: 200, headers: { "Content-Type": "text/html" } });
|
||||
if (url === protectedLink) return new Response("<title>Just a moment...</title>", { status: 200, headers: { "Content-Type": "text/html" } });
|
||||
return new Response("not-found", { status: 404 });
|
||||
}) as typeof fetch;
|
||||
|
||||
const manager = new DownloadManager(defaultSettings(), emptySession(), createStoragePaths(path.join(root, "state")));
|
||||
manager.addPackages([{ name: "ddownload-status", links: [missing, protectedLink] }]);
|
||||
await waitFor(() => Object.values(manager.getSnapshot().session.items).every((item) => item.onlineStatus !== "checking"), 2_000);
|
||||
const items = Object.values(manager.getSnapshot().session.items);
|
||||
|
||||
expect(items[0]).toEqual(expect.objectContaining({
|
||||
status: "failed",
|
||||
fullStatus: "Offline",
|
||||
onlineStatus: "offline",
|
||||
lastError: "Datei nicht gefunden auf DDownload"
|
||||
}));
|
||||
expect(items[1]).toEqual(expect.objectContaining({
|
||||
status: "queued",
|
||||
onlineStatus: undefined,
|
||||
totalBytes: null
|
||||
}));
|
||||
});
|
||||
|
||||
it("keeps DDownload metadata when a debrid response later returns download.bin", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-ddownload-preserve-"));
|
||||
tempDirs.push(root);
|
||||
const link = "https://ddownload.com/keep1234567";
|
||||
const expectedName = "Series.S02E03.German.DL.part01.rar";
|
||||
const binary = Buffer.alloc(192 * 1024, 31);
|
||||
const server = http.createServer((_req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Accept-Ranges", "bytes");
|
||||
res.setHeader("Content-Length", String(binary.length));
|
||||
res.end(binary);
|
||||
});
|
||||
server.listen(0, "127.0.0.1");
|
||||
await once(server, "listening");
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") throw new Error("server address unavailable");
|
||||
const directUrl = `http://127.0.0.1:${address.port}/download`;
|
||||
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
if (url === link) {
|
||||
return new Response(`<h2 class="dk-dl-name">${expectedName}</h2><p class="dk-dl-size">192 KB</p>`, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "text/html" }
|
||||
});
|
||||
}
|
||||
if (url.includes("api.real-debrid.com/rest/1.0/unrestrict/link")) {
|
||||
return new Response(JSON.stringify({ download: directUrl, filename: "download.bin", filesize: binary.length }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
return originalFetch(input, init);
|
||||
}) as typeof fetch;
|
||||
|
||||
try {
|
||||
const manager = new DownloadManager({
|
||||
...defaultSettings(),
|
||||
token: "rd-token",
|
||||
outputDir: path.join(root, "downloads"),
|
||||
extractDir: path.join(root, "extract"),
|
||||
autoExtract: false
|
||||
}, emptySession(), createStoragePaths(path.join(root, "state")));
|
||||
manager.addPackages([{ name: "ddownload-preserve", links: [link] }]);
|
||||
await waitFor(() => Object.values(manager.getSnapshot().session.items)[0]?.fileName === expectedName, 2_000);
|
||||
|
||||
await manager.start();
|
||||
await waitFor(() => !manager.getSnapshot().session.running, 15_000);
|
||||
const downloadedItem = Object.values(manager.getSnapshot().session.items)[0];
|
||||
|
||||
expect(downloadedItem.status).toBe("completed");
|
||||
expect(downloadedItem.fileName).toBe(expectedName);
|
||||
expect(path.basename(downloadedItem.targetPath)).toBe(expectedName);
|
||||
} finally {
|
||||
server.close();
|
||||
await once(server, "close");
|
||||
}
|
||||
}, 20_000);
|
||||
|
||||
it("resolves 1Fichier names, sizes and availability in one batch after import", async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-onefichier-metadata-"));
|
||||
tempDirs.push(root);
|
||||
|
||||
@@ -633,6 +633,16 @@ describe("responsive Downloadstatus und Servicebezeichnungen", () => {
|
||||
expect(formatHosterLabel(hosters[1])).toEqual({ compact: "1Fichier", title: "1Fichier", iconSrc: "./provider-icons/onefichier.png" });
|
||||
});
|
||||
|
||||
it("normalizes DDownload and ddl.to to one hoster identity", () => {
|
||||
const hosters = [
|
||||
extractHoster("https://ddownload.com/ntwscdw62gyb"),
|
||||
extractHoster("https://ddl.to/ntwscdw62gyb/Archive.part02.rar")
|
||||
];
|
||||
|
||||
expect(hosters).toEqual(["ddownload", "ddownload"]);
|
||||
expect(formatHosterLabel(hosters[1])).toEqual({ compact: "DD", title: "DDownload", iconSrc: "./provider-icons/ddownload.ico" });
|
||||
});
|
||||
|
||||
it("removes duplicated access-mode wording from service labels", () => {
|
||||
expect(normalizeDownloadServiceLabel("Mega-Debrid Web (Web Account)")).toBe("Mega-Debrid (Web)");
|
||||
expect(normalizeDownloadServiceLabel("Mega-Debrid API (API Account)")).toBe("Mega-Debrid (API)");
|
||||
|
||||
Reference in New Issue
Block a user