Repository navigation
[feat] assets: import a video from a web page link - #634
Conversation
## summary
- Stage the video on a supported web page as an upload
(PUT uploads/{handle}/url) and register it with the existing
asset.import command, so the edit lease is only needed for the short
staging write. The handle records its link: the same link answers
without downloading again and another link is rejected (409). The
route ends the download when the client disconnects.
- Download in a separate worker process with yt-dlp site extractors
only, selecting formats yt-dlp fetches directly over HTTP(S). Inside
the worker yt-dlp may start only ffmpeg/ffprobe on local files and
deno; external downloaders, PhantomJS and section downloads are
refused, so every network request is yt-dlp's own. It connects directly,
without the system proxy, and its resolver refuses any answer that the
shared public-address check rejects, so redirects, media servers and
host-agnostic extractors cannot reach loopback, private, reserved or
multicast addresses. Cancellation, the timeout and the end of the
calling process (the worker exits when its stdin closes) end the
worker's whole process tree. The worker starts with -X utf8 -P and
answers in ASCII JSON, so non-ASCII titles and paths survive a
non-UTF-8 Windows code page. Playlists, live streams and sources over 15 minutes or
512 MB are refused; an unknown size is counted while downloading.
Browser-playable codecs (H.264, VP9, AV1) are preferred up to 1080p.
- CLI: asset import-url downloads on the CLI machine and registers
through the asset import path; in an Agent turn the file stays in the
execution directory and is published with artifact.publish. Repeating
an --operation-id with the same link replays its receipt before any
download; another link under the same ID is rejected.
- A bundled Agent skill points link requests to asset import-url, so
the Agent no longer resolves and curls a site's original file, and
treats a refusal as final instead of fetching the link another way.
- Canvas: "Import video from link" in the canvas New node menu opens a
dialog whose Cancel ends the download, and places the imported video
as a node.
- Keep the url_import_* messages in one bilingual table in the domain
(domain/url_import.py), used by the HTTP layer and the CLI, so CLI and
Agent errors follow OPENDIRECTOR_LANGUAGE like HTTP errors follow
Accept-Language.
- Add yt-dlp as a dependency and document the feature in the user and
CLI guides.
Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
WITHHOLD c17f2f3 Refs #185 Refs #187 Independent pre-review (AI subagent,
Ran: Advisory score: 82/100
Highest-priority remaining action: let Release checks settle on |
david6666666
left a comment
There was a problem hiding this comment.
REQUEST CHANGES c17f2f3 Refs #185 #187
当前证据暂定 82/100,非批准分。 范围 3/3、正确性 2/3、验证 2/3、主张证据 3/3、简洁度 2/3。下载并解码了 158 秒演示,核对了画布导入、刷新后回放和 CLI 放置;作者的运行记录还覆盖了下载中取消与 Agent 两种语言。发现一个演示未覆盖的窗口:下载已结束、画布还在等素材登记或查询时点取消,同一工程里仍可能稍后插入节点,详见行内。
读了变更和受影响路径,没有自己运行 PR 代码。CodeQL、DSH 已绿,Release 仍待结果;Agent 的实际运行范围以作者记录为准。先补登记尾段取消的回归,再确认 CI。
English: Honor cancellation before adding a canvas node, including when asset registration or resource lookup is already in flight.
Dot,代表 @david6666666 作非表决评审。
| notify(t("canvas.workspace.toast.importCancelledSwitched")); | ||
| return; | ||
| } | ||
| const where = point ?? center(); |
There was a problem hiding this comment.
这里等完素材查询后只判断工程有没有切换,没有再看取消信号。下载已完成、登记或查询还在等时,用户点「取消」会关掉弹窗,但同一工程仍可能稍后新增节点。建议在提交画布命令前再检查 signal,并加一个等待登记回执时取消的用例;如果素材已登记,也请明确取消只阻止放置,不承诺撤销资产。
There was a problem hiding this comment.
Thanks, fixed in ed472ab.
- The placement decision moved into
importLinkedVideo(src/canvas/workspace/linkImport.ts): after the registration and the asset lookup it checks the project switch, then the cancel signal, and only then sends the canvas command. Nothing is awaited between that check andadd-nodes. - If the asset was already registered when the user cancels, Cancel only prevents placement. The asset stays in the asset library and is not undone, and a toast says so (
canvas.linkImport.cancelledRegistered, zh/en). The user guide (en/zh) now says the same, replacing "the video is still added". - New case in
tests/creationClient.test.ts: cancelling while theasset.importreceipt is pending, and cancelling during the asset lookup, both place no node and keep the registered asset (noDELETE). It fails without the new check. Not cancelled → placed; project switched → not placed.
npm test 1072 passed, tsc --noEmit, build, check:i18n clean.
Cancelling the link dialog while the registration receipt or the asset lookup was still pending closed the dialog, but the node could still be added to the same canvas afterwards. Check the cancel signal right before the canvas command; a video registered before the cancel stays in the asset library and the toast says so. Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Import a video from a web page link, from the canvas, the CLI and the Agent. This is the URL-ingestion step of "start from a reference video" (#185, #187). Analysing the imported video is left to the reference shot breakdown in #606.
PUT /api/creation/projects/{id}/uploads/{handle}/urldownloads the page's video into an upload handle (CreationAssets.stage_url). Registration stays the existingasset.importcommand, so provenance, receipts, replay and validation are those of a local upload, and the edit lease is only needed for the short staging write.UploadOwner.sourceUrl): the same link on a staged handle answers without downloading again; another link, or a cancelled handle, returns 409url_import_handle_conflictbefore any download.stage_urlstops the copy, cancels the handle itself (the client'sDELETEcan lose the race against the handle lock) and returnsurl_import_cancelled, so no staged copy is left behind.media/downloads.py→media/download_worker.py): yt-dlp runs in a separate worker process, so its network and resolver can be constrained without touching the server process.allowed_extractors: ['default', '-generic']). That alone is not a boundary, because some site extractors (e.g. Mediasite) accept any host. The worker therefore wrapssocket.getaddrinfo: every name it resolves (the page, redirects, API and media hosts) must resolve only to addresses accepted by the sharedhttp_settings.public_addresscheck (now a public helper also used by_public_pin), so loopback, private, link-local, CGNAT, reserved (including NAT64 and IPv4-compatible), multicast and IPv4-mapped private answers fail the connection withurl_import_private.protocolhttp/https, so HLS, DASH-segment, RTMP and other streams are never selected, and results withsection_start/section_end(which yt-dlp always hands to ffmpeg) are refused (url_import_unsupported). In addition the worker confines yt-dlp:subprocess.Popen(which yt-dlp's ownPopenwraps) may start onlyffmpeg/ffprobe(merging and probing local files) anddeno(started by yt-dlp without network permission), so PhantomJS, rtmpdump, curl, aria2c and other programs are refused; andExternalFD.real_download, the base of every external downloader includingFFmpegFD, is disabled. The worker connects directly (proxy: '', proxy variables removed from its environment) and disablescurl_cffi, which resolves names in libcurl. Literal private hosts, non-http(s) schemes and credentials in the URL are refused before the worker starts.max_filesize; an unknown size is counted from progress events across all files of the download and stops once it exceeds 512 MB. A missing output file reportsurl_import_failed, not "too large". The worker runs in its own process group (a separate session on POSIX,taskkill /Ton Windows); cancellation and the 30-minute timeout kill the whole tree, including any ffmpeg merge. The caller keeps the worker's stdin open; when it closes (the caller exits or is killed, e.g. a stopped Agent turn), the worker kills its own process group, so on POSIX no download outlives its caller. On Windows the worker exits, but an ffmpeg it started may run to completion. The worker starts with-X utf8 -P(UTF-8 I/O; the current/execution directory is not put onsys.path) and answers in ASCII JSON, so non-ASCII titles and paths survive a non-UTF-8 Windows code page.stage_urlchecks cancellation after the download, during the copy into the handle and after it. Browser-playable codecs (H.264, VP9, AV1) up to 1080p are preferred, then the best available format.canvas.linkImport.cancelledRegistered).opendirector asset import-url URL [--name] [--output-dir]downloads on the CLI machine with the samedownload_videoand registers through the same code asasset import(HTTP upload, orartifact.publishfrom the execution directory in an Agent turn). The receipt addsassetIdand the source page (url,title,site,durationSeconds).PUT …/url: the HTTP CLI holds a 60-second, non-renewed edit lease, so a server-side download longer than that would lose it before staging, and an Agent turn must register from its execution directory throughartifact.publish. Downloading first keeps the lease for the registration only, as forasset import.uuid5(operation, url). Repeating an--operation-idwith the same link returns the stored receipt (replayed: true) before any download; another link under that ID returns 409url_import_operation_conflict. In an Agent turn a retry reuses the file already in the execution directory.video-link-importskill points link requests to this command and tells the Agent that a refusal is final: it must not fetch the same link another way (see the Agent runs below for why).url_import_invalid|private|unsupported|failed|timeout|unavailable|playlist|live|too_long|too_large|cancelled|handle_conflict|operation_conflict. One bilingual table in the domain (domain/url_import.py, liketimeline_errors.py) is used by the HTTP layer (Accept-Language) and by the CLI error output (OPENDIRECTOR_LANGUAGE), so canvas, CLI and Agent errors are all bilingual; the domain keeps the Chinese text, as elsewhere.Big Buck Bunny Trailer 400p.webm); the link itself is not stored in the project. Recording it would need a new provenance field; I left that for Feature: start a short film from a reference video (YouTube / TikTok / Reel / local) #185/Feature: start a short from a reference video (YouTube / TikTok / Reel / local) #187 if their analysis needs it.yt-dlp>=2026.11.23(Unlicense, pure Python, no extras), pinned inrequirements.txt. It has no upper bound because site extractors are fixed continuously in new date-versioned releases; a cap would freeze broken extractors. Sites that need yt-dlp's JavaScript runtime components (e.g. YouTube) are not specially supported; the docs say so and failures returnurl_import_failedwith the site's reason.Question for maintainers
#187 is
needs-design. This PR makes yt-dlp a hard dependency, limited to site extractors, public addresses, direct connections and a size/duration budget, with the user told to import only videos they have the right to use. If you would rather keep it optional (an extra), allow a configured proxy, or limit it to specific sites, I can change that.Linked issue
Refs #185, Refs #187 — only the "accept a public video URL as input" criterion; analysis, concepts and cost estimates are out of scope. Related: #171 / #606 (shot breakdown).
Fixes #NorRefs #Nis included, or no issue appliesLabels
type:feat,area:assets,area:canvas,area:agent,modality:videoTest plan
Local on
c17f2f3773081f2998146293d78c8eec8d45447bunless noted:pytest tests -q: 3329 passed, 121 skipped, 0 failed. (In one earlier full run on this machine,test_native_runtime::test_cancel_native_process_groupfailed in all four parameters on both this branch and unmodifiedmaincf566d49; it has passed in every run since.)pytest tests/test_video_link_import.py(58 passed; an earlier set of 50 also passed 10 consecutive runs):url_import_private, and the server received no request;m3u8,m3u8_native,http_dash_segmentsorrtmp(manifest, AES key and segment on a local 127.0.0.1 server) is refused as unsupported and the server receives no request; adding a direct format on 127.0.0.1 is refused by the resolver guard, again with no request;section_start/section_endand a direct format on 127.0.0.1 is refused before anything is fetched (the reviewer's ffmpeg repro, now with no request);confine,Popenrefusesphantomjs,curl,aria2candrtmpdump, still startsffprobe, andFFmpegFD.real_downloadraises;download_videois killed with SIGTERM to its process group; the worker and a child it started are both gone within 5 s;cp936orcp1252returns the title中文标题 Caféand a path under中文目录 Caféintact (both fail without the ASCII-JSON fix);url_import_unavailable, garbage output →url_import_failed, a successful result is returned; the real worker reports an unsupported site without a network request;asset.import, does not download twice, rejects the same handle with another link (409), and a cancelled staging leaves no handle or asset;cancelledwith onlyowner.jsonin its folder (nocontent, no partial file) and no asset;url_import_privateandurl_import_failed(with the site's detail) in English underOPENDIRECTOR_LANGUAGE=en-USand in Chinese underzh-CN;--operation-idreplay without a second download or asset, another link under the same ID rejected withurl_import_operation_conflict, a private link rejected with no download. Replaying an operation whose receipt was rejected returns that receipt instead of reporting a different link.tests/creationClient.test.ts: the client stages viaPUT …/url, registers once, and a cancelled import is not registered and deletes its handle. Sinceed472ab7: cancelling while the registration receipt is pending, or during the asset lookup, places no node and keeps the registered asset (noDELETE); without the cancel check before the canvas command this test fails. Not cancelled → placed; project switched → not placed.npm test(1071 passed, 0 failed),npx tsc --noEmit,npm run build,npm run check:i18n(0 problems),scripts/generate_contracts.py --check,lint-imports,pre-commit run --from-ref origin/main --to-ref HEAD.url_import_too_largewith no file; withmax_filesizeremoved, the progress-hook budget stopped the real download at about 0.5 MB →url_import_too_large.ed472ab756401a6efca651011aa995498fbb24e2(review feedback, cancel after registration):npm test1072 passed,npx tsc --noEmit,npm run build,npm run check:i18n(0 problems), pre-commit on the changed files. The pre-review score below is for the first commit.cf566d4941b059b03686370f7dc97a819865d2bc, headc17f2f3773081f2998146293d78c8eec8d45447b.Its remaining findings, none blocking: Windows teardown has not been run (see Gaps);
confinerelies on yt-dlp internals (ExternalFD) with no upper version bound, failing closed asurl_import_failedif they change; the CLI keeps its replay rule in the adapter, asasset importdoes; client-disconnect cancellation through the real route is covered by the smoke receipt, not an automated test.Sign in to confirm you're not a bot, HTTP 412, login required); a home connection was not tested. Real downloads used Wikimedia Commons only, single-file formats; no real separate video+audio merge was exercised. Stream-only (HLS/DASH) videos and sections are deliberately unsupported, and so are sites that need PhantomJS. A configured system proxy is deliberately not used. Only the Default (OpenCode) Agent runtime was run; runtimes that sandbox the network may block the CLI-side download, in which case the user can import from the canvas. Nothing was run on Windows:taskkill /T, the stdin-EOF exit and the code-page handling are covered only by the POSIX runs and the forced-encoding test.Evidence that it works
Served from this branch on a separate data directory. Everything in this section (walkthrough, screenshots, smoke receipt, Agent runs) ran on this head
c17f2f37; the project names in the window titles carry the commit. Input: Big Buck Bunny Trailer 400p (Blender Foundation, CC BY 3.0). The cancel demo uses Sintel (CC BY 3.0).Canvas and CLI walkthrough (zh-CN, 2:38):
--operation-id(replayed: True, no download), another link under that ID →url_import_operation_conflict, a private address rejected in en and zhlink-import-zh.mp4
The site offers
webm vp9/opus 426×236,mov mp4v (video only)and theogv(Theora) source. The browser-playable VP9 rendition was registered asBig Buck Bunny Trailer 400p.webm(33 s). Its first frame is a white title card, which is why a paused node looks white.Smoke receipt on this head (
driver/cli_demo.sh, then aPUT …/urlfor the 15-minute video that the client disconnects after 4 s). Afterwards the server's upload-staging directory held only the handles of the four successful imports (walkthrough, CLI, English, smoke); the cancelled imports left nothing:English UI on this head: menu entry, rejected link, imported node playing.
Real Agent (Default runtime, Qwen/Qwen3.8-27B served by vLLM), each in an empty project:
把这个链接的视频导入到画布上:<Bunny link>33abe5ca)curlCommons API,curl -o …ogv,ffprobe,asset import --help-field payload,asset import …ogv --kind video,canvas add-material.ogvregistered (not playable in Chrome)6ac8d1aeasset import-urlthencanvas add-material把这个视频导入到画布:http://192.168.1.10/media/clip.mp46ac8d1ae(before the "refusal is final" section)project show --summary;capabilities;asset import-url "<link>"→url_import_private; thencurl -fL … http://192.168.1.10/media/clip.mp4twice (connection failed)project show --summary;asset import-url "<link>"→url_import_privateImport the video from <Bunny link> onto the canvas, name it 'Bunny reference' and put it at x 600, y 200.project show --summary;asset import-url "<link>" --name "Bunny reference";canvas add-material --asset … --x 600 --y 200Bunny reference(WebM) at (600, 200), playing把这个视频导入到画布,作为后面生成的参考素材:<Bunny link>project show --summary;asset import-url "<link>" --name "Big Buck Bunny Trailer (参考)";canvas add-material --asset … --x 0 --y 0project show --summary;asset import-url "<link>"→url_import_private; nothing elseThe commands are the complete list of shell commands in each run's OpenCode trace (
agent-runs/*.opencode.jsonl, kept locally; not attached because they include the full system prompt and local paths). The Agent's shell is not sandboxed by this feature: a model that ignores the skill can still runcurlitself. The download path in OpenDirector is what this PR constrains.Provider verification
No model provider is involved in the feature. Real downloads: Wikimedia Commons through yt-dlp 2026.11.23. YouTube, Bilibili and Vimeo were attempted from the cluster and refused by the sites, as above. Unit tests use a yt-dlp double, except the Mediasite, stream-format, section, confinement and unsupported-site tests, which use the real yt-dlp offline. The Agent runs used a real self-hosted Qwen3.8-27B.
Bilingual UI
Menu item, dialog, hint, progress, success toast and all thirteen error codes ship in zh-CN and en-US. Both locales were inspected in the browser (screenshots above and the video).
🤖 Generated with Claude Code