Search by

liufencn / flarum-mediaembed

LiuFenCN

中文媒体站点嵌入:给 Flarum 的 s9e MediaEmbed 补上国内常用视频 / 音乐站点(B站、AcFun、腾讯视频、网易云音乐、西瓜视频),链接自动转为内嵌播放器

Package info

github.com/LiuFenCN/flarum-ext-mediaembed

Type:flarum-extension

pkg:composer/liufencn/flarum-mediaembed

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-15 17:24 UTC

This package is auto-updated.

Last update: 2026-10-18 02:18:43 UTC


README

给 Flarum 2.x 的富文本引擎补上国内常用视频 / 音乐站点:帖子里的 B 站、AcFun、腾讯视频、网易云音乐、西瓜视频链接,发帖后自动渲染成内嵌播放器,不再只是普通超链接。 Adds popular Chinese video / music sites to the Flarum 2.x rich-text engine: Bilibili, AcFun, Tencent Video, NetEase Cloud Music and ixigua links in posts automatically render as embedded players instead of plain hyperlinks.

零依赖、零配置——装好启用即用,不改动 Flarum 核心与任何 vendor 文件。

Zero dependencies, zero configuration — install, enable, done. No changes to Flarum core or any vendor file.

播放效果

为什么需要这个扩展 · Why this extension

Flarum 2.x 的富文本由 s9e/TextFormatter 渲染,「链接变播放器」靠它的 MediaEmbed 插件:解析时把裸 URL 包成 MEDIA 标签 → 按 host 查站点表 → 命中就换成 <BILIBILI> / <YOUTUBE> 之类标签再渲染成 iframe。

Flarum 2.x renders rich text with s9e/TextFormatter; "link becomes player" is handled by its MediaEmbed plugin: at parse time a bare URL is wrapped in a MEDIA tag → the site table is looked up by host → a match is rewritten to a <BILIBILI> / <YOUTUBE>-style tag and rendered as an iframe.

s9e 内置站点表有 136 个站点(YouTube / Vimeo / Dailymotion / SoundCloud / Spotify / TikTok / Twitch / 优酷……),国内站一个都没有。fof/formatting 负责装上 MediaEmbed,但只额外注册了 youtube 一个站点。本扩展就是补这一块。

The bundled site table has 136 sites (YouTube / Vimeo / Dailymotion / SoundCloud / Spotify / TikTok / Twitch / Youku…) but not a single Chinese site. fof/formatting installs MediaEmbed but registers only youtube on top. This extension fills that gap.

支持的站点 · Supported sites

站点 Site 链接形态 URL forms 播放器 Player
Bilibili video/BV号、video/av号、?p=N 分P、带 share_source 等尾巴的分享链接、无 www / m. 子域 player.bilibili.com
AcFun acfun.cn/v/ac+ID acfun.cn/player
腾讯视频 Tencent Video x/cover/{cid}/{vid}.html、x/page/{vid}.html、cover/...?vid= 等 6 种形态 v.qq.com/txp/iframe
网易云音乐 NetEase Cloud Music 单曲 / 专辑 / 歌单,含 #/ hash 路由与 song/33894312 斜杠式 music.163.com/outchain
西瓜视频 ixigua ixigua.com/{长ID} ixigua.com/iframe

各站点播放器地址均于 2026-10-15 用真实 ID 实测返回真播放器页(B 站另在真实浏览器中取到 206 视频分片)。西瓜视频的 iframe 是纯 JS SPA,无法从服务端端到端验证,播不了可单独删除 extend.php 中对应段落,不影响其他站点。

Every player URL was verified on 2026-10-15 with real IDs to return a genuine player page (Bilibili additionally served 206 video chunks in a real browser). The ixigua iframe is a pure JS SPA that cannot be verified end-to-end server-side; if it fails, delete the corresponding block in extend.php — the other sites are unaffected.

