aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-format-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-11 14:09:23 +0100
committerChocobozzz <me@florianbigard.com>2019-02-11 14:09:23 +0100
commitb718fd22374d64534bcfe69932cf562894abed6a (patch)
tree311d3c67e2a4d1f33ebdd1dc163527de9d33d0f7 /server/models/video/video-format-utils.ts
parentadb115f5522bea4d52456a9fc5eb4140bb064476 (diff)
parent501e961199578129629cf0567033d13efced9904 (diff)
downloadPeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.gz
PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.tar.zst
PeerTube-b718fd22374d64534bcfe69932cf562894abed6a.zip
Merge branch 'develop' into pr/1285
Diffstat (limited to 'server/models/video/video-format-utils.ts')
-rw-r--r--server/models/video/video-format-utils.ts63
1 files changed, 61 insertions, 2 deletions
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 7a9513cbe..c63285e25 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -1,7 +1,12 @@
1import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 1import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
2import { VideoModel } from './video' 2import { VideoModel } from './video'
3import { VideoFileModel } from './video-file' 3import { VideoFileModel } from './video-file'
4import { ActivityUrlObject, VideoTorrentObject } from '../../../shared/models/activitypub/objects' 4import {
5 ActivityPlaylistInfohashesObject,
6 ActivityPlaylistSegmentHashesObject,
7 ActivityUrlObject,
8 VideoTorrentObject
9} from '../../../shared/models/activitypub/objects'
5import { CONFIG, MIMETYPES, THUMBNAILS_SIZE } from '../../initializers' 10import { CONFIG, MIMETYPES, THUMBNAILS_SIZE } from '../../initializers'
6import { VideoCaptionModel } from './video-caption' 11import { VideoCaptionModel } from './video-caption'
7import { 12import {
@@ -11,6 +16,8 @@ import {
11 getVideoSharesActivityPubUrl 16 getVideoSharesActivityPubUrl
12} from '../../lib/activitypub' 17} from '../../lib/activitypub'
13import { isArray } from '../../helpers/custom-validators/misc' 18import { isArray } from '../../helpers/custom-validators/misc'
19import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model'
20import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
14 21
15export type VideoFormattingJSONOptions = { 22export type VideoFormattingJSONOptions = {
16 completeDescription?: boolean 23 completeDescription?: boolean
@@ -121,7 +128,12 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails {
121 } 128 }
122 }) 129 })
123 130
131 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
132
124 const tags = video.Tags ? video.Tags.map(t => t.name) : [] 133 const tags = video.Tags ? video.Tags.map(t => t.name) : []
134
135 const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists)
136
125 const detailsJson = { 137 const detailsJson = {
126 support: video.support, 138 support: video.support,
127 descriptionPath: video.getDescriptionAPIPath(), 139 descriptionPath: video.getDescriptionAPIPath(),
@@ -129,12 +141,17 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails {
129 account: video.VideoChannel.Account.toFormattedJSON(), 141 account: video.VideoChannel.Account.toFormattedJSON(),
130 tags, 142 tags,
131 commentsEnabled: video.commentsEnabled, 143 commentsEnabled: video.commentsEnabled,
144 downloadEnabled: video.downloadEnabled,
132 waitTranscoding: video.waitTranscoding, 145 waitTranscoding: video.waitTranscoding,
133 state: { 146 state: {
134 id: video.state, 147 id: video.state,
135 label: VideoModel.getStateLabel(video.state) 148 label: VideoModel.getStateLabel(video.state)
136 }, 149 },
137 files: [] 150
151 trackerUrls: video.getTrackerUrls(baseUrlHttp, baseUrlWs),
152
153 files: [],
154 streamingPlaylists
138 } 155 }
139 156
140 // Format and sort video files 157 // Format and sort video files
@@ -143,6 +160,25 @@ function videoModelToFormattedDetailsJSON (video: VideoModel): VideoDetails {
143 return Object.assign(formattedJson, detailsJson) 160 return Object.assign(formattedJson, detailsJson)
144} 161}
145 162
163function streamingPlaylistsModelToFormattedJSON (video: VideoModel, playlists: VideoStreamingPlaylistModel[]): VideoStreamingPlaylist[] {
164 if (isArray(playlists) === false) return []
165
166 return playlists
167 .map(playlist => {
168 const redundancies = isArray(playlist.RedundancyVideos)
169 ? playlist.RedundancyVideos.map(r => ({ baseUrl: r.fileUrl }))
170 : []
171
172 return {
173 id: playlist.id,
174 type: playlist.type,
175 playlistUrl: playlist.playlistUrl,
176 segmentsSha256Url: playlist.segmentsSha256Url,
177 redundancies
178 } as VideoStreamingPlaylist
179 })
180}
181
146function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFileModel[]): VideoFile[] { 182function videoFilesModelToFormattedJSON (video: VideoModel, videoFiles: VideoFileModel[]): VideoFile[] {
147 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls() 183 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
148 184
@@ -233,6 +269,28 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
233 }) 269 })
234 } 270 }
235 271
272 for (const playlist of (video.VideoStreamingPlaylists || [])) {
273 let tag: (ActivityPlaylistSegmentHashesObject | ActivityPlaylistInfohashesObject)[]
274
275 tag = playlist.p2pMediaLoaderInfohashes
276 .map(i => ({ type: 'Infohash' as 'Infohash', name: i }))
277 tag.push({
278 type: 'Link',
279 name: 'sha256',
280 mimeType: 'application/json' as 'application/json',
281 mediaType: 'application/json' as 'application/json',
282 href: playlist.segmentsSha256Url
283 })
284
285 url.push({
286 type: 'Link',
287 mimeType: 'application/x-mpegURL' as 'application/x-mpegURL',
288 mediaType: 'application/x-mpegURL' as 'application/x-mpegURL',
289 href: playlist.playlistUrl,
290 tag
291 })
292 }
293
236 // Add video url too 294 // Add video url too
237 url.push({ 295 url.push({
238 type: 'Link', 296 type: 'Link',
@@ -264,6 +322,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
264 waitTranscoding: video.waitTranscoding, 322 waitTranscoding: video.waitTranscoding,
265 state: video.state, 323 state: video.state,
266 commentsEnabled: video.commentsEnabled, 324 commentsEnabled: video.commentsEnabled,
325 downloadEnabled: video.downloadEnabled,
267 published: video.publishedAt.toISOString(), 326 published: video.publishedAt.toISOString(),
268 originallyPublishedAt: video.originallyPublishedAt ? 327 originallyPublishedAt: video.originallyPublishedAt ?
269 video.originallyPublishedAt.toISOString() : 328 video.originallyPublishedAt.toISOString() :