+
+ const json = buildOEmbed({
+ channel: video.VideoChannel,
+ title: video.name,
+ embedPath: video.getEmbedStaticPath() + buildPlayerURLQuery(req.query.url),
+ previewPath: video.getPreviewStaticPath(),
+ previewSize: PREVIEWS_SIZE,
+ req
+ })
+
+ return res.json(json)
+}
+
+function buildPlayerURLQuery (inputQueryUrl: string) {
+ const allowedParameters = new Set([
+ 'start',
+ 'stop',
+ 'loop',
+ 'autoplay',
+ 'muted',
+ 'controls',
+ 'controlBar',
+ 'title',
+ 'api',
+ 'warningTitle',
+ 'peertubeLink',
+ 'p2p',
+ 'subtitle',
+ 'bigPlayBackgroundColor',
+ 'mode',
+ 'foregroundColor'
+ ])
+
+ const params = new URLSearchParams()
+
+ new URL(inputQueryUrl).searchParams.forEach((v, k) => {
+ if (allowedParameters.has(k)) {
+ params.append(k, v)
+ }
+ })
+
+ const stringQuery = params.toString()
+ if (!stringQuery) return ''
+
+ return '?' + stringQuery
+}
+
+function buildOEmbed (options: {
+ req: express.Request
+ title: string
+ channel: MChannelSummary
+ previewPath: string | null
+ embedPath: string
+ previewSize: {
+ height: number
+ width: number
+ }
+}) {
+ const { req, previewSize, previewPath, title, channel, embedPath } = options
+