diff --git a/README.md b/README.md index 5851a311..95a0eb0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

Popost

-

Reverse-engineer any viral social video or image post

+

Remake any viral social video or image post

The world’s first project that remakes both videos and image posts, built to recreate viral social content.

@@ -39,7 +39,7 @@ -

Reverse-engineer any viral social content.
Videos and image posts. Paste a link to remake million-view formats in one click.

+

Remake any viral social content.
Videos and image posts. Paste a link to remake million-view formats in one click.

Install Popost and try a remake · ⭐ Star this Skill for your next project

@@ -104,7 +104,7 @@ See the [Skill instructions](./skills/popost/SKILL.md) or use the [web app](http [Creative ads](#case-18) · [Product promos](#case-22) · [Motion design](#case-14) · [AI presenters](#case-17) · [Animation](#case-24) · [Explainers](#case-04) -These six video remake examples each include the reference, the Popost remake, and an adaptation brief. Animated images show opening excerpts; click to watch the full videos. +These six video remake examples each include the reference, the Popost remake, and an adaptation brief. Click an animated preview to watch the full video. Open the video editor to play and edit a copy of the project in your browser tab. @@ -120,7 +120,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Replace CeraVe with Colgate and the sandworm keeper with a dragon dentist. He complains that one tooth takes forever to brush—then a dragon opens its mouth. Spoken in English. -[Source and creator](https://x.com/DiscussingFilm/status/2122428691758108871) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-18-reference-4c8cf384f770.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-18-remake-296c77c3cde1.mp4) +[Source and creator](https://x.com/DiscussingFilm/status/2122428691758108871) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-18-reference-4c8cf384f770.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-18-remake-296c77c3cde1.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-18/en.html) @@ -136,7 +136,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Replace Grok Bot with Popost. Three coworkers send Instagram, TikTok, and X links, and their AI agent remakes the posts for their own content. -[Source and creator](https://x.com/bot/status/2120582957782200586) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-22-reference-faa72c145d4b.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-22-remake-b4339f308ab5.mp4) +[Source and creator](https://x.com/bot/status/2120582957782200586) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-22-reference-faa72c145d4b.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-22-remake-b4339f308ab5.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-22/en.html) @@ -152,7 +152,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Change the copy to “Just five minutes”: five minutes become five hours, the clock turns into dark circles, and the last line is “I’ll go to bed early tomorrow.” Text in English. -[Source and creator](https://x.com/ChrisGPT/status/2119998815856218494) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-14-reference-8615036ae278.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-14-remake-6271077c7d47.mp4) +[Source and creator](https://x.com/ChrisGPT/status/2119998815856218494) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-14-reference-8615036ae278.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-14-remake-6271077c7d47.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-14/en.html) @@ -168,7 +168,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Replace the woman with an American male fitness coach: “My face. My voice. But the me telling you to get up is still in bed.” -[Source and creator](https://x.com/UchegbuPeaceM/status/2116098525318574097) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-17-reference-a8397cf69426.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-17-remake-f2c703c525bd.mp4) +[Source and creator](https://x.com/UchegbuPeaceM/status/2116098525318574097) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-17-reference-a8397cf69426.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-17-remake-f2c703c525bd.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-17/en.html) @@ -184,7 +184,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Replace the black cat with a corgi who owes a pigeon gang 300 fries. The Venice chase becomes its adventure to repay the debt. Spoken in English. -[Source and creator](https://x.com/Pixar/status/2120924590968860697) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-24-reference-60aecdb07c13.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-24-remake-8f6519ebaa27.mp4) +[Source and creator](https://x.com/Pixar/status/2120924590968860697) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-24-reference-60aecdb07c13.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-24-remake-8f6519ebaa27.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-24/en.html) @@ -200,7 +200,7 @@ These six video remake examples each include the reference, the Popost remake, a > Use Popost to remake this viral video, following its style, structure, and hook. My content: Change the topic to Clipcat: 30,000+ real viral commerce videos, free prompts, and a way to remake an idea for your own product. Narrated in Chinese by a male voice. -[Source and creator](https://www.douyin.com/video/7699110937210522915) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-04-reference-4f0988470589.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-04-remake-0e3551ebe98a.mp4) +[Source and creator](https://www.douyin.com/video/7699110937210522915) · [Full reference](https://static.popost.ai/readme/video-showcase-20261129/case-04-reference-4f0988470589.mp4) · [Full remake](https://static.popost.ai/readme/video-showcase-20261129/case-04-remake-0e3551ebe98a.mp4) · [Open video editor](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-04/en.html) diff --git a/README.zh-CN.md b/README.zh-CN.md index 3983a27d..3dc56fd5 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,6 @@

Popost

-

逆向一切社媒爆款视频和图文

+

复刻一切社媒爆款视频和图文

全球首个同时支持视频和图文类型复刻的项目,真正的爆款社媒复刻

@@ -39,7 +39,7 @@ -

逆向一切社媒爆款
视频、图文都能复刻,粘贴链接,一键做同款百万爆款

+

复刻一切社媒爆款
视频、图文都能复刻,粘贴链接,一键做同款百万爆款

安装 Popost 开始复刻 · ⭐ Star 收藏,下次直接找到这个 Skill

@@ -106,7 +106,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 [品牌创意广告](#case-18) · [产品宣传片](#case-22) · [Motion 动效](#case-14) · [数字人口播](#case-17) · [动漫](#case-24) · [知识讲解](#case-04) -下面是六种视频复刻案例。每组都附参考、复刻成片和一句改编要求。左右动图为开场节选,点击可看完整视频。 +下面是六种视频复刻案例。每组都附参考、复刻成片和一句改编要求。左右动图为开场节选,点击可看完整视频。打开视频编辑器即可播放并修改案例副本,改动只保存在当前浏览器标签页。 @@ -122,7 +122,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把CeraVe换成高露洁,沙虫饲养员换成龙牙医,他一本正经地抱怨一颗牙要刷半天,最后张开的是巨龙的嘴。口播是英文。 -[原帖与作者](https://x.com/DiscussingFilm/status/2122428691758108871) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-18-reference-4c8cf384f770.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-18-remake-296c77c3cde1.mp4) +[原帖与作者](https://x.com/DiscussingFilm/status/2122428691758108871) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-18-reference-4c8cf384f770.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-18-remake-296c77c3cde1.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-18/zh.html) @@ -138,7 +138,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把Grok Bot换成Popost,三个同事分别丢来Instagram、TikTok和X链接,AI Agent把它们做出同款爆款。 -[原帖与作者](https://x.com/bot/status/2120582957782200586) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-22-reference-faa72c145d4b.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-22-remake-b4339f308ab5.mp4) +[原帖与作者](https://x.com/bot/status/2120582957782200586) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-22-reference-faa72c145d4b.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-22-remake-b4339f308ab5.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-22/zh.html) @@ -154,7 +154,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把文案换成“我只看五分钟”:五分钟变成五小时,时钟转成黑眼圈,最后只剩一句“明天一定早睡”。文案是英文。 -[原帖与作者](https://x.com/ChrisGPT/status/2119998815856218494) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-14-reference-8615036ae278.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-14-remake-6271077c7d47.mp4) +[原帖与作者](https://x.com/ChrisGPT/status/2119998815856218494) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-14-reference-8615036ae278.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-14-remake-6271077c7d47.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-14/zh.html) @@ -170,7 +170,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把女生换成美国男生健身教练,让他说“脸是我的,声音也是我的,但今天催你起床的我,还没起床”。 -[原帖与作者](https://x.com/UchegbuPeaceM/status/2116098525318574097) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-17-reference-a8397cf69426.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-17-remake-f2c703c525bd.mp4) +[原帖与作者](https://x.com/UchegbuPeaceM/status/2116098525318574097) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-17-reference-a8397cf69426.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-17-remake-f2c703c525bd.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-17/zh.html) @@ -186,7 +186,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把小黑猫换成一只欠了鸽子黑帮三百根薯条的柯基,威尼斯追逐战变成它的还债大冒险。口播是英文。 -[原帖与作者](https://x.com/Pixar/status/2120924590968860697) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-24-reference-60aecdb07c13.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-24-remake-8f6519ebaa27.mp4) +[原帖与作者](https://x.com/Pixar/status/2120924590968860697) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-24-reference-60aecdb07c13.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-24-remake-8f6519ebaa27.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-24/zh.html) @@ -202,7 +202,7 @@ Popost 本身免费使用。你本地使用的 Agent 和模型服务各有自己 > 用popost复刻做同款爆款,参考原视频的风格、结构、钩子,我的内容是:把主题换成Clipcat:3万多真实爆款带货视频,免费查看和复制提示词,找到灵感后直接复刻自己的带货视频。用中文男声讲解。 -[原帖与作者](https://www.douyin.com/video/7699110937210522915) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-04-reference-4f0988470589.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-04-remake-0e3551ebe98a.mp4) +[原帖与作者](https://www.douyin.com/video/7699110937210522915) · [完整参考视频](https://static.popost.ai/readme/video-showcase-20261129/case-04-reference-4f0988470589.mp4) · [完整复刻视频](https://static.popost.ai/readme/video-showcase-20261129/case-04-remake-0e3551ebe98a.mp4) · [打开视频编辑器](https://static.popost.ai/readme/video-studio-20261203-067aaf3db1da/case-04/zh.html) diff --git a/scripts/showcase-video/README.md b/scripts/showcase-video/README.md new file mode 100644 index 00000000..a31c16c4 --- /dev/null +++ b/scripts/showcase-video/README.md @@ -0,0 +1,13 @@ +# README video previews + +The public sample uses the same editor shell, timeline compiler, and edit operations as `popost video preview --edit`. The browser loads a published project snapshot into a tab-local draft. Cloud sync, project uploads, and server-side exports are unavailable in this host. + +The build keeps the original timeline and makes lightweight playback versions of the media. Build the static files with Node and FFmpeg after running `npm ci`. + +```sh +node scripts/showcase-video/build.mjs cases.json path/to/new-output-directory +``` + +The input is a JSON array. Each entry has an `id` such as `case-18`, the path to its approved project directory in `project`, the path to its published MP4 in `video`, and `titles` with `en` and `zh` labels. List additional dependencies referenced within the scene HTML and scripts in `sceneAssets`, using project-relative paths. Include applicable licenses with third-party scene scripts. + +Serve the output over HTTPS or localhost. Open `case-18/en.html` or `case-18/zh.html` to test both languages. Before deployment, verify playback and an edit in each case, and open a fresh tab to check that it starts from the published snapshot. Publish the generated folder under a new versioned prefix on the public media host, then update the two README files. diff --git a/scripts/showcase-video/build.mjs b/scripts/showcase-video/build.mjs new file mode 100644 index 00000000..159b582f --- /dev/null +++ b/scripts/showcase-video/build.mjs @@ -0,0 +1,37 @@ +import { build } from 'esbuild'; +import { mkdtemp, readFile, rm } from 'node:fs/promises'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const [manifest, destination] = process.argv.slice(2); +if (!manifest || !destination) throw new Error('Usage: node scripts/showcase-video/build.mjs CASES.json OUTPUT'); +const here = dirname(fileURLToPath(import.meta.url)); +const output = resolve(destination); +const temporary = await mkdtemp(join(here, '../../node_modules/.showcase-video-')); +try { + const prepare = join(temporary, 'prepare.mjs'); + await build({ + entryPoints: [join(here, 'prepare.ts')], outfile: prepare, bundle: true, + platform: 'node', format: 'esm', packages: 'external', + }); + const generator = await import(pathToFileURL(prepare).href); + await generator.prepare(output, JSON.parse(await readFile(manifest, 'utf8'))); +} finally { + await rm(temporary, { recursive: true, force: true }); +} + +const browser = await build({ + entryPoints: [join(here, 'host.ts')], outfile: join(output, 'host.js'), bundle: true, + platform: 'browser', format: 'esm', target: 'es2022', minify: true, metafile: true, + inject: [join(here, 'utf8.ts')], + define: { 'Buffer.byteLength': 'utf8ByteLength' }, + plugins: [{ + name: 'separate-node-utilities', + setup(builder) { + builder.onResolve({ filter: /^node:/ }, ({ path }) => ({ path, external: true, sideEffects: false })); + }, + }], +}); +if (Object.values(browser.metafile.outputs).some((file) => file.imports.some((item) => item.external && item.path !== '../studio.js'))) { + throw new Error('The browser Studio host retained a Node dependency'); +} diff --git a/scripts/showcase-video/host.ts b/scripts/showcase-video/host.ts new file mode 100644 index 00000000..46e40217 --- /dev/null +++ b/scripts/showcase-video/host.ts @@ -0,0 +1,181 @@ +import { compilePage } from '../../skills/popost/src/video/compile/page'; +import type { StudioComment, StudioVersion } from '../../skills/popost/src/video/preview/studio-data'; +import { createSession, type Sample } from './session'; + +const nativeFetch = window.fetch.bind(window); +const folder = new URL('./', location.href); +const project = new URL('project/', folder); +const draftKey = 'popost-showcase:' + folder.pathname; +const lang = document.documentElement.lang === 'zh-CN' ? 'zh' : 'en'; +const json = (body: unknown, status = 200) => + new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } }); +const unavailable = () => json({ ok: false, problems: [{ + level: 'error', at: '(demo)', message: lang === 'zh' ? '浏览器演示暂不支持此操作。' : 'This action is unavailable in the browser demo.', +}] }, 422); + +function readDraft(): unknown { + try { return JSON.parse(sessionStorage.getItem(draftKey) ?? 'null') ?? undefined; } catch { return undefined; } +} + +// The same Studio uses these virtual URLs when it runs behind the local CLI server. +function mapProjectPath(input: string, base: string) { + return input.startsWith('/project/') ? base + input.slice('/project/'.length) : input; +} + +function start(sample: Sample) { + const session = createSession(sample, lang, readDraft(), (source) => { + try { sessionStorage.setItem(draftKey, JSON.stringify(source)); } catch { /* The active draft stays in memory. */ } + }); + if (!session.state().resolved) throw new Error('Invalid showcase project'); + + const versions: (StudioVersion & { source: unknown })[] = []; + const comments: StudioComment[] = []; + const hash = async () => Array.from(new Uint8Array(await crypto.subtle.digest( + 'SHA-256', new TextEncoder().encode(JSON.stringify(session.state().source)), + )), (byte) => byte.toString(16).padStart(2, '0')).join(''); + + async function read(path: string) { + switch (path) { + case '/api/state': return json(session.state()); + case '/api/source': return json(session.state().source); + case '/api/schema': return nativeFetch(new URL('../schema.json', folder)); + case '/api/cloud/status': return json({ mode: 'off', configured: false }); + case '/api/export-options': return json({ premium: false, verified: false }); + case '/api/studio': return json({ + hash: await hash(), slots: session.slots(), comments, + versions: versions.map(({ source: _source, ...version }) => version), lastExport: null, + }); + default: return unavailable(); + } + } + async function edit(path: string, body: Record) { + switch (path) { + case '/api/edit': return json(session.apply(body)); + case '/api/source': return json(session.replace(body.source, body.base)); + case '/api/undo': return json(session.travel(true)); + case '/api/redo': return json(session.travel(false)); + case '/api/studio/version': + versions.unshift({ id: crypto.randomUUID(), created: Date.now(), name: String(body.name).slice(0, 100), source: session.state().source, hash: await hash() }); + break; + case '/api/studio/restore': { + const version = versions.find(({ id }) => id === body.id); + return version ? json(session.replace(version.source)) : unavailable(); + } + case '/api/studio/comment': { + const comment = comments.find(({ id }) => id === body.id); + if (comment && typeof body.resolved === 'boolean') comment.resolved = body.resolved; + else if (typeof body.text === 'string' && body.text.trim() && typeof body.frame === 'number' && Number.isInteger(body.frame)) { + comments.push({ id: crypto.randomUUID(), frame: body.frame, text: body.text.trim().slice(0, 4000), created: Date.now(), resolved: false }); + } else return unavailable(); + break; + } + default: return unavailable(); + } + return json({ ok: true, state: session.state() }); + } + + function audioPath(input: string) { + if (!input.startsWith('/project/')) return input; + const file = decodeURIComponent(input.slice('/project/'.length)); + const audio = sample.audioFiles[file]; + return audio ? '/project/' + audio : input; + } + + window.fetch = async (input, init) => { + const request = input instanceof Request ? input : new Request(input, init); + const method = (init?.method ?? request.method).toUpperCase(); + const url = new URL(request.url); + if (url.origin !== location.origin) return unavailable(); + if (url.pathname.startsWith('/api/')) { + if (method === 'GET') return read(url.pathname); + if (method === 'POST') { + try { + const body = request.body ? await request.json() as Record : {}; + return await edit(url.pathname, body ?? {}); + } catch { return unavailable(); } + } + return unavailable(); + } + if (method !== 'GET') return unavailable(); + return nativeFetch(mapProjectPath(audioPath(url.pathname), project.href) + url.search, { credentials: 'omit' }); + }; + // The event channel remains in the tab. Edits return the complete new state. + window.EventSource = class extends EventTarget { close() {} } as unknown as typeof EventSource; + + function shellMedia(input: string) { + if (input.startsWith('/api/thumbnail?')) { + const frame = Number(new URL(input, folder).searchParams.get('frame')); + const fps = session.state().resolved!.canvas.fps; + const index = Math.max(0, Math.min(sample.thumbnailCount - 1, Math.floor(frame / fps / 2))); + return new URL('thumbs/' + String(index).padStart(3, '0') + '.webp', folder).href; + } + if (input.startsWith(location.origin + '/project/')) input = input.slice(location.origin.length); + return mapProjectPath(input, project.href); + } + const setAttribute = Element.prototype.setAttribute; + Element.prototype.setAttribute = function (name, value) { + return setAttribute.call(this, name, name === 'src' ? shellMedia(this instanceof HTMLAudioElement ? audioPath(value) : value) : value); + }; + const media = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'src')!; + Object.defineProperty(HTMLMediaElement.prototype, 'src', { + ...media, set(value: string) { media.set!.call(this, shellMedia(this instanceof HTMLAudioElement ? audioPath(value) : value)); }, + }); + + const frame = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'src')!; + const previewUrls = new WeakMap(); + Object.defineProperty(HTMLIFrameElement.prototype, 'src', { + ...frame, + get(this: HTMLIFrameElement) { return previewUrls.get(this) ?? frame.get!.call(this); }, + set(this: HTMLIFrameElement, value: string) { + if (this.id !== 'page' || !value.startsWith('/page?')) { frame.set!.call(this, value); return; } + previewUrls.set(this, new URL(value, folder).href); + const current = session.state(); + void compilePage(current.resolved!, { nativeFootage: true }).then((html) => { + if (current.generation !== session.state().generation) return; + const base = project.href; + const mediaBridge = ''; + this.srcdoc = html.replace('', '' + mediaBridge); + }); + }, + }); + + const preference = Storage.prototype.getItem; + Storage.prototype.getItem = function (key) { + return key === 'popost-studio-language' ? lang : preference.call(this, key); + }; + // The shell's language switch reloads the document. Keep the draft in the same tab. + document.addEventListener('click', (event) => { + if (!(event.target instanceof Element) || !event.target.closest('#lang-toggle')) return; + event.stopImmediatePropagation(); + location.replace(new URL(lang === 'zh' ? 'en.html' : 'zh.html', folder)); + }, true); + document.addEventListener('studio:page-ready', () => { + const footer = document.querySelector('.studio-footer'); + if (footer) { + const label = document.createElement('span'); + label.textContent = lang === 'zh' ? '改动仅保存在当前标签页' : 'Edits stay in this tab'; + footer.replaceChildren('Popost Video Studio', label); + } + }, { once: true }); +} + +// The preview iframe has a separate realm. Native Studio footage uses root-relative URLs there. +function installStageMedia(base: string) { + const media = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'src')!; + Object.defineProperty(HTMLMediaElement.prototype, 'src', { + ...media, + set(value: string) { media.set!.call(this, value.startsWith('/project/') ? base + value.slice('/project/'.length) : value); }, + }); +} + +try { + const response = await nativeFetch(new URL('sample.json', folder), { credentials: 'omit' }); + if (!response.ok) throw new Error('Unable to load sample'); + start(await response.json() as Sample); + const script = document.createElement('script'); + script.src = new URL('../studio.js', folder).href; + document.body.append(script); +} catch { + const app = document.querySelector('#app'); + if (app) app.textContent = lang === 'zh' ? '案例加载失败,请刷新页面重试。' : 'Could not load this case. Refresh to try again.'; +} diff --git a/scripts/showcase-video/prepare.ts b/scripts/showcase-video/prepare.ts new file mode 100644 index 00000000..7cc58258 --- /dev/null +++ b/scripts/showcase-video/prepare.ts @@ -0,0 +1,112 @@ +import { execFileSync } from 'node:child_process'; +import { copyFile, mkdir, readFile, readdir, realpath, writeFile } from 'node:fs/promises'; +import { dirname, join, relative, resolve as pathResolve } from 'node:path'; +import { createNodeRuntime } from '../../skills/popost/src/node-runtime'; +import { loadWords } from '../../skills/popost/src/video/compile/words'; +import { probeFootage } from '../../skills/popost/src/video/compile/footage'; +import { checkProject, readProjectFiles } from '../../skills/popost/src/video/project/check'; +import { parseProject } from '../../skills/popost/src/video/project/schema'; +import { editSchemas } from '../../skills/popost/src/video/preview/edit/routes'; +import { shellHtml } from '../../skills/popost/src/video/preview/html'; +import { resolve } from '../../skills/popost/src/video/timeline/resolve'; + +interface ShowcaseCase { + id: string; + project: string; + video: string; + titles: { en: string; zh: string }; + sceneAssets?: string[]; +} + +const writeJson = (file: string, value: unknown) => writeFile(file, JSON.stringify(value) + '\n'); +const ffmpeg = (args: string[]) => execFileSync('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-nostdin', '-y', ...args]); + +export const prepare = async (output: string, cases: ShowcaseCase[]) => { + const rt = createNodeRuntime('codex'); + await mkdir(output, { recursive: true }); + const shell = shellHtml(true); + const inline = shell.indexOf(''); + if (inline < 0 || shellEnd < inline) throw new Error('Studio shell script is missing'); + const csp = "default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; media-src 'self' blob:; font-src 'self' data:; connect-src 'self'; frame-src 'self'; base-uri 'self'; form-action 'none'"; + const demoStyle = '#studio-export-open,#studio-compare,.studio-side-body:has(input[type=file]) > .primary,.studio-side-body > input[type=file] + .studio-note{display:none!important}'; + const html = (locale: string) => shell.slice(0, inline) + .replace('', '') + .replace('lang="en"', 'lang="' + locale + '"') + + '' + shell.slice(shellEnd + ''.length); + await writeFile(join(output, 'studio.js'), shell.slice(inline + '