Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/api/src/opendirector_api/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hashlib import sha256
from io import BytesIO
import asyncio
import threading
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
import json
Expand Down Expand Up @@ -33,7 +34,7 @@
from opendirector.domain.timeline_errors import timeline_error, timeline_error_message
from opendirector.infrastructure.creation_projects import CreationProjects
from opendirector.media.fonts import MAX_FONT_BYTES, inspect_font
from opendirector_api.models import AssetSource, Session
from opendirector_api.models import AssetSource, Session, UrlSource
from opendirector_api.localization import localized_receipt

from opendirector_api.localization import localized_error_for_language
Expand Down Expand Up @@ -422,6 +423,16 @@ def copy_upload(project_id: UUID, handle_id: UUID, source: AssetSource, x_opendi
return assets.stage_copy(project_id, handle_id, str(x_opendirector_session), source.projectId, source.assetId,
source.fingerprint)

@router.put('/projects/{project_id}/uploads/{handle_id}/url', response_model=UploadInfo)
async def url_upload(project_id: UUID, handle_id: UUID, source: UrlSource, request: Request,
x_opendirector_session: UUID = Header()):
stop = threading.Event()
try:
return await preview_until_disconnect(request, run_in_threadpool(
assets.stage_url, project_id, handle_id, str(x_opendirector_session), source.url, cancelled=stop.is_set))
finally:
stop.set()

@router.get('/projects/{project_id}/uploads/{handle_id}', response_model=UploadInfo)
def upload_info(project_id: UUID, handle_id: UUID, x_opendirector_session: UUID = Header()):
return assets.uploads.info(project_id, handle_id, str(x_opendirector_session))
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/opendirector_api/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


from opendirector.domain.timeline_errors import timeline_error_message
from opendirector.domain.url_import import url_import_message

from opendirector.domain.creation.commands import CommandReceipt
from opendirector.domain.capabilities import Capability
Expand Down Expand Up @@ -195,7 +196,7 @@ def localized_error_for_language(
code: str = "operation_rejected",
required_capability: Capability | None = None,
) -> str:
specific = timeline_error_message(code, language)
specific = timeline_error_message(code, language) or url_import_message(code, language, chinese)
if specific is not None:
return specific
if not wants_english_language(language):
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/opendirector_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class AssetSource(Model):
fingerprint: str | None = Field(default=None, max_length=128, description='Expected source content; a different one is refused.')


class UrlSource(Model):
url: str = Field(min_length=1, max_length=2048)


class ModelConnection(Model):
connectionType: Literal['api', 'self_hosted'] = 'api'
protocol: Literal['openai', 'volcengine', 'higgsfield_open', 'bigmodel_video', 'kling_video', 'minimax_video_v2', 'vllm_omni', 'vllm_omni_segmentation', 'vllm_omni_music', 'vllm_omni_depth', 'vllm_omni_score'] | None = None
Expand Down
11 changes: 11 additions & 0 deletions docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ An unsuccessful Agent export to its macOS/Linux execution directory can leave an
In an Agent execution context, files must remain inside the authorized execution directory and commands remain scoped to that context. `timeline default-font` returns a read-only installation path; copy that font into the authorized execution directory before using `asset import`. The installation path does not bypass that boundary. Package commands do not require an open editor. MP4 rendering requires the browser. Editable JSON describes same-project structure; FCPXML and legacy XML media bundles refuse text overlays.


## 从链接导入视频 / Import a video from a link

```bash
opendirector --project PROJECT_UUID asset import-url "https://commons.wikimedia.org/wiki/File:EXAMPLE.webm"
opendirector --project PROJECT_UUID canvas add-material --asset ASSET_UUID --x 0 --y 0
```

`asset import-url` 只启用 yt-dlp 的站点解析器(不启用通用解析器),只选择可直接通过 HTTP(S) 下载的文件格式(只以 HLS/DASH 分片流或片段形式提供的视频返回 `url_import_unsupported`);下载进程中 yt-dlp 只能启动处理本地文件的 ffmpeg/ffprobe 和无网络权限的 deno,外部下载器、PhantomJS 等其他程序一律拒绝,因此所有网络请求都经过下方的地址检查,拒绝播放列表和直播,视频最长 15 分钟、512 MB(大小未知时在下载过程中累计,超出即停止)。下载在独立进程中直连完成,不使用系统代理;该进程的每次域名解析(包括跳转和媒体服务器)只要得到本机、局域网、链路本地、保留(含 NAT64)或组播等非公网地址就拒绝连接,返回 `url_import_private`;取消、超时或调用方进程退出(包括 Agent 轮次被停止)都会结束下载进程及其启动的子进程;在 Windows 上,调用方被强行结束时下载进程会退出,但它启动的 ffmpeg 等子进程可能自行运行到结束。下载在 CLI 所在机器完成,再走与 `asset import` 相同的登记路径,因此编辑租约只用于最后的登记,长时间下载不会占用编辑权。回执包含 `assetId` 和来源页面 `source`(链接、标题、站点、时长)。Agent 执行时文件保存在执行目录的 `downloads/` 下并在回执 `file` 中给出;其他情况使用临时目录,可用 `--output-dir` 保留。重复使用同一 `--operation-id` 和同一链接时,先查原回执并直接返回(`replayed: true`),不再下载;同一 `--operation-id` 换用其他链接返回 `url_import_operation_conflict`。Agent 执行时复用执行目录中已下载的文件。可用站点取决于 yt-dlp 的站点解析器:部分网站会拦截服务器或机房 IP,YouTube 等站点还可能需要 yt-dlp 的 JavaScript 运行时组件(本功能不安装),此时返回 `url_import_failed` 及原因,请改为下载后用 `asset import` 登记。画布中的「从链接导入视频」由服务端下载到上传暂存区(同一句柄只对应一个链接,换链接返回 `url_import_handle_conflict`),再执行同一 `asset.import`;关闭对话框或断开连接会结束下载进程,不登记素材。

`asset import-url` enables only yt-dlp's site extractors (not the generic extractor), selects only formats downloaded directly over HTTP(S) (videos offered only as HLS/DASH segment streams or as sections return `url_import_unsupported`); inside the download process yt-dlp may start only ffmpeg/ffprobe on local files and deno without network permission, while external downloaders, PhantomJS and other programs are refused, so every network request passes the address check below, refuses playlists and live streams, and limits videos to 15 minutes and 512 MB; when the size is unknown it is counted during the download, which stops once the limit is exceeded. The download runs in a separate process that connects directly, without the system proxy. Every name that process resolves, including redirects and media servers, must resolve only to public addresses; loopback, private, link-local, reserved (including NAT64), multicast and other non-public answers refuse the connection with `url_import_private`. Cancellation, the timeout or the end of the calling process (including a stopped Agent turn) ends the download process and anything it started; on Windows, when the caller itself is killed, the download process exits but an ffmpeg it started may run to completion. The CLI downloads on its own machine and then registers through the same path as `asset import`, so the edit lease is held only for registration, not for the download. The receipt includes `assetId` and the source page (`url`, `title`, `site`, `durationSeconds`). In an Agent turn the file is kept under `downloads/` in the execution directory and reported as `file`; otherwise a temporary directory is used unless `--output-dir` is given. Repeating the same `--operation-id` with the same link returns the original receipt (`replayed: true`) without downloading again; the same `--operation-id` with a different link returns `url_import_operation_conflict`. In an Agent turn the downloaded file in the execution directory is reused. Which sites work depends on yt-dlp's site extractors: some sites block server and data-centre addresses, and sites such as YouTube can additionally need yt-dlp's JavaScript runtime components, which this feature does not install. Such failures return `url_import_failed` with the reason; download the file manually and register it with `asset import`. The canvas **Import video from link** action downloads on the server into an upload handle (one link per handle; another link returns `url_import_handle_conflict`) and then runs the same `asset.import`. Closing the dialog or disconnecting ends the download process and registers nothing.

## Voice library

`opendirector voice list --model MODEL_CONFIG_UUID` reads the full library and returns the selected model's connection identity, voices and adapter requirements. For a large MOSS library, request up to 150 voices per page.
Expand Down
9 changes: 9 additions & 0 deletions docs/guides/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ Select a node, then choose an action from its toolbar.

For a local edit, mark an area or create a selection first, then enter your instructions and confirm the action. If a required model capability is missing, follow the tool's instructions to configure it. Hover over a disabled control for an explanation.

### Import a video from a link

Right-click the canvas, choose **New node → Import video from link**, and paste the page of a single video. OpenDirector downloads it on the computer that runs the app, registers it as a video asset and adds it as a video node, ready for references, trimming or other video tools.

- One video page on a supported site, up to 15 minutes and 512 MB. Playlists, live streams and videos offered only as segmented streams (HLS/DASH) are not supported. Every connection the download makes, including redirects and media servers, must go to a public internet address; this computer and the local network are refused. Link import connects directly, without the system proxy.
- Cancel stops the download and registers nothing. If the video was already registered when you cancelled, Cancel only stops it from being placed: the asset stays in the asset library and is not removed.
- Which sites work depends on the yt-dlp downloader. Some sites block downloads from servers or data centres, and some (such as YouTube) may need extra yt-dlp components. If the import fails, download the file yourself and use **Upload**.
- Import only videos you have the right to use. The asset is named after the page title; the link itself is not stored in the project.

## Arrange and export videos

1. Create a timeline node and open its editor.
Expand Down
9 changes: 9 additions & 0 deletions docs/guides/user-guide.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ Codex 网页检索引用在具有匹配来源时显示为编号链接;复制

需要局部修改时先标记区域或创建选区,再填写要求并确认执行。缺少所需模型能力时,按工具提示补充配置;灰色入口以悬停提示为准。

### 从链接导入视频

右键画布,选择 **新建节点 → 从链接导入视频**,粘贴单个视频的网页链接。OpenDirector 在运行应用的电脑上下载视频,登记为视频素材并添加为视频节点,之后可作参考、修剪或使用其他视频工具。

- 支持常见视频网站的单个视频页面,最长 15 分钟、512 MB。不支持播放列表、直播以及只以分片流(HLS/DASH)提供的视频。下载过程中的每个连接(包括跳转和媒体服务器)都必须指向公网地址,本机或局域网地址会被拒绝;链接导入直接连接,不使用系统代理。
- 点击「取消」会停止下载,不登记素材。如果取消时素材已经登记完成,取消只会阻止它被放到画布上:素材保留在资产库中,不会被删除。
- 可用站点取决于 yt-dlp 下载组件:部分网站会拦截服务器或机房的下载,部分网站(如 YouTube)可能需要额外的 yt-dlp 组件。导入失败时,可自行下载后使用 **上传**。
- 请只导入你有权使用的视频。素材以网页标题命名,工程中不保存链接本身。

## 编排和导出视频

1. 创建时间线节点并打开编辑器。
Expand Down
42 changes: 42 additions & 0 deletions packages/agent/skills/video-link-import/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: video-link-import
description: 从视频网页链接(yt-dlp 支持的站点上的单个视频页面)导入视频到工程和画布:使用 opendirector asset import-url,不要自己用 curl/wget 拼直链下载。Use when the user gives a video page URL and wants the video in the project, on the canvas, or as a reference.
---

# Video link import / 从链接导入视频

`opendirector asset import-url` downloads the video on a page with the site's
own extractor, prefers a format the browser can play (H.264, VP9 or AV1 up to
1080p), and registers it through the same path as `asset import`. Do not
resolve direct file URLs with curl or wget: a page's original file may be a
format the canvas cannot play.

## Steps

1. Read the canvas with `opendirector project show --summary` to choose a
free position.
2. `opendirector asset import-url "URL"` — add `--name` for a custom title.
The receipt returns `assetId` and `source` (`url`, `title`, `site`,
`durationSeconds`); in an Agent turn `file` is the downloaded copy in the
execution directory.
3. `opendirector canvas add-material --asset ASSET_ID --x X --y Y` shows it
on the canvas.

## When the import is refused

A refusal is final for that link. Never fetch the same link another way
(curl, wget, Python, a browser tool or a different URL for the same host),
even if the user gave a direct file URL: the refusal is a security or policy
check, not a transport problem. Report the error code and ask the user to
upload the file or give a public page of a single video.

- `url_import_private`: the link points to this computer or a local or
private network.
- `url_import_playlist`, `url_import_live`, `url_import_too_long`,
`url_import_too_large`, `url_import_unsupported`: ask for a single video
page of at most 15 minutes and 512 MB that is offered as a file, not only as
a stream.
- `url_import_failed`: the site refused or failed, often because it blocks
server downloads; ask the user to download the file and upload it.

Import only videos the user has the right to use.
30 changes: 30 additions & 0 deletions packages/core/src/opendirector/application/creation_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from opendirector.domain.creation.project import ProjectSnapshot
from opendirector.domain.creation.validation import ContractError
from opendirector.domain.projects import ProjectError
from opendirector.domain.url_import import url_import_error
from opendirector.media.downloads import download_video, validate_url, video_filename
from opendirector.media.processing import open_image, png
from opendirector.ports.files import (
AssetFileWrite, CHUNK_BYTES, MAX_CREATION_TEXT_BYTES, stream_identity,
Expand Down Expand Up @@ -48,6 +50,34 @@ def stage_copy(self, project_id, handle, session, source_project_id, source_asse
finally:
writer.abort()

def stage_url(self, project_id, handle, session, url, *, cancelled=None):
url = validate_url(url)
owner = self.uploads.owner(project_id, handle, session)
if owner is not None:
if owner.sourceUrl != url or owner.cancelled:
raise url_import_error('url_import_handle_conflict')
staged = self.uploads.info(project_id, handle, session)
if staged.status in {'ready', 'registered'}:
return staged
stopped = cancelled or (lambda: False)
with TemporaryDirectory(prefix='opendirector-url-') as folder:
video = download_video(url, Path(folder), cancelled=cancelled)
if stopped():
raise url_import_error('url_import_cancelled')
writer = self.uploads.begin(project_id, handle, session, video_filename(video.title, video.path.suffix or '.mp4'),
expected_kind='video', source_url=url)
try:
with video.path.open('rb') as stream:
while (chunk := stream.read(CHUNK_BYTES)) and not stopped():
writer.write(chunk)
staged = None if stopped() else writer.finish()
finally:
writer.abort()
if stopped():
self.uploads.cancel(project_id, handle, session)
raise url_import_error('url_import_cancelled')
return staged

def reference_available(self, project_id, asset_id, *, snapshot=None):
stream, asset = self.open_media(project_id, asset_id, snapshot=snapshot)
return self.check_reference_media(stream, asset)
Expand Down
Loading
Loading