Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

test(yt-dlp): execute download with installed package resource resolution

kashorin1da4e02ad8bd
diff --git a/packages/yt-dlp/README.md b/packages/yt-dlp/README.md
index 964f759d..72575cb4 100644
--- a/packages/yt-dlp/README.md
+++ b/packages/yt-dlp/README.md
@@ -17,8 +17,9 @@ Runtime Profile and creates no Build.
- `downloadVideo(url, target)` downloads one video to the given path. Its caller owns destination
preparation and overwrite policy. The target extension must be `.mp4`, `.mkv`, `.webm` or `.mov`.
-The downloader invokes the locked Python project in `services/yt-dlp` through `uv`, located relative
-to the installed Distribution. Ship its `pyproject.toml` and `uv.lock` with this package's source.
+The downloader locates its declared `@hypit/yt-dlp-service-runtime` package through the active
+Distribution/package resolver and invokes that package's locked Python project through `uv`.
+Ship its `pyproject.toml` and `uv.lock`; the caller's location and a `services/` ancestor are irrelevant.
`uv` and `ffmpeg` must be available on PATH; the CLI also uses `ffprobe` to report the saved media.
The request selects `bv*+ba/b`, with `res:1080,vcodec:h264` format preferences and `--no-playlist`.
diff --git a/packages/yt-dlp/test/download.test.ts b/packages/yt-dlp/test/download.test.ts
index cdc5b868..52260b09 100644
--- a/packages/yt-dlp/test/download.test.ts
+++ b/packages/yt-dlp/test/download.test.ts
@@ -1,5 +1,10 @@
import assert from "node:assert/strict";
-import { existsSync } from "node:fs";
+import { existsSync, writeFileSync } from "node:fs";
+import { cp, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { pathToFileURL } from "node:url";
+import childProcess from "node:child_process";
+import { syncBuiltinESMExports } from "node:module";
import { dirname, join } from "node:path";
import test from "node:test";
@@ -16,6 +21,43 @@ test("only http and https links are fetched; Windows paths stay files", () => {
assert.equal(isVideoUrl("/tmp/clip.mp4"), false);
});
+test("download resolves its declared service from an installed package outside the checkout", async (t) => {
+ const directory = await mkdtemp(join(tmpdir(), "hypit-installed-yt-dlp-"));
+ t.after(() => rm(directory, { recursive: true, force: true }));
+ const modules = join(directory, "node_modules", "@hypit");
+ const installed = join(modules, "yt-dlp");
+ const service = join(modules, "yt-dlp-service-runtime");
+ const loader = join(modules, "package-loader-node");
+ await mkdir(join(installed, "src"), { recursive: true });
+ await mkdir(service, { recursive: true });
+ await mkdir(loader, { recursive: true });
+ await cp(new URL("../package.json", import.meta.url), join(installed, "package.json"));
+ await cp(new URL("../src/download.ts", import.meta.url), join(installed, "src", "download.ts"));
+ const sourceService = dirname(resolveNodePackageResource("@hypit/yt-dlp-service-runtime", "pyproject.toml", { from: import.meta.url }));
+ for (const name of ["package.json", "pyproject.toml", "uv.lock"]) await cp(join(sourceService, name), join(service, name));
+ // Forward only the real locator implementation; no workspace links or services/ ancestor exists.
+ await writeFile(join(loader, "package.json"), JSON.stringify({ name: "@hypit/package-loader-node", type: "module", exports: "./index.mjs" }));
+ await writeFile(join(loader, "index.mjs"), `export { resolveNodePackageResource } from ${JSON.stringify(import.meta.resolve("@hypit/package-loader-node"))};`);
+ let calls = 0;
+ t.mock.method(childProcess, "spawnSync", (command: string, args: string[]) => {
+ calls++;
+ assert.equal(command, "uv");
+ assert.deepEqual(args.slice(0, 5), ["run", "--project", servicePath, "--frozen", "yt-dlp"]);
+ assert.equal(args.at(-1), "https://example.test/video");
+ const output = args[args.indexOf("--output") + 1]!.replace("%(ext)s", "mp4");
+ writeFileSync(output, "downloaded bytes");
+ return { status: 0, stderr: "", stdout: "" };
+ });
+ syncBuiltinESMExports();
+ t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
+ const servicePath = await realpath(service);
+ const module = await import(pathToFileURL(join(installed, "src", "download.ts")).href);
+ const target = join(directory, "reference.mp4");
+ await module.downloadVideo("https://example.test/video", target);
+ assert.equal(await readFile(target, "utf8"), "downloaded bytes");
+ assert.equal(calls, 1);
+});
+
test("the pinned yt-dlp project is a Distribution package asset", () => {
const project = dirname(resolveNodePackageResource(
"@hypit/yt-dlp-service-runtime",