aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-caption.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-caption.ts')
-rw-r--r--server/models/video/video-caption.ts27
1 files changed, 26 insertions, 1 deletions
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index 2eaa77407..1fb1cae82 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -1,6 +1,6 @@
1import { remove } from 'fs-extra' 1import { remove } from 'fs-extra'
2import { join } from 'path' 2import { join } from 'path'
3import { OrderItem, Transaction } from 'sequelize' 3import { Op, OrderItem, Transaction } from 'sequelize'
4import { 4import {
5 AllowNull, 5 AllowNull,
6 BeforeDestroy, 6 BeforeDestroy,
@@ -166,6 +166,31 @@ export class VideoCaptionModel extends Model<Partial<AttributesOnly<VideoCaption
166 return VideoCaptionModel.scope(ScopeNames.WITH_VIDEO_UUID_AND_REMOTE).findAll(query) 166 return VideoCaptionModel.scope(ScopeNames.WITH_VIDEO_UUID_AND_REMOTE).findAll(query)
167 } 167 }
168 168
169 static async listCaptionsOfMultipleVideos (videoIds: number[], transaction?: Transaction) {
170 const query = {
171 order: [ [ 'language', 'ASC' ] ] as OrderItem[],
172 where: {
173 videoId: {
174 [Op.in]: videoIds
175 }
176 },
177 transaction
178 }
179
180 const captions = await VideoCaptionModel.scope(ScopeNames.WITH_VIDEO_UUID_AND_REMOTE).findAll<MVideoCaptionVideo>(query)
181 const result: { [ id: number ]: MVideoCaptionVideo[] } = {}
182
183 for (const id of videoIds) {
184 result[id] = []
185 }
186
187 for (const caption of captions) {
188 result[caption.videoId].push(caption)
189 }
190
191 return result
192 }
193
169 static getLanguageLabel (language: string) { 194 static getLanguageLabel (language: string) {
170 return VIDEO_LANGUAGES[language] || 'Unknown' 195 return VIDEO_LANGUAGES[language] || 'Unknown'
171 } 196 }