diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-format-utils.ts | 18 |
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 | ||
178 | function 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 | |||
178 | function videoFilesModelToFormattedJSON ( | 184 | function 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 | ||
210 | function addVideoFilesInAPAcc ( | 212 | function 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, |