aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-format-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-format-utils.ts')
-rw-r--r--server/models/video/video-format-utils.ts49
1 files changed, 24 insertions, 25 deletions
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index adf460734..9dc3e7722 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -14,8 +14,6 @@ import {
14} from '../../lib/activitypub/url' 14} from '../../lib/activitypub/url'
15import { 15import {
16 MStreamingPlaylistRedundanciesOpt, 16 MStreamingPlaylistRedundanciesOpt,
17 MStreamingPlaylistVideo,
18 MVideo,
19 MVideoAP, 17 MVideoAP,
20 MVideoFile, 18 MVideoFile,
21 MVideoFormattable, 19 MVideoFormattable,
@@ -127,8 +125,6 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid
127 } 125 }
128 }) 126 })
129 127
130 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
131
132 const tags = video.Tags ? video.Tags.map(t => t.name) : [] 128 const tags = video.Tags ? video.Tags.map(t => t.name) : []
133 129
134 const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists) 130 const streamingPlaylists = streamingPlaylistsModelToFormattedJSON(video, video.VideoStreamingPlaylists)
@@ -147,14 +143,14 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vid
147 label: VideoModel.getStateLabel(video.state) 143 label: VideoModel.getStateLabel(video.state)
148 }, 144 },
149 145
150 trackerUrls: video.getTrackerUrls(baseUrlHttp, baseUrlWs), 146 trackerUrls: video.getTrackerUrls(),
151 147
152 files: [], 148 files: [],
153 streamingPlaylists 149 streamingPlaylists
154 } 150 }
155 151
156 // Format and sort video files 152 // Format and sort video files
157 detailsJson.files = videoFilesModelToFormattedJSON(video, video, baseUrlHttp, baseUrlWs, video.VideoFiles) 153 detailsJson.files = videoFilesModelToFormattedJSON(video, video.VideoFiles)
158 154
159 return Object.assign(formattedJson, detailsJson) 155 return Object.assign(formattedJson, detailsJson)
160} 156}
@@ -165,17 +161,13 @@ function streamingPlaylistsModelToFormattedJSON (
165): VideoStreamingPlaylist[] { 161): VideoStreamingPlaylist[] {
166 if (isArray(playlists) === false) return [] 162 if (isArray(playlists) === false) return []
167 163
168 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
169
170 return playlists 164 return playlists
171 .map(playlist => { 165 .map(playlist => {
172 const playlistWithVideo = Object.assign(playlist, { Video: video })
173
174 const redundancies = isArray(playlist.RedundancyVideos) 166 const redundancies = isArray(playlist.RedundancyVideos)
175 ? playlist.RedundancyVideos.map(r => ({ baseUrl: r.fileUrl })) 167 ? playlist.RedundancyVideos.map(r => ({ baseUrl: r.fileUrl }))
176 : [] 168 : []
177 169
178 const files = videoFilesModelToFormattedJSON(playlistWithVideo, video, baseUrlHttp, baseUrlWs, playlist.VideoFiles) 170 const files = videoFilesModelToFormattedJSON(video, playlist.VideoFiles)
179 171
180 return { 172 return {
181 id: playlist.id, 173 id: playlist.id,
@@ -194,14 +186,12 @@ function sortByResolutionDesc (fileA: MVideoFile, fileB: MVideoFile) {
194 return -1 186 return -1
195} 187}
196 188
197// FIXME: refactor/merge model and video arguments
198function videoFilesModelToFormattedJSON ( 189function videoFilesModelToFormattedJSON (
199 model: MVideo | MStreamingPlaylistVideo,
200 video: MVideoFormattableDetails, 190 video: MVideoFormattableDetails,
201 baseUrlHttp: string,
202 baseUrlWs: string,
203 videoFiles: MVideoFileRedundanciesOpt[] 191 videoFiles: MVideoFileRedundanciesOpt[]
204): VideoFile[] { 192): VideoFile[] {
193 const trackerUrls = video.getTrackerUrls()
194
205 return [ ...videoFiles ] 195 return [ ...videoFiles ]
206 .filter(f => !f.isLive()) 196 .filter(f => !f.isLive())
207 .sort(sortByResolutionDesc) 197 .sort(sortByResolutionDesc)
@@ -213,7 +203,7 @@ function videoFilesModelToFormattedJSON (
213 }, 203 },
214 204
215 // FIXME: deprecated in 3.2 205 // FIXME: deprecated in 3.2
216 magnetUri: generateMagnetUri(model, video, videoFile, baseUrlHttp, baseUrlWs), 206 magnetUri: generateMagnetUri(video, videoFile, trackerUrls),
217 207
218 size: videoFile.size, 208 size: videoFile.size,
219 fps: videoFile.fps, 209 fps: videoFile.fps,
@@ -229,15 +219,13 @@ function videoFilesModelToFormattedJSON (
229 }) 219 })
230} 220}
231 221
232// FIXME: refactor/merge model and video arguments
233function addVideoFilesInAPAcc ( 222function addVideoFilesInAPAcc (
234 acc: ActivityUrlObject[] | ActivityTagObject[], 223 acc: ActivityUrlObject[] | ActivityTagObject[],
235 model: MVideoAP | MStreamingPlaylistVideo,
236 video: MVideoWithHost, 224 video: MVideoWithHost,
237 baseUrlHttp: string,
238 baseUrlWs: string,
239 files: MVideoFile[] 225 files: MVideoFile[]
240) { 226) {
227 const trackerUrls = video.getTrackerUrls()
228
241 const sortedFiles = [ ...files ] 229 const sortedFiles = [ ...files ]
242 .filter(f => !f.isLive()) 230 .filter(f => !f.isLive())
243 .sort(sortByResolutionDesc) 231 .sort(sortByResolutionDesc)
@@ -271,14 +259,13 @@ function addVideoFilesInAPAcc (
271 acc.push({ 259 acc.push({
272 type: 'Link', 260 type: 'Link',
273 mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet', 261 mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
274 href: generateMagnetUri(model, video, file, baseUrlHttp, baseUrlWs), 262 href: generateMagnetUri(video, file, trackerUrls),
275 height: file.resolution 263 height: file.resolution
276 }) 264 })
277 } 265 }
278} 266}
279 267
280function videoModelToActivityPubObject (video: MVideoAP): VideoObject { 268function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
281 const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
282 if (!video.Tags) video.Tags = [] 269 if (!video.Tags) video.Tags = []
283 270
284 const tag = video.Tags.map(t => ({ 271 const tag = video.Tags.map(t => ({
@@ -319,7 +306,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
319 } 306 }
320 ] 307 ]
321 308
322 addVideoFilesInAPAcc(url, video, video, baseUrlHttp, baseUrlWs, video.VideoFiles || []) 309 addVideoFilesInAPAcc(url, video, video.VideoFiles || [])
323 310
324 for (const playlist of (video.VideoStreamingPlaylists || [])) { 311 for (const playlist of (video.VideoStreamingPlaylists || [])) {
325 const tag = playlist.p2pMediaLoaderInfohashes 312 const tag = playlist.p2pMediaLoaderInfohashes
@@ -331,8 +318,7 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
331 href: playlist.segmentsSha256Url 318 href: playlist.segmentsSha256Url
332 }) 319 })
333 320
334 const playlistWithVideo = Object.assign(playlist, { Video: video }) 321 addVideoFilesInAPAcc(tag, video, playlist.VideoFiles || [])
335 addVideoFilesInAPAcc(tag, playlistWithVideo, video, baseUrlHttp, baseUrlWs, playlist.VideoFiles || [])
336 322
337 url.push({ 323 url.push({
338 type: 'Link', 324 type: 'Link',
@@ -342,6 +328,19 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
342 }) 328 })
343 } 329 }
344 330
331 for (const trackerUrl of video.getTrackerUrls()) {
332 const rel2 = trackerUrl.startsWith('http')
333 ? 'http'
334 : 'websocket'
335
336 url.push({
337 type: 'Link',
338 name: `tracker-${rel2}`,
339 rel: [ 'tracker', rel2 ],
340 href: trackerUrl
341 })
342 }
343
345 const subtitleLanguage = [] 344 const subtitleLanguage = []
346 for (const caption of video.VideoCaptions) { 345 for (const caption of video.VideoCaptions) {
347 subtitleLanguage.push({ 346 subtitleLanguage.push({