X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-format-utils.ts;h=9b6509dfd6540b6df68078adcf01cf38b5ea7da4;hb=f95628636b6ccdf3eae2449ca718e075b072f678;hp=55b0ed062576450de0cd08c4c44a767622607fed;hpb=a15871560f80e07386c1dabb8370cd2664ecfd1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index 55b0ed062..9b6509dfd 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -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 { @@ -19,10 +19,11 @@ import { MVideoFile, MVideoFormattable, MVideoFormattableDetails -} from '../../typings/models' -import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' +} from '../../types/models' +import { MVideoFileRedundanciesOpt } from '../../types/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 @@ -174,13 +175,22 @@ function streamingPlaylistsModelToFormattedJSON (video: MVideo, playlists: MStre }) } +function sortByResolutionDesc (fileA: MVideoFile, fileB: MVideoFile) { + if (fileA.resolution < fileB.resolution) return 1 + if (fileA.resolution === fileB.resolution) return 0 + return -1 +} + function videoFilesModelToFormattedJSON ( model: MVideo | MStreamingPlaylistVideo, baseUrlHttp: string, baseUrlWs: string, videoFiles: MVideoFileRedundanciesOpt[] ): VideoFile[] { - return videoFiles + const video = extractVideo(model) + + return [ ...videoFiles ] + .sort(sortByResolutionDesc) .map(videoFile => { return { resolution: { @@ -193,14 +203,10 @@ 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) => { - if (a.resolution.id < b.resolution.id) return 1 - if (a.resolution.id === b.resolution.id) return 0 - return -1 - }) } function addVideoFilesInAPAcc ( @@ -210,7 +216,9 @@ function addVideoFilesInAPAcc ( baseUrlWs: string, files: MVideoFile[] ) { - for (const file of files) { + const sortedFiles = [ ...files ].sort(sortByResolutionDesc) + + for (const file of sortedFiles) { acc.push({ type: 'Link', mediaType: MIMETYPES.VIDEO.EXT_MIMETYPE[file.extname] as any, @@ -220,6 +228,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 +286,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 +318,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({ @@ -331,7 +349,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject { originallyPublishedAt: video.originallyPublishedAt ? video.originallyPublishedAt.toISOString() : null, updated: video.updatedAt.toISOString(), mediaType: 'text/markdown', - content: video.getTruncatedDescription(), + content: video.description, support: video.support, subtitleLanguage, icon: icons.map(i => ({