ActivityPub-federated video streaming platform using P2P directly in your web browser
Improve SEO
Chocobozzz006bbf2b52f8
diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.html b/client/src/app/shared/shared-video-miniature/videos-list.component.htmlindex 85a38dd56b..92f0f49e18 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.html+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.html@@ -77,5 +77,9 @@</my-video-miniature></div>}++ @if (videos.length !== 0 && hasMoreResults()) {+ <my-button theme="secondary" ptRouterLink="." [ptQueryParams]="getNextPageQueryParams()" i18n>Load more</my-button>+ }</div></div>diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.ts b/client/src/app/shared/shared-video-miniature/videos-list.component.tsindex bea737ee65..451ae2d118 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.ts+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.ts@@ -179,8 +179,9 @@ export class VideosListComponent implements OnInit, OnDestroy {this.filtersChanged.emit(this.filters)})+ this.handlePagination()this.reloadSyndicationItems()- this.reloadVideos()+ this.loadMoreVideos(true)}ngOnDestroy () {@@ -201,13 +202,19 @@ export class VideosListComponent implements OnInit, OnDestroy {}// No more results- if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return+ if (!this.hasMoreResults()) returnthis.pagination.currentPage += 1this.loadMoreVideos()}+ hasMoreResults () {+ if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return false++ return true+ }+loadMoreVideos (reset = false) {let liveFilters: VideoFilterslet videoFilters: VideoFilters@@ -252,6 +259,14 @@ export class VideosListComponent implements OnInit, OnDestroy {this.highlightedLives = this.highlightedLives.filter(v => v.id !== video.id)}+ getNextPageQueryParams () {+ return {+ ...this.route.snapshot.queryParams,++ page: (this.pagination.currentPage + 1) + ''+ }+ }+private calcPageSizes () {if (this.screenService.isInMobileView()) {this.pagination.itemsPerPage = 5@@ -353,4 +368,23 @@ export class VideosListComponent implements OnInit, OnDestroy {}})}++ // Handle "Load more" button for SEO+ private handlePagination () {+ const initPage = this.route.snapshot.queryParams['page']++ this.pagination.currentPage = initPage+ ? +initPage+ : 1++ this.route.queryParams.subscribe(queryParams => {+ const page = queryParams['page']+ if (!page || +page === this.pagination.currentPage) return++ resetCurrentPage(this.pagination)+ this.pagination.currentPage = +page++ this.loadMoreVideos(true)+ })+ }}diff --git a/packages/server-commands/src/requests/requests.ts b/packages/server-commands/src/requests/requests.tsindex e73e7d1e61..85ed8326f9 100644--- a/packages/server-commands/src/requests/requests.ts+++ b/packages/server-commands/src/requests/requests.ts@@ -79,12 +79,12 @@ export function makeGetRequest (options: CommonRequestParams) {return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })}-export function makeHTMLRequest (url: string, path: string) {+export function makeHTMLRequest (url: string, path: string, expectedStatus: HttpStatusCodeType = HttpStatusCode.OK_200) {return makeGetRequest({url,path,accept: 'text/html',- expectedStatus: HttpStatusCode.OK_200+ expectedStatus})}diff --git a/packages/tests/src/client/index.ts b/packages/tests/src/client/index.tsindex 43fbcc2bbc..36dc13a4c3 100644--- a/packages/tests/src/client/index.ts+++ b/packages/tests/src/client/index.ts@@ -1,4 +1,5 @@export * from './embed-html.js'+export * from './head-tags.js'export * from './index-html.js'+export * from './jsonld.js'export * from './oembed.js'-export * from './head-tags.js'diff --git a/packages/tests/src/client/jsonld.ts b/packages/tests/src/client/jsonld.tsnew file mode 100644index 0000000000..4b3d955876--- /dev/null+++ b/packages/tests/src/client/jsonld.ts@@ -0,0 +1,250 @@+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */++import { HttpStatusCode, VideoCreateResult, VideoPlaylistCreateResult, VideoPrivacy } from '@peertube/peertube-models'+import {+ PeerTubeServer,+ cleanupTests,+ createMultipleServers,+ doubleFollow,+ makeHTMLRequest,+ setAccessTokensToServers,+ setDefaultVideoChannel,+ waitJobs+} from '@peertube/peertube-server-commands'+import { getWatchPlaylistBasePaths, getWatchVideoBasePaths } from '@tests/shared/client.js'+import { expect } from 'chai'++async function getJSONLD (server: PeerTubeServer, path: string) {+ let html: string++ try {+ const { text } = await makeHTMLRequest(server.url, path)+ html = text+ } catch (err) {+ const { text } = await makeHTMLRequest(server.url, path, HttpStatusCode.NOT_FOUND_404)+ html = text+ }++ const regexp = new RegExp('<script type="application/ld\\+json">([^<]+?)</script>')+ const matches = html.match(regexp)+ if (!matches) return null++ return JSON.parse(matches[1])+}++describe('Test JSONLD HTML tags', function () {+ let servers: PeerTubeServer[]++ let privateVideo: VideoCreateResult+ let publicVideo: VideoCreateResult++ let privatePlaylist: VideoPlaylistCreateResult+ let publicPlaylist: VideoPlaylistCreateResult++ before(async function () {+ this.timeout(120000)++ servers = await createMultipleServers(2)+ await setAccessTokensToServers(servers)+ await setDefaultVideoChannel(servers)+ await doubleFollow(servers[0], servers[1])++ {+ privateVideo = await servers[0].videos.quickUpload({ name: 'private video', privacy: VideoPrivacy.PRIVATE })+ publicVideo = await servers[0].videos.upload({+ attributes: {+ name: 'simple public video',+ privacy: VideoPrivacy.PUBLIC,+ tags: [],+ language: undefined,+ nsfw: false,+ description: undefined+ }+ })++ await servers[0].videos.rate({ id: publicVideo.id, rating: 'like' })+ await servers[0].views.simulateView({ id: publicVideo.id, xForwardedFor: '0.0.0.1,127.0.0.1' })+ await servers[0].views.simulateView({ id: publicVideo.id, xForwardedFor: '0.0.0.2,127.0.0.1' })+ await servers[0].debug.sendCommand({ body: { command: 'process-video-views-buffer' } })+ }++ {+ privatePlaylist = await servers[0].playlists.create({+ attributes: {+ displayName: 'private playlist',+ privacy: VideoPrivacy.PRIVATE+ }+ })++ publicPlaylist = await servers[0].playlists.create({+ attributes: {+ displayName: 'public playlist',+ privacy: VideoPrivacy.PUBLIC,+ videoChannelId: servers[0].store.channel.id+ }+ })++ await servers[0].playlists.addElement({+ playlistId: publicPlaylist.uuid,+ attributes: {+ videoId: publicVideo.uuid+ }+ })+ }++ await waitJobs(servers)+ })++ describe('Common', function () {+ it('Should not have JSONLD tags on private video/playlist', async function () {+ expect(await getJSONLD(servers[0], getWatchVideoBasePaths()[0] + privateVideo.uuid)).to.be.null+ expect(await getJSONLD(servers[0], getWatchPlaylistBasePaths()[0] + privatePlaylist.uuid)).to.be.null+ })+ })++ describe('Video', function () {+ it('Should have valid JSONLD tags for a simple video', async function () {+ for (const server of servers) {+ const video = await server.videos.get({ id: publicVideo.uuid })+ const jsonld = await getJSONLD(server, getWatchVideoBasePaths()[0] + publicVideo.uuid)++ expect(jsonld).to.deep.equal({+ '@context': 'http://schema.org',+ '@type': 'VideoObject',+ 'name': 'simple public video',+ 'description': '',+ 'image': server.url + video.previewPath,+ 'thumbnailUrl': server.url + video.previewPath,+ 'duration': 'PT' + video.duration + 'S',+ 'url': server.url + '/w/' + publicVideo.shortUUID,+ 'embedUrl': server.url + '/videos/embed/' + publicVideo.shortUUID,++ 'author': {+ '@type': 'Organization',+ 'name': 'Main root channel',+ 'url': server.url === servers[0].url+ ? server.url + '/c/root_channel'+ : server.url + '/c/root_channel@' + servers[0].host+ },++ 'contentRating': 'General Audience',++ 'interactionStatistic': [+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/WatchAction',+ 'userInteractionCount': 2+ },+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/LikeAction',+ 'userInteractionCount': 1+ },+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/DislikeAction',+ 'userInteractionCount': 0+ }+ ],++ 'publisher': {+ '@type': 'Organization',+ 'name': 'PeerTube',+ 'url': server.url+ },++ 'uploadDate': video.createdAt,+ 'datePublished': video.publishedAt,+ 'dateModified': video.updatedAt+ })+ }+ })++ it('Should update the video and have valid JSONLD tags', async function () {+ await servers[0].videos.update({+ id: publicVideo.id,+ attributes: {+ tags: [ 'tag1', 'tag2' ],+ nsfw: true+ }+ })++ await servers[0].captions.add({ language: 'fr', videoId: publicVideo.uuid, fixture: 'subtitle-good1.vtt' })+ await servers[0].captions.add({ language: 'en', videoId: publicVideo.uuid, fixture: 'subtitle-good1.vtt' })++ await waitJobs(servers)++ for (const server of servers) {+ const { data: captions } = await server.captions.list({ videoId: publicVideo.uuid })+ const jsonld = await getJSONLD(server, getWatchVideoBasePaths()[0] + publicVideo.uuid)++ expect(jsonld.contentRating).to.equal('Mature')++ expect(jsonld.caption).to.deep.equal([+ {+ '@type': 'MediaObject',+ 'contentUrl': captions.find(c => c.language.id === 'en').fileUrl,+ 'encodingFormat': 'text/vtt',+ 'inLanguage': 'en',+ 'name': 'English'+ },+ {+ '@type': 'MediaObject',+ 'contentUrl': captions.find(c => c.language.id === 'fr').fileUrl,+ 'encodingFormat': 'text/vtt',+ 'inLanguage': 'fr',+ 'name': 'French'+ }+ ])++ expect(jsonld.keywords).to.deep.equal([+ 'tag1',+ 'tag2'+ ])+ }+ })+ })++ describe('Playlist', function () {+ it('Should have valid JSONLD tags for a simple playlist', async function () {+ for (const server of servers) {+ const jsonld = await getJSONLD(server, getWatchPlaylistBasePaths()[0] + publicPlaylist.uuid)+ const playlist = await server.playlists.get({ playlistId: publicPlaylist.uuid })++ expect(jsonld).to.deep.equal({+ '@context': 'http://schema.org',+ '@type': 'ItemList',+ 'name': 'public playlist',+ 'description': '',+ 'url': server.url + '/w/p/' + publicPlaylist.shortUUID,+ 'numberOfItems': 1,++ 'embedUrl': server.url + playlist.embedPath,+ 'image': server.url + playlist.thumbnailPath,+ 'thumbnailUrl': server.url + playlist.thumbnailPath,++ 'author': {+ '@type': 'Organization',+ 'name': 'Main root channel',+ 'url': server.url === servers[0].url+ ? server.url + '/c/root_channel'+ : server.url + '/c/root_channel@' + servers[0].host+ },++ 'publisher': {+ '@type': 'Organization',+ 'name': 'PeerTube',+ 'url': server.url+ },++ 'uploadDate': playlist.createdAt,+ 'dateModified': playlist.updatedAt+ })+ }+ })+ })++ after(async function () {+ await cleanupTests(servers)+ })+})diff --git a/packages/tests/src/misc-endpoints.ts b/packages/tests/src/misc-endpoints.tsindex 8cba17c627..2a4b02f552 100644--- a/packages/tests/src/misc-endpoints.ts+++ b/packages/tests/src/misc-endpoints.ts@@ -1,9 +1,7 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import { expect } from 'chai'-import { writeJson } from 'fs-extra/esm'-import { join } from 'path'import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'+import { uuidToShort } from '@peertube/peertube-node-utils'import {cleanupTests,createSingleServer,@@ -11,6 +9,9 @@ import {PeerTubeServer,setAccessTokensToServers} from '@peertube/peertube-server-commands'+import { expect } from 'chai'+import { writeJson } from 'fs-extra/esm'+import { join } from 'path'import { expectLogDoesNotContain } from './shared/checks.js'describe('Test misc endpoints', function () {@@ -165,6 +166,8 @@ describe('Test misc endpoints', function () {})describe('Test bots endpoints', function () {+ let uuid1: string+it('Should get the empty sitemap', async function () {const res = await makeGetRequest({url: server.url,@@ -207,12 +210,13 @@ describe('Test misc endpoints', function () {token: user3Token})- const { id: video1Id } = await server.videos.upload({ attributes: { name: 'video 1', nsfw: false }, videoChannelId: channel1Id })+ const video1 = await server.videos.upload({ attributes: { name: 'video 1', nsfw: false }, videoChannelId: channel1Id })+ uuid1 = video1.uuidawait server.videos.upload({ attributes: { name: 'video 2', nsfw: false }, videoChannelId: channel2Id })await server.videos.upload({ attributes: { name: 'video 3', privacy: VideoPrivacy.PRIVATE }, videoChannelId: channel3Id })await server.videos.update({- id: video1Id,+ id: uuid1,attributes: {tags: [ 'fish', 'chips' ]}@@ -268,6 +272,35 @@ describe('Test misc endpoints', function () {expect(res.text).to.contain(`<video:title>${'v'.repeat(97)}...</video:title>`)})++ it('Should use an experimental env variable to update video URLs', async function () {+ const video = await server.videos.get({ id: uuid1 })++ {+ const res = await makeGetRequest({+ url: server.url,+ path: '/sitemap.xml?t=3', // avoid using cache+ expectedStatus: HttpStatusCode.OK_200+ })++ const url = server.url + '/w/' + uuidToShort(video.uuid)+ expect(res.text).to.contain(`<url><loc>${url}</loc><video:video>`)+ }++ await server.kill()+ await server.run({}, { env: { EXPERIMENTAL_SITEMAP_VIDEO_URL: 'true' } })++ {+ const res = await makeGetRequest({+ url: server.url,+ path: '/sitemap.xml?t=4', // avoid using cache+ expectedStatus: HttpStatusCode.OK_200+ })++ const url = server.url + '/videos/watch/' + video.uuid+ expect(res.text).to.contain(`<url><loc>${url}</loc><video:video>`)+ }+ })})after(async function () {diff --git a/server/core/controllers/sitemap.ts b/server/core/controllers/sitemap.tsindex 4de98c169f..ead4d2f39a 100644--- a/server/core/controllers/sitemap.ts+++ b/server/core/controllers/sitemap.ts@@ -102,7 +102,9 @@ async function getSitemapLocalVideoUrls () {v.getMaxQualityFile(VideoFileStream.AUDIO)?.getFileUrl(v)return {- url: WEBSERVER.URL + v.getWatchStaticPath(),+ url: process.env.EXPERIMENTAL_SITEMAP_VIDEO_URL === 'true'+ ? WEBSERVER.URL + '/videos/watch/' + v.uuid+ : WEBSERVER.URL + v.getWatchStaticPath(),video: [{// Sitemap title should be < 100 charactersdiff --git a/server/core/lib/html/shared/playlist-html.ts b/server/core/lib/html/shared/playlist-html.tsindex f633c97fc6..564d92924c 100644--- a/server/core/lib/html/shared/playlist-html.ts+++ b/server/core/lib/html/shared/playlist-html.ts@@ -35,7 +35,6 @@ export class PlaylistHtml {req,html,playlist: videoPlaylist,- addEmbedInfo: true,addOG: true,addTwitterCard: true,isEmbed: false,@@ -61,7 +60,6 @@ export class PlaylistHtml {html,playlist,- addEmbedInfo: true,addOG: false,addTwitterCard: false,isEmbed: true,@@ -83,33 +81,17 @@ export class PlaylistHtml {addOG: booleanaddTwitterCard: boolean- addEmbedInfo: booleanisEmbed: booleancurrentQuery: Record<string, string>}) {- const { req, html, playlist, addEmbedInfo, addOG, addTwitterCard, isEmbed, currentQuery = {} } = options+ const { req, html, playlist, addOG, addTwitterCard, isEmbed, currentQuery = {} } = optionsconst escapedTruncatedDescription = TagsHtml.buildEscapedTruncatedDescription(playlist.description)let htmlResult = TagsHtml.addTitleTag(html, playlist.name)htmlResult = TagsHtml.addDescriptionTag(htmlResult, escapedTruncatedDescription)- const list = { numberOfItems: playlist.get('videosLength') as number }- const schemaType = 'ItemList'-- const twitterCard = addTwitterCard- ? 'player'- : undefined-- const ogType = addOG- ? 'video' as 'video'- : undefined-- const embed = addEmbedInfo- ? { url: WEBSERVER.URL + playlist.getEmbedStaticPath(), createdAt: playlist.createdAt.toISOString() }- : undefined-return TagsHtml.addTags(htmlResult, {url: WEBSERVER.URL + playlist.getWatchStaticPath(),@@ -127,14 +109,31 @@ export class PlaylistHtml {? { url: playlist.getThumbnailUrl(), width: playlist.Thumbnail.width, height: playlist.Thumbnail.height }: undefined,- list,+ list: { numberOfItems: playlist.get('videosLength') as number },- schemaType,- ogType,- twitterCard,+ schemaType: 'ItemList',++ ogType: addOG+ ? 'video' as 'video'+ : undefined,++ twitterCard: addTwitterCard+ ? 'player'+ : undefined,- embed,- oembedUrl: this.getOEmbedUrl(playlist, currentQuery),+ videoOrPlaylist: {+ embedUrl: WEBSERVER.URL + playlist.getEmbedStaticPath(),+ oembedUrl: this.getOEmbedUrl(playlist, currentQuery),+ createdAt: playlist.createdAt.toISOString(),+ updatedAt: playlist.updatedAt.toISOString(),++ channel: playlist.VideoChannel+ ? {+ displayName: playlist.VideoChannel.name,+ url: playlist.VideoChannel.getClientUrl(false)+ }+ : undefined+ },rssFeeds: req? getDefaultRSSFeeds(req)diff --git a/server/core/lib/html/shared/tags-html.ts b/server/core/lib/html/shared/tags-html.tsindex 53c239665f..19e6d8c80c 100644--- a/server/core/lib/html/shared/tags-html.ts+++ b/server/core/lib/html/shared/tags-html.ts@@ -1,5 +1,6 @@import { escapeAttribute, escapeHTML } from '@peertube/peertube-core-utils'import { mdToPlainText } from '@server/helpers/markdown.js'+import { getActivityStreamDuration } from '@server/lib/activitypub/activity.js'import { ServerConfigManager } from '@server/lib/server-config-manager.js'import { getServerActor } from '@server/models/application/application.js'import truncate from 'lodash-es/truncate.js'@@ -9,6 +10,51 @@ import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, WEBSERVER } from '../../../initiaimport { MVideo, MVideoPlaylist } from '../../../types/models/index.js'import { Hooks } from '../../plugins/hooks.js'+type JsonldSchema = {+ '@context': 'http://schema.org'+ '@type': string++ name: string+ description: string+ image: string+ url: string++ embedUrl?: string+ uploadDate?: string++ thumbnailUrl?: string+ numberOfItems?: number+ duration?: string+ inLanguage?: string++ interactionStatistic?: {+ '@type': 'InteractionCounter'+ interactionType: string+ userInteractionCount: number+ }[]++ keywords?: string[]++ author?: {+ '@type': 'Organization'+ name: string+ url: string+ }++ contentRating?: 'Mature' | 'General Audience'++ datePublished?: string+ dateModified?: string++ caption?: {+ '@type': 'MediaObject'+ 'contentUrl': string+ 'encodingFormat': string+ 'inLanguage': string+ 'name': string+ }[]+}+export type TagsOptions = {forbidIndexation: booleanembedIndexation: boolean@@ -41,14 +87,37 @@ export type TagsOptions = {height: number}- embed?: {- url: string+ videoOrPlaylist?: {+ embedUrl: string+ oembedUrl: string+ updatedAt: stringcreatedAt: string- duration?: string- views?: number++ channel?: {+ displayName: string+ url: string+ }}- oembedUrl?: string+ video?: {+ duration: number+ language: string+ tags: string[]++ views: number+ likes: number+ dislikes: number++ nsfw: boolean+ publishedAt: string++ captions: {+ label: string+ mediaType: string+ language: string+ url: string+ }[]+ }rssFeeds?: {title: string@@ -89,7 +158,7 @@ export class TagsHtml {// ---------------------------------------------------------------------------static async addTags (htmlStringPage: string, tagsValues: TagsOptions, context: HookContext) {- const { url, escapedTitle, oembedUrl, forbidIndexation, embedIndexation, relMe, rssFeeds } = tagsValues+ const { url, escapedTitle, videoOrPlaylist, forbidIndexation, embedIndexation, relMe, rssFeeds } = tagsValuesconst serverActor = await getServerActor()let tagsStr = ''@@ -109,8 +178,8 @@ export class TagsHtml {}// OEmbed- if (oembedUrl) {- const href = WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(oembedUrl)+ if (videoOrPlaylist?.oembedUrl) {+ const href = WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoOrPlaylist.oembedUrl)tagsStr += `<link rel="alternate" type="application/json+oembed" href="${href}" title="${escapeAttribute(escapedTitle)}" />`}@@ -178,9 +247,9 @@ export class TagsHtml {metaTags['og:url'] = tags.urlmetaTags['og:description'] = tags.escapedTruncatedDescription- if (tags.embed) {- metaTags['og:video:url'] = tags.embed.url- metaTags['og:video:secure_url'] = tags.embed.url+ if (tags.videoOrPlaylist) {+ metaTags['og:video:url'] = tags.videoOrPlaylist.embedUrl+ metaTags['og:video:secure_url'] = tags.videoOrPlaylist.embedUrlmetaTags['og:video:type'] = 'text/html'metaTags['og:video:width'] = EMBED_SIZE.widthmetaTags['og:video:height'] = EMBED_SIZE.height@@ -216,8 +285,8 @@ export class TagsHtml {metaTags['twitter:image:height'] = tags.image.height}- if (tags.twitterCard === 'player') {- metaTags['twitter:player'] = tags.embed.url+ if (tags.twitterCard === 'player' && tags.videoOrPlaylist) {+ metaTags['twitter:player'] = tags.videoOrPlaylist.embedUrlmetaTags['twitter:player:width'] = EMBED_SIZE.widthmetaTags['twitter:player:height'] = EMBED_SIZE.height}@@ -250,7 +319,7 @@ export class TagsHtml {return Hooks.wrapObject(profilePageSchema, 'filter:html.client.json-ld.result', context)}- const schema = {+ const schema: JsonldSchema = {'@context': 'http://schema.org','@type': tags.schemaType,'name': tags.escapedTitle,@@ -264,13 +333,70 @@ export class TagsHtml {schema['thumbnailUrl'] = tags.image?.url}- if (tags.embed) {- schema['embedUrl'] = tags.embed.url- schema['uploadDate'] = tags.embed.createdAt+ if (tags.videoOrPlaylist) {+ const videoOrPlaylist = tags.videoOrPlaylist+ const video = tags.video++ schema['publisher'] = {+ '@type': 'Organization',+ 'name': CONFIG.INSTANCE.NAME,+ 'url': WEBSERVER.URL+ }- if (tags.embed.duration) schema['duration'] = tags.embed.duration+ schema['embedUrl'] = videoOrPlaylist.embedUrl+ schema['uploadDate'] = videoOrPlaylist.createdAtschema['thumbnailUrl'] = tags.image?.url++ schema['dateModified'] = videoOrPlaylist.updatedAt++ if (videoOrPlaylist.channel) {+ schema['author'] = {+ '@type': 'Organization',+ 'name': videoOrPlaylist.channel.displayName,+ 'url': videoOrPlaylist.channel.url+ }+ }++ if (video) {+ schema['datePublished'] = video.publishedAt++ schema['interactionStatistic'] = [+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/WatchAction',+ 'userInteractionCount': video.views+ },+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/LikeAction',+ 'userInteractionCount': video.likes+ },+ {+ '@type': 'InteractionCounter',+ 'interactionType': 'http://schema.org/DislikeAction',+ 'userInteractionCount': video.dislikes+ }+ ]++ if (video.duration) schema['duration'] = getActivityStreamDuration(video.duration)+ if (video.language) schema['inLanguage'] = video.language++ if (video.tags.length !== 0) schema['keywords'] = video.tags++ if (video.captions.length !== 0) {+ schema['caption'] = video.captions.map(c => ({+ '@type': 'MediaObject',+ 'contentUrl': c.url,+ 'encodingFormat': c.mediaType,+ 'inLanguage': c.language,+ 'name': c.label+ }))+ }++ if (video.nsfw) schema['contentRating'] = 'Mature'+ else schema['contentRating'] = 'General Audience'+ }}return Hooks.wrapObject(schema, 'filter:html.client.json-ld.result', context)diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.tsindex de21c7abde..b30cfd4cc7 100644--- a/server/core/lib/html/shared/video-html.ts+++ b/server/core/lib/html/shared/video-html.ts@@ -2,13 +2,13 @@ import { addQueryParams, escapeHTML } from '@peertube/peertube-core-utils'import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'import { Memoize } from '@server/helpers/memoize.js'import { getVideoRSSFeeds } from '@server/lib/rss.js'+import { VideoCaptionModel } from '@server/models/video/video-caption.js'import express from 'express'import validator from 'validator'import { CONFIG } from '../../../initializers/config.js'import { MEMOIZE_TTL, WEBSERVER } from '../../../initializers/constants.js'import { VideoModel } from '../../../models/video/video.js'-import { MVideo, MVideoThumbnail, MVideoThumbnailBlacklist } from '../../../types/models/index.js'-import { getActivityStreamDuration } from '../../activitypub/activity.js'+import { MVideo, MVideoSeo } from '../../../types/models/index.js'import { isVideoInPrivateDirectory } from '../../video-privacy.js'import { buildEmptyEmbedHTML } from './common.js'import { PageHtml } from './page-html.js'@@ -24,7 +24,7 @@ export class VideoHtml {const [ html, video ] = await Promise.all([PageHtml.getIndexHTML(req, res),- VideoModel.loadWithBlacklist(videoId)+ VideoModel.loadForSEO(videoId)])if (video?.privacy === VideoPrivacy.PASSWORD_PROTECTED) {@@ -43,7 +43,6 @@ export class VideoHtml {html,video,currentQuery: req.query,- addEmbedInfo: true,addOG: true,addTwitterCard: true,isEmbed: false@@ -52,8 +51,8 @@ export class VideoHtml {@Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML })static async getEmbedVideoHTML (videoId: string) {- const videoPromise: Promise<MVideoThumbnailBlacklist> = validator.default.isInt(videoId) || validator.default.isUUID(videoId, 4)- ? VideoModel.loadWithBlacklist(videoId)+ const videoPromise: Promise<MVideoSeo> = validator.default.isInt(videoId) || validator.default.isUUID(videoId, 4)+ ? VideoModel.loadForSEO(videoId): Promise.resolve(undefined)const [ html, video ] = await Promise.all([ PageHtml.getEmbedHTML(), videoPromise ])@@ -67,7 +66,6 @@ export class VideoHtml {html,video,- addEmbedInfo: true,addOG: false,addTwitterCard: false,isEmbed: true,@@ -85,41 +83,21 @@ export class VideoHtml {req: express.Requesthtml: string- video: MVideoThumbnail+ video: MVideoSeoaddOG: booleanaddTwitterCard: boolean- addEmbedInfo: booleanisEmbed: booleancurrentQuery: Record<string, string>}) {- const { req, html, video, addEmbedInfo, addOG, addTwitterCard, isEmbed, currentQuery = {} } = options+ const { req, html, video, addOG, addTwitterCard, isEmbed, currentQuery = {} } = optionsconst escapedTruncatedDescription = TagsHtml.buildEscapedTruncatedDescription(video.description)let customHTML = TagsHtml.addTitleTag(html, video.name)customHTML = TagsHtml.addDescriptionTag(customHTML, escapedTruncatedDescription)- const embed = addEmbedInfo- ? {- url: WEBSERVER.URL + video.getEmbedStaticPath(),- createdAt: video.createdAt.toISOString(),- duration: video.duration ? getActivityStreamDuration(video.duration) : undefined,- views: video.views- }- : undefined-- const ogType = addOG- ? 'video' as 'video'- : undefined-- const twitterCard = addTwitterCard- ? 'player'- : undefined-- const schemaType = 'VideoObject'-const preview = video.getPreview()return TagsHtml.addTags(customHTML, {@@ -139,12 +117,45 @@ export class VideoHtml {? { url: WEBSERVER.URL + video.getPreviewStaticPath(), width: preview.width, height: preview.height }: undefined,- embed,- oembedUrl: this.getOEmbedUrl(video, currentQuery),+ videoOrPlaylist: {+ embedUrl: WEBSERVER.URL + video.getEmbedStaticPath(),+ oembedUrl: this.getOEmbedUrl(video, currentQuery),++ channel: {+ displayName: video.VideoChannel.name,+ url: video.VideoChannel.getClientUrl(false)+ },++ createdAt: video.createdAt.toISOString(),+ updatedAt: video.updatedAt.toISOString()+ },++ video: {+ publishedAt: video.publishedAt.toISOString(),+ duration: video.duration,+ views: video.views,+ language: video.language,+ dislikes: video.dislikes,+ likes: video.likes,+ nsfw: video.nsfw,+ tags: video.Tags.map(t => t.name),+ captions: video.VideoCaptions.map(c => ({+ label: VideoCaptionModel.getLanguageLabel(c.language),+ mediaType: 'text/vtt',+ language: c.language,+ url: c.getFileUrl(video)+ }))+ },++ ogType: addOG+ ? 'video' as 'video'+ : undefined,++ twitterCard: addTwitterCard+ ? 'player'+ : undefined,- ogType,- twitterCard,- schemaType,+ schemaType: 'VideoObject',rssFeeds: req? getVideoRSSFeeds(video, req)diff --git a/server/core/models/video/sql/video/shared/abstract-video-query-builder.ts b/server/core/models/video/sql/video/shared/abstract-video-query-builder.tsindex c4a10082ac..d61db21243 100644--- a/server/core/models/video/sql/video/shared/abstract-video-query-builder.ts+++ b/server/core/models/video/sql/video/shared/abstract-video-query-builder.ts@@ -317,6 +317,18 @@ export class AbstractVideoQueryBuilder extends AbstractRunQuery {}}+ protected includeCaptions () {+ this.addJoin(+ 'LEFT JOIN "videoCaption" AS "VideoCaptions" ON "video"."id" = "VideoCaptions"."videoId"'+ )++ this.attributes = {+ ...this.attributes,++ ...this.buildAttributesObject('VideoCaptions', this.tables.getCaptionAttributes())+ }+ }+protected buildActorInclude (prefixKey: string) {return this.buildAttributesObject(prefixKey, this.tables.getActorAttributes())}diff --git a/server/core/models/video/sql/video/shared/video-model-builder.ts b/server/core/models/video/sql/video/shared/video-model-builder.tsindex 1ec9157fa0..fa7db45783 100644--- a/server/core/models/video/sql/video/shared/video-model-builder.ts+++ b/server/core/models/video/sql/video/shared/video-model-builder.ts@@ -10,6 +10,7 @@ import { ServerBlocklistModel } from '@server/models/server/server-blocklist.js'import { ServerModel } from '@server/models/server/server.js'import { TrackerModel } from '@server/models/server/tracker.js'import { UserVideoHistoryModel } from '@server/models/user/user-video-history.js'+import { VideoCaptionModel } from '@server/models/video/video-caption.js'import { VideoLiveScheduleModel } from '@server/models/video/video-live-schedule.js'import { VideoSourceModel } from '@server/models/video/video-source.js'import { ScheduleVideoUpdateModel } from '../../../schedule-video-update.js'@@ -49,6 +50,7 @@ export class VideoModelBuilder {private trackersDone: Set<string>private tagsDone: Set<string>private autoTagsDone: Set<string>+ private captionsDone: Set<any>private videos: VideoModel[]@@ -62,16 +64,17 @@ export class VideoModelBuilder {buildVideosFromRows (options: {rows: SQLRow[]+ addCaptions: booleaninclude?: VideoIncludeTyperowsWebVideoFiles?: SQLRow[]rowsStreamingPlaylist?: SQLRow[]}) {- const { rows, rowsWebVideoFiles, rowsStreamingPlaylist, include } = options+ const { rows, rowsWebVideoFiles, rowsStreamingPlaylist, include, addCaptions } = optionsthis.reinit()for (const row of rows) {- this.buildVideoAndAccount(row)+ this.buildVideoAndAccount(row, { addCaptions })const videoModel = this.videosMemo[row.id as number]@@ -102,6 +105,7 @@ export class VideoModelBuilder {if (this.mode === 'get') {this.addTag(row, videoModel)this.addTracker(row, videoModel)+ this.addCaption(row, videoModel)this.setBlacklisted(row, videoModel)this.setScheduleVideoUpdate(row, videoModel)} else {@@ -159,6 +163,7 @@ export class VideoModelBuilder {this.trackersDone = new Set()this.tagsDone = new Set()this.autoTagsDone = new Set()+ this.captionsDone = new Set()this.videos = []}@@ -190,7 +195,9 @@ export class VideoModelBuilder {}}- private buildVideoAndAccount (row: SQLRow) {+ private buildVideoAndAccount (row: SQLRow, options: {+ addCaptions: boolean+ }) {if (this.videosMemo[row.id]) returnconst videoModel = new VideoModel(this.grab(row, this.tables.getVideoAttributes(), ''), this.buildOpts)@@ -203,6 +210,10 @@ export class VideoModelBuilder {videoModel.VideoAutomaticTags = []videoModel.Trackers = []+ if (options.addCaptions === true) {+ videoModel.VideoCaptions = []+ }+this.buildAccount(row, videoModel)this.videosMemo[row.id] = videoModel@@ -376,6 +387,19 @@ export class VideoModelBuilder {this.trackersDone.add(key)}+ private addCaption (row: SQLRow, videoModel: VideoModel) {+ const id = row['VideoCaptions.id']++ if (!id || this.captionsDone.has(id)) return++ const attributes = this.grab(row, this.tables.getCaptionAttributes(), 'VideoCaptions')+ const captionModel = new VideoCaptionModel(attributes, this.buildOpts)++ videoModel.VideoCaptions.push(captionModel)++ this.captionsDone.add(id)+ }+private setBlacklisted (row: SQLRow, videoModel: VideoModel) {const id = row['VideoBlacklist.id']if (!id || this.blacklistDone.has(id)) returndiff --git a/server/core/models/video/sql/video/shared/video-table-attributes.ts b/server/core/models/video/sql/video/shared/video-table-attributes.tsindex 34a76cc332..cc3c156a08 100644--- a/server/core/models/video/sql/video/shared/video-table-attributes.ts+++ b/server/core/models/video/sql/video/shared/video-table-attributes.ts@@ -215,6 +215,10 @@ export class VideoTableAttributes {return [ 'id', 'fileUrl' ]}+ getCaptionAttributes () {+ return [ 'id', 'language', 'fileUrl', 'storage', 'filename', 'automaticallyGenerated', 'm3u8Filename', 'm3u8Url' ]+ }+getActorAttributes () {let attributeKeys = ['id',diff --git a/server/core/models/video/sql/video/video-model-get-query-builder.ts b/server/core/models/video/sql/video/video-model-get-query-builder.tsindex 01c1c21727..4e8b0e8348 100644--- a/server/core/models/video/sql/video/video-model-get-query-builder.ts+++ b/server/core/models/video/sql/video/video-model-get-query-builder.ts@@ -1,5 +1,5 @@-import { Sequelize, Transaction } from 'sequelize'import { pick } from '@peertube/peertube-core-utils'+import { Sequelize, Transaction } from 'sequelize'import { AbstractVideoQueryBuilder } from './shared/abstract-video-query-builder.js'import { VideoFileQueryBuilder } from './shared/video-file-query-builder.js'import { VideoModelBuilder } from './shared/video-model-builder.js'@@ -19,6 +19,37 @@ export type GetType =| 'thumbnails-blacklist'| 'id'| 'blacklist-rights'+ | 'seo'++const videoFilesInclude = new Set<GetType>([ 'api', 'full', 'account-blacklist-files', 'all-files' ])+const captionsInclude = new Set<GetType>([ 'seo' ])++const trackersInclude = new Set<GetType>([ 'api' ])+const liveInclude = new Set<GetType>([ 'api', 'full' ])+const scheduleUpdateInclude = new Set<GetType>([ 'api', 'full' ])+const tagsInclude = new Set<GetType>([ 'api', 'full', 'seo' ])+const userHistoryInclude = new Set<GetType>([ 'api', 'full' ])+const accountInclude = new Set<GetType>([ 'api', 'full', 'account', 'account-blacklist-files', 'seo' ])+const ownerUserInclude = new Set<GetType>([ 'blacklist-rights' ])++const blacklistedInclude = new Set<GetType>([+ 'api',+ 'full',+ 'account-blacklist-files',+ 'thumbnails-blacklist',+ 'blacklist-rights',+ 'seo'+])++const thumbnailsInclude = new Set<GetType>([+ 'api',+ 'full',+ 'account-blacklist-files',+ 'all-files',+ 'thumbnails',+ 'thumbnails-blacklist',+ 'seo'+])export type BuildVideoGetQueryOptions = {id?: number | string@@ -39,8 +70,6 @@ export class VideoModelGetQueryBuilder {private readonly videoModelBuilder: VideoModelBuilder- private static readonly videoFilesInclude = new Set<GetType>([ 'api', 'full', 'account-blacklist-files', 'all-files' ])-constructor (protected readonly sequelize: Sequelize) {this.videoQueryBuilder = new VideosModelGetQuerySubBuilder(sequelize)this.webVideoFilesQueryBuilder = new VideoFileQueryBuilder(sequelize)@@ -59,17 +88,18 @@ export class VideoModelGetQueryBuilder {const [ videoRows, webVideoFilesRows, streamingPlaylistFilesRows ] = await Promise.all([this.videoQueryBuilder.queryVideos(options),- VideoModelGetQueryBuilder.videoFilesInclude.has(options.type)+ videoFilesInclude.has(options.type)? this.webVideoFilesQueryBuilder.queryWebVideos(fileQueryOptions): Promise.resolve(undefined),- VideoModelGetQueryBuilder.videoFilesInclude.has(options.type)+ videoFilesInclude.has(options.type)? this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(fileQueryOptions): Promise.resolve(undefined)])const videos = this.videoModelBuilder.buildVideosFromRows({rows: videoRows,+ addCaptions: captionsInclude.has(options.type),rowsWebVideoFiles: webVideoFilesRows,rowsStreamingPlaylist: streamingPlaylistFilesRows})@@ -92,31 +122,6 @@ export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder {protected webVideoFilesQuery: stringprotected streamingPlaylistFilesQuery: string- private static readonly trackersInclude = new Set<GetType>([ 'api' ])- private static readonly liveInclude = new Set<GetType>([ 'api', 'full' ])- private static readonly scheduleUpdateInclude = new Set<GetType>([ 'api', 'full' ])- private static readonly tagsInclude = new Set<GetType>([ 'api', 'full' ])- private static readonly userHistoryInclude = new Set<GetType>([ 'api', 'full' ])- private static readonly accountInclude = new Set<GetType>([ 'api', 'full', 'account', 'account-blacklist-files' ])- private static readonly ownerUserInclude = new Set<GetType>([ 'blacklist-rights' ])-- private static readonly blacklistedInclude = new Set<GetType>([- 'api',- 'full',- 'account-blacklist-files',- 'thumbnails-blacklist',- 'blacklist-rights'- ])-- private static readonly thumbnailsInclude = new Set<GetType>([- 'api',- 'full',- 'account-blacklist-files',- 'all-files',- 'thumbnails',- 'thumbnails-blacklist'- ])-constructor (protected readonly sequelize: Sequelize) {super(sequelize, 'get')}@@ -132,51 +137,55 @@ export class VideosModelGetQuerySubBuilder extends AbstractVideoQueryBuilder {'"video".*': ''}- if (VideosModelGetQuerySubBuilder.thumbnailsInclude.has(options.type)) {+ if (thumbnailsInclude.has(options.type)) {this.includeThumbnails()}- if (VideosModelGetQuerySubBuilder.blacklistedInclude.has(options.type)) {+ if (blacklistedInclude.has(options.type)) {this.includeBlacklisted()}- if (VideosModelGetQuerySubBuilder.accountInclude.has(options.type)) {+ if (accountInclude.has(options.type)) {this.includeChannels()this.includeAccounts()}- if (VideosModelGetQuerySubBuilder.tagsInclude.has(options.type)) {+ if (tagsInclude.has(options.type)) {this.includeTags()}- if (VideosModelGetQuerySubBuilder.scheduleUpdateInclude.has(options.type)) {+ if (scheduleUpdateInclude.has(options.type)) {this.includeScheduleUpdate()}- if (VideosModelGetQuerySubBuilder.liveInclude.has(options.type)) {+ if (liveInclude.has(options.type)) {this.includeLive()this.includeLiveSchedules()}- if (options.userId && VideosModelGetQuerySubBuilder.userHistoryInclude.has(options.type)) {+ if (options.userId && userHistoryInclude.has(options.type)) {this.includeUserHistory(options.userId)}- if (VideosModelGetQuerySubBuilder.ownerUserInclude.has(options.type)) {+ if (ownerUserInclude.has(options.type)) {this.includeOwnerUser()}- if (VideosModelGetQuerySubBuilder.trackersInclude.has(options.type)) {+ if (trackersInclude.has(options.type)) {this.includeTrackers()}+ if (captionsInclude.has(options.type)) {+ this.includeCaptions()+ }+this.whereId(options)this.query = this.buildQuery(options)}private buildQuery (options: BuildVideoGetQueryOptions) {- const order = VideosModelGetQuerySubBuilder.tagsInclude.has(options.type)+ const order = tagsInclude.has(options.type)? 'ORDER BY "Tags"."name" ASC': ''diff --git a/server/core/models/video/sql/video/videos-model-list-query-builder.ts b/server/core/models/video/sql/video/videos-model-list-query-builder.tsindex d15a5a4140..b08afc6a6e 100644--- a/server/core/models/video/sql/video/videos-model-list-query-builder.ts+++ b/server/core/models/video/sql/video/videos-model-list-query-builder.ts@@ -53,11 +53,17 @@ export class VideosModelListQueryBuilder extends AbstractVideoQueryBuilder {this.streamingPlaylistFilesQueryBuilder.queryStreamingPlaylistVideos(fileQueryOptions)])- return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include, rowsStreamingPlaylist, rowsWebVideoFiles })+ return this.videoModelBuilder.buildVideosFromRows({+ rows,+ include: options.include,+ addCaptions: false,+ rowsStreamingPlaylist,+ rowsWebVideoFiles+ })}}- return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include })+ return this.videoModelBuilder.buildVideosFromRows({ rows, include: options.include, addCaptions: false })}private buildInnerQuery (options: BuildVideosListQueryOptions) {diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.tsindex 206d75c0c1..42469e0b27 100644--- a/server/core/models/video/video.ts+++ b/server/core/models/video/video.ts@@ -103,6 +103,7 @@ import {MVideoId,MVideoImmutable,MVideoOwned,+ MVideoSeo,MVideoThumbnail,MVideoThumbnailBlacklist,MVideoWithAllFiles,@@ -1345,6 +1346,12 @@ export class VideoModel extends SequelizeModel<VideoModel> {return queryBuilder.queryVideo({ id, transaction, type: 'thumbnails-blacklist' })}+ static loadForSEO (id: number | string, transaction?: Transaction): Promise<MVideoSeo> {+ const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize)++ return queryBuilder.queryVideo({ id, transaction, type: 'seo' })+ }+static loadAndPopulateAccountAndFiles (id: number | string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> {const queryBuilder = new VideoModelGetQueryBuilder(VideoModel.sequelize)diff --git a/server/core/types/models/video/video.ts b/server/core/types/models/video/video.tsindex 13e5a55ec4..41436aad40 100644--- a/server/core/types/models/video/video.ts+++ b/server/core/types/models/video/video.ts@@ -116,6 +116,14 @@ export type MVideoWithStreamingPlaylist =& MVideo& Use<'VideoStreamingPlaylists', MStreamingPlaylistFiles[]>+export type MVideoSeo =+ & MVideo+ & Use<'Thumbnails', MThumbnail[]>+ & Use<'VideoBlacklist', MVideoBlacklistLight>+ & Use<'VideoChannel', MChannelAccountLight>+ & Use<'Tags', MTag[]>+ & Use<'VideoCaptions', MVideoCaptionLanguageUrl[]>+// ############################################################################// Associations with not all their attributes