aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-04 15:03:30 +0200
committerChocobozzz <me@florianbigard.com>2020-06-04 15:03:30 +0200
commit5072b9092284e96428ed919dbeed60c46dd96ba4 (patch)
tree410f2964486c7ad633ca9874b69d247988972df6 /server
parent0bd558a0f9c7c6f1d5460e3792eaae663bf4f5e5 (diff)
downloadPeerTube-5072b9092284e96428ed919dbeed60c46dd96ba4.tar.gz
PeerTube-5072b9092284e96428ed919dbeed60c46dd96ba4.tar.zst
PeerTube-5072b9092284e96428ed919dbeed60c46dd96ba4.zip
Sort AP files by resolution desc
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-format-utils.ts18
1 files changed, 11 insertions, 7 deletions
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index d71a3a5db..6d38815bb 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -175,6 +175,12 @@ function streamingPlaylistsModelToFormattedJSON (video: MVideo, playlists: MStre
175 }) 175 })
176} 176}
177 177
178function sortByResolutionDesc (fileA: MVideoFile, fileB: MVideoFile) {
179 if (fileA.resolution < fileB.resolution) return 1
180 if (fileA.resolution === fileB.resolution) return 0
181 return -1
182}
183
178function videoFilesModelToFormattedJSON ( 184function videoFilesModelToFormattedJSON (
179 model: MVideo | MStreamingPlaylistVideo, 185 model: MVideo | MStreamingPlaylistVideo,
180 baseUrlHttp: string, 186 baseUrlHttp: string,
@@ -183,7 +189,8 @@ function videoFilesModelToFormattedJSON (
183): VideoFile[] { 189): VideoFile[] {
184 const video = extractVideo(model) 190 const video = extractVideo(model)
185 191
186 return videoFiles 192 return [ ...videoFiles ]
193 .sort(sortByResolutionDesc)
187 .map(videoFile => { 194 .map(videoFile => {
188 return { 195 return {
189 resolution: { 196 resolution: {
@@ -200,11 +207,6 @@ function videoFilesModelToFormattedJSON (
200 metadataUrl: video.getVideoFileMetadataUrl(videoFile, baseUrlHttp) 207 metadataUrl: video.getVideoFileMetadataUrl(videoFile, baseUrlHttp)
201 } as VideoFile 208 } as VideoFile
202 }) 209 })
203 .sort((a, b) => {
204 if (a.resolution.id < b.resolution.id) return 1
205 if (a.resolution.id === b.resolution.id) return 0
206 return -1
207 })
208} 210}
209 211
210function addVideoFilesInAPAcc ( 212function addVideoFilesInAPAcc (
@@ -214,7 +216,9 @@ function addVideoFilesInAPAcc (
214 baseUrlWs: string, 216 baseUrlWs: string,
215 files: MVideoFile[] 217 files: MVideoFile[]
216) { 218) {
217 for (const file of files) { 219 const sortedFiles = [ ...files ].sort(sortByResolutionDesc)
220
221 for (const file of sortedFiles) {
218 acc.push({ 222 acc.push({
219 type: 'Link', 223 type: 'Link',
220 mediaType: MIMETYPES.VIDEO.EXT_MIMETYPE[file.extname] as any, 224 mediaType: MIMETYPES.VIDEO.EXT_MIMETYPE[file.extname] as any,