Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix(video-download): support agent downloads across platforms
Joshua Yin Junxi7ce0813a88d0
diff --git a/apps/daemon/src/creator/templates/video-download.ts b/apps/daemon/src/creator/templates/video-download.tsindex 2cb99b54..11676f4d 100644--- a/apps/daemon/src/creator/templates/video-download.ts+++ b/apps/daemon/src/creator/templates/video-download.ts@@ -84,9 +84,9 @@ export function createVideoDownloadTemplate(): CreatorTemplateDefinition {{ kind: 'source_audio', required: false }],agentGuidance: [- '仅支持公开的 YouTube 和 Bilibili 链接。',- '先运行 probe,再从 download_probe.options 中选择 option.id。',- '更新 selectedOptionId 和 mediaType 后运行 download;不得自行构造或写入 formatId。'+ '支持公开的 YouTube、Bilibili、X、TikTok、Instagram、抖音、Facebook、小红书和 Pinterest 视频链接,可下载视频或提取音频。',+ '先设置 sourceUrl 并运行 probe,再读取最新 download_probe.options;只选择其中与用户请求的 video 或 audio 对应的 option.id。',+ '更新 selectedOptionId 和 mediaType 后运行 download;不得自行构造或写入 formatId。若 probe 没有对应选项,再说明该链接无法提供所需媒体。'].join(' ')};}diff --git a/apps/daemon/test/unit/creator-agent-context.test.ts b/apps/daemon/test/unit/creator-agent-context.test.tsindex 98a6afbf..b5d40f20 100644--- a/apps/daemon/test/unit/creator-agent-context.test.ts+++ b/apps/daemon/test/unit/creator-agent-context.test.ts@@ -4,6 +4,27 @@ import { createAgentContextBuilder } from '../../src/creator/agent/context-buildimport { createDefaultCreatorTemplateRegistry } from '../../src/creator/templates/registry.js';describe('creator agent context', () => {+ it('tells the video download Agent to handle video and audio across supported platforms', () => {+ const builder = createAgentContextBuilder({+ templates: createDefaultCreatorTemplateRegistry()+ });+ const context = builder.build({+ ...job(),+ templateId: 'video-download',+ templateVersion: 2+ });++ for (const platform of [+ 'YouTube', 'Bilibili', 'X', 'TikTok', 'Instagram',+ '抖音', 'Facebook', '小红书', 'Pinterest'+ ]) {+ expect(context.templateGuidance).toContain(platform);+ }+ expect(context.templateGuidance).toContain('可下载视频或提取音频');+ expect(context.templateGuidance).toContain('download_probe.options');+ expect(context.templateGuidance).not.toContain('仅支持公开的 YouTube 和 Bilibili');+ });+it('projects settings, stage state and safe artifact summaries without paths or large subtitle content', () => {const builder = createAgentContextBuilder({templates: createDefaultCreatorTemplateRegistry(),diff --git a/apps/daemon/test/unit/creator-download-executor.test.ts b/apps/daemon/test/unit/creator-download-executor.test.tsindex 9928d444..74227500 100644--- a/apps/daemon/test/unit/creator-download-executor.test.ts+++ b/apps/daemon/test/unit/creator-download-executor.test.ts@@ -127,7 +127,12 @@ describe('creator download executor', () => {platform: 'xiaohongshu', requestedUrl: sourceUrl, duration: 173.454});expect(probe.options).toEqual(expect.arrayContaining([- expect.objectContaining({ mediaType: 'video', videoFormatId: '0' })+ expect.objectContaining({ mediaType: 'video', videoFormatId: '0' }),+ expect.objectContaining({+ mediaType: 'audio',+ audioFormatId: '0',+ transcode: 'mp3'+ })]));});@@ -151,6 +156,28 @@ describe('creator download executor', () => {args = JSON.parse(await readFile(join(workdir, 'args.json'), 'utf8')) as string[];expect(args).toContain(sourceUrl);+ const audioProbe = parseDownloadProbe({+ id: '6a9149f3000000001f01d20a',+ title: 'Public video note',+ extractor_key: 'XiaoHongShu',+ webpage_url: sourceUrl,+ formats: [{+ format_id: '0', ext: 'mp4', width: 1388, height: 720,+ vcodec: 'h264', acodec: 'aac'+ }]+ }, sourceUrl);+ const audioProbeArtifact = await writeProbeArtifact(workdir, audioProbe);+ const audio = await executor.run(stageInput({+ workdir, stageId: 'download',+ state: { sourceUrl, mediaType: 'audio', selectedOptionId: 'audio-mp3-192' },+ inputArtifacts: [audioProbeArtifact]+ }));+ args = JSON.parse(await readFile(join(workdir, 'args.json'), 'utf8')) as string[];+ expect(args).toEqual(expect.arrayContaining([+ '-f', '0', '--extract-audio', '--audio-format', 'mp3', sourceUrl+ ]));+ expect(audio.outputs).toEqual([expect.objectContaining({ kind: 'source_audio' })]);+for (const invalidUrl of ['https://www.xiaohongshu.com/user/profile/6a9149f3000000001f01d20a','https://notxiaohongshu.com/explore/6a9149f3000000001f01d20a',diff --git a/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx b/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsxindex 6b66763f..0ca6b428 100644--- a/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx+++ b/apps/web/src/features/dashboard/VideoDownloadWorkspace.test.tsx@@ -7,10 +7,11 @@ import type {CreatorStageRun,CreatorYtDlpStatus} from '@opencreator/protocol';-import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { useEffect } from 'react';import { LanguageProvider } from '../../i18n/LanguageProvider.js';-import { CreatorSessionProvider } from './creator-session-store.js';+import { CreatorSessionProvider, useOptionalCreatorSession } from './creator-session-store.js';import VideoDownloadWorkspace from './VideoDownloadWorkspace.js';import type { RuntimeDependenciesController } from '../../app/use-runtime-dependencies.js';@@ -194,6 +195,81 @@ describe('VideoDownloadWorkspace', () => {})).not.toBeInTheDocument();});+ it.each([+ ['video', videoArtifact(), 'Creator Download.mp4'],+ ['audio', audioArtifact(), 'Creator Download.mp3']+ ])('opens Works when an Agent download completes as %s', async (_type, artifact, fileName) => {+ const initial = job({+ state: { sourceUrl: 'https://www.youtube.com/watch?v=demo' },+ artifacts: [probeArtifact()]+ });+ let applySnapshot: ((next: CreatorJob) => void) | undefined;+ renderWorkspace(initial, {+ applyAction: vi.fn(),+ onSnapshot: callback => { applySnapshot = callback; }+ });++ const worksTab = await screen.findByRole('tab', { name: '作品' });+ expect(worksTab).toHaveAttribute('aria-selected', 'false');+ act(() => applySnapshot?.(job({+ ...initial,+ revision: 1,+ stages: [downloadStage('agent_download', String(artifact.metadata.optionId), 'running', 50)]+ })));+ expect(worksTab).toHaveAttribute('aria-selected', 'false');++ act(() => applySnapshot?.(job({+ ...initial,+ revision: 2,+ artifacts: [probeArtifact(), artifact],+ stages: [downloadStage('agent_download', String(artifact.metadata.optionId), 'succeeded', 100)]+ })));+ expect(worksTab).toHaveAttribute('aria-selected', 'true');+ expect(screen.getByText(fileName)).toBeInTheDocument();++ fireEvent.click(screen.getByRole('tab', { name: '下载规格' }));+ expect(worksTab).toHaveAttribute('aria-selected', 'false');+ });++ it('follows a new Agent link and opens its completed audio in Works', async () => {+ const initial = job({+ state: { sourceUrl: 'https://www.youtube.com/watch?v=demo' },+ artifacts: [probeArtifact()]+ });+ let applySnapshot: ((next: CreatorJob) => void) | undefined;+ renderWorkspace(initial, {+ applyAction: vi.fn(),+ onSnapshot: callback => { applySnapshot = callback; }+ });+ await screen.findByRole('tab', { name: '作品' });++ const nextUrl = 'https://www.youtube.com/watch?v=another';+ const nextProbe = {+ ...probeArtifact(),+ id: 'next_probe',+ metadata: {+ ...probeArtifact().metadata,+ requestedUrl: nextUrl,+ url: nextUrl+ }+ };+ const nextAudio = {+ ...audioArtifact(),+ id: 'next_audio',+ sourceArtifactIds: [nextProbe.id],+ metadata: { ...audioArtifact().metadata, requestedUrl: nextUrl }+ };+ act(() => applySnapshot?.(job({+ ...initial,+ revision: 1,+ state: { sourceUrl: nextUrl },+ artifacts: [probeArtifact(), nextProbe, nextAudio]+ })));++ expect(screen.getByRole('tab', { name: '作品' })).toHaveAttribute('aria-selected', 'true');+ expect(screen.getByText('Creator Download.mp3')).toBeInTheDocument();+ });+it('selects the real audio track when the video language changes', async () => {const current = job({state: {@@ -742,6 +818,7 @@ function renderWorkspace(openArtifact?: ReturnType<typeof vi.fn>;runtimeDependencies?: Partial<RuntimeDependenciesController>;onOpenRuntimeComponents?: () => void;+ onSnapshot?: (callback: (next: CreatorJob) => void) => void;}) {const runtimeDependencies = input.runtimeDependencies === undefined@@ -762,6 +839,9 @@ function renderWorkspace(runAgentTurn: vi.fn()} as never}>+ {input.onSnapshot === undefined ? null : (+ <SnapshotObserver onSnapshot={input.onSnapshot} />+ )}<VideoDownloadWorkspaceonBack={vi.fn()}runtimeDependencies={runtimeDependencies}@@ -772,6 +852,16 @@ function renderWorkspace();}+function SnapshotObserver(props: {+ onSnapshot(callback: (next: CreatorJob) => void): void;+}) {+ const session = useOptionalCreatorSession();+ useEffect(() => {+ if (session !== null) props.onSnapshot(session.applyRemoteSnapshot);+ }, [props.onSnapshot, session?.applyRemoteSnapshot]);+ return null;+}+function ytDlpStatus(patch: Partial<CreatorYtDlpStatus> = {}): CreatorYtDlpStatus {diff --git a/apps/web/src/features/dashboard/VideoDownloadWorkspace.tsx b/apps/web/src/features/dashboard/VideoDownloadWorkspace.tsxindex b48f1505..c39e6183 100644--- a/apps/web/src/features/dashboard/VideoDownloadWorkspace.tsx+++ b/apps/web/src/features/dashboard/VideoDownloadWorkspace.tsx@@ -116,6 +116,9 @@ export default function VideoDownloadWorkspace(props: {.sort(compareArtifactFreshness),[session?.job.artifacts]);+ const seenDownloadArtifactIdsRef = useRef(+ new Set(downloadArtifacts.map(artifact => artifact.id))+ );const downloadedOptionIds = useMemo(() => downloadedOptionsForProbe(downloadArtifacts,@@ -195,7 +198,7 @@ export default function VideoDownloadWorkspace(props: {useEffect(() => {const sourceUrl = readString(session?.state.sourceUrl);- if (sourceUrl !== undefined && sourceUrl !== url && !url.trim()) {+ if (sourceUrl !== undefined && sourceUrl !== url) {setUrl(sourceUrl);}}, [session?.state.sourceUrl, url]);@@ -206,6 +209,20 @@ export default function VideoDownloadWorkspace(props: {setResultTab('formats');}, [probeArtifact?.id]);+ useEffect(() => {+ if (probe === undefined || probeArtifact === undefined) return;+ const newArtifacts = downloadArtifacts.filter(artifact => (+ !seenDownloadArtifactIdsRef.current.has(artifact.id)+ && artifactMatchesProbe(artifact, probeArtifact, probe)+ ));+ if (newArtifacts.length === 0) return;+ for (const artifact of newArtifacts) {+ seenDownloadArtifactIdsRef.current.add(artifact.id);+ }+ setCurrentStep(1);+ setResultTab('outputs');+ }, [downloadArtifacts, probe, probeArtifact]);+useEffect(() => {if (probe === undefined) return;if (selectedOption !== undefined) return;