]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-format-utils.ts
parseQueryStringFilter cleanup
[github/Chocobozzz/PeerTube.git] / server / models / video / video-format-utils.ts
index 55b0ed062576450de0cd08c4c44a767622607fed..d71a3a5dbee34b3e5a1c8719e646b3f3b3827bf0 100644 (file)
@@ -8,7 +8,7 @@ import {
   getVideoDislikesActivityPubUrl,
   getVideoLikesActivityPubUrl,
   getVideoSharesActivityPubUrl
-} from '../../lib/activitypub'
+} from '../../lib/activitypub/url'
 import { isArray } from '../../helpers/custom-validators/misc'
 import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model'
 import {
@@ -23,6 +23,7 @@ import {
 import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
 import { VideoFile } from '@shared/models/videos/video-file.model'
 import { generateMagnetUri } from '@server/helpers/webtorrent'
+import { extractVideo } from '@server/helpers/video'
 
 export type VideoFormattingJSONOptions = {
   completeDescription?: boolean
@@ -180,6 +181,8 @@ function videoFilesModelToFormattedJSON (
   baseUrlWs: string,
   videoFiles: MVideoFileRedundanciesOpt[]
 ): VideoFile[] {
+  const video = extractVideo(model)
+
   return videoFiles
     .map(videoFile => {
       return {
@@ -193,7 +196,8 @@ function videoFilesModelToFormattedJSON (
         torrentUrl: model.getTorrentUrl(videoFile, baseUrlHttp),
         torrentDownloadUrl: model.getTorrentDownloadUrl(videoFile, baseUrlHttp),
         fileUrl: model.getVideoFileUrl(videoFile, baseUrlHttp),
-        fileDownloadUrl: model.getVideoFileDownloadUrl(videoFile, baseUrlHttp)
+        fileDownloadUrl: model.getVideoFileDownloadUrl(videoFile, baseUrlHttp),
+        metadataUrl: video.getVideoFileMetadataUrl(videoFile, baseUrlHttp)
       } as VideoFile
     })
     .sort((a, b) => {
@@ -220,6 +224,15 @@ function addVideoFilesInAPAcc (
       fps: file.fps
     })
 
+    acc.push({
+      type: 'Link',
+      rel: [ 'metadata', MIMETYPES.VIDEO.EXT_MIMETYPE[file.extname] ],
+      mediaType: 'application/json' as 'application/json',
+      href: extractVideo(model).getVideoFileMetadataUrl(file, baseUrlHttp),
+      height: file.resolution,
+      fps: file.fps
+    })
+
     acc.push({
       type: 'Link',
       mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
@@ -269,7 +282,15 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     }
   }
 
-  const url: ActivityUrlObject[] = []
+  const url: ActivityUrlObject[] = [
+    // HTML url should be the first element in the array so Mastodon correctly displays the embed
+    {
+      type: 'Link',
+      mediaType: 'text/html',
+      href: WEBSERVER.URL + '/videos/watch/' + video.uuid
+    }
+  ]
+
   addVideoFilesInAPAcc(url, video, baseUrlHttp, baseUrlWs, video.VideoFiles || [])
 
   for (const playlist of (video.VideoStreamingPlaylists || [])) {
@@ -293,13 +314,6 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     })
   }
 
-  // Add video url too
-  url.push({
-    type: 'Link',
-    mediaType: 'text/html',
-    href: WEBSERVER.URL + '/videos/watch/' + video.uuid
-  })
-
   const subtitleLanguage = []
   for (const caption of video.VideoCaptions) {
     subtitleLanguage.push({
@@ -309,7 +323,10 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     })
   }
 
-  const icons = [ video.getMiniature(), video.getPreview() ]
+  // FIXME: remove and uncomment in PT 2.3
+  // Breaks compatibility with PT <= 2.1
+  // const icons = [ video.getMiniature(), video.getPreview() ]
+  const miniature = video.getMiniature()
 
   return {
     type: 'Video' as 'Video',
@@ -334,13 +351,20 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
     content: video.getTruncatedDescription(),
     support: video.support,
     subtitleLanguage,
-    icon: icons.map(i => ({
+    icon: {
       type: 'Image',
-      url: i.getFileUrl(video),
+      url: miniature.getFileUrl(video),
       mediaType: 'image/jpeg',
-      width: i.width,
-      height: i.height
-    })),
+      width: miniature.width,
+      height: miniature.height
+    } as any,
+    // icon: icons.map(i => ({
+    //   type: 'Image',
+    //   url: i.getFileUrl(video),
+    //   mediaType: 'image/jpeg',
+    //   width: i.width,
+    //   height: i.height
+    // })),
     url,
     likes: getVideoLikesActivityPubUrl(video),
     dislikes: getVideoDislikesActivityPubUrl(video),