有意不做:b23.tv 短链(302 跳转需发 HTTP 请求,会让发帖渲染依赖外网)、space.bilibili.com 合集、bilibili.com/read/cv 专栏(非视频)。

Deliberately not supported: b23.tv short links (302 redirects would require an HTTP request at render time, making posting depend on external network), space.bilibili.com collections, bilibili.com/read/cv columns (not video).

正确不嵌:news.qq.com 等腾讯非视频页(host 刻意只写 v.qq.com)、evil.com/bilibili.com/... 伪造域名、百度网盘、GitHub。

Correctly not embedded: Tencent non-video pages such as news.qq.com (the host list deliberately contains only v.qq.com), spoofed domains like evil.com/bilibili.com/..., Baidu Netdisk, GitHub.

安装 · Installation

composer require liufencn/flarum-mediaembed
php flarum extension:enable liufencn-mediaembed
php flarum cache:clear

也可以手动部署:把本仓库放到 extensions/liufencn-mediaembed/,再在后台启用。扩展 id 为 liufencn-mediaembed。

Manual deployment works too: place this repository at extensions/liufencn-mediaembed/ and enable it in the admin panel. The extension id is liufencn-mediaembed.

历史数据兼容 · Legacy data compatibility

站内历史数据里存着早年用别的扩展生成的 <BILIBILI bvid="1iM4y1y7oA"> 标签(属性名 bvid、值是裸号无 BV 前缀)。本扩展的属性名与历史数据同名,模板对值做前缀兼容——存量帖无需重解析即可播放。

Existing posts may contain <BILIBILI bvid="1iM4y1y7oA"> tags generated years ago by another extension (attribute bvid, value is a bare ID without the BV prefix). This extension uses the same attribute name and its template tolerates the missing prefix — stored posts play without re-parsing.

注意 s9e 的硬特性:文本在发帖那一刻就解析成 XML 存库,渲染直接用存量 XML。新增站点只影响之后解析的文本;已发帖里的裸链接需要重解析才会变播放器($formatter->unparse($old) → parse($text) → 更新 content 列)。

Note a hard s9e property: text is parsed to XML at post time and stored; rendering reuses the stored XML. New sites only affect text parsed afterwards; bare links in already-posted messages need a re-parse to become players ($formatter->unparse($old) → parse($text) → update the content column).

依赖兜底 · Dependency fallback

正常情况下 MediaEmbed 已被 fof/formatting 装好,直接 add 站点即可。万一 fof/formatting 被停用 / 卸载,extend.php 里的兜底分支会自己把插件 load 进来,保证本扩展独立可用。

Normally fof/formatting has already installed MediaEmbed, so the extension just adds its sites. If fof/formatting is ever disabled or uninstalled, a fallback branch in extend.php loads the plugin itself, keeping this extension usable standalone.

测试 · Tests

verify.php 是 26 用例的离线验证台(重绑内存缓存避开 Formatter 缓存):

verify.php is an offline harness of 26 cases (rebinds the in-memory cache to bypass the Formatter cache):

php verify.php   # 期望 PASS 25 / FAIL 0(另 1 例负例断言"不嵌")
                # expect PASS 25 / FAIL 0 (one negative case asserts "not embedded")

致谢 · Credits

  • Flarum — MIT
  • s9e/TextFormatter — MIT(MediaEmbed 插件与站点定义机制的提供者 · provider of the MediaEmbed plugin and the site-definition mechanism)

License

AGPL-3.0-or-later — 可自由使用、修改、商用;但若你修改后对外提供服务,必须以相同许可开源你的改动。完整条款见 LICENSE。

AGPL-3.0-or-later — free to use, modify and commercialize; however, if you modify it and offer it to others as a service, your changes must be released under the same license. See LICENSE for the full terms.

联系作者 / Contact

渠道 Channel 地址 Address
🏝️ 论坛(CatIsland) https://bbs.cathi.cn
💬 QQ 交流群 369748859
📮 邮箱 792818521@qq.com