aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/custom-validators/video-captions.ts8
-rw-r--r--server/lib/video-pre-import.ts7
-rw-r--r--server/tests/api/videos/video-imports.ts10
3 files changed, 20 insertions, 5 deletions
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts
index d5b09ea03..0e24655a0 100644
--- a/server/helpers/custom-validators/video-captions.ts
+++ b/server/helpers/custom-validators/video-captions.ts
@@ -2,6 +2,7 @@ import { UploadFilesForCheck } from 'express'
2import { readFile } from 'fs-extra' 2import { readFile } from 'fs-extra'
3import { getFileSize } from '@shared/extra-utils' 3import { getFileSize } from '@shared/extra-utils'
4import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
5import { logger } from '../logger'
5import { exists, isFileValid } from './misc' 6import { exists, isFileValid } from './misc'
6 7
7function isVideoCaptionLanguageValid (value: any) { 8function isVideoCaptionLanguageValid (value: any) {
@@ -24,12 +25,13 @@ function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {
24 25
25async function isVTTFileValid (filePath: string) { 26async function isVTTFileValid (filePath: string) {
26 const size = await getFileSize(filePath) 27 const size = await getFileSize(filePath)
28 const content = await readFile(filePath, 'utf8')
27 29
28 if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false 30 logger.debug('Checking VTT file %s', filePath, { size, content })
29 31
30 const content = await readFile(filePath, 'utf8') 32 if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false
31 33
32 return content?.startsWith('WEBVTT\n') 34 return content?.startsWith('WEBVTT')
33} 35}
34 36
35// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
diff --git a/server/lib/video-pre-import.ts b/server/lib/video-pre-import.ts
index 796079875..df67dc953 100644
--- a/server/lib/video-pre-import.ts
+++ b/server/lib/video-pre-import.ts
@@ -259,7 +259,7 @@ async function forgeThumbnail ({ inputPath, video, downloadUrl, type }: {
259 try { 259 try {
260 return await updateVideoMiniatureFromUrl({ downloadUrl, video, type }) 260 return await updateVideoMiniatureFromUrl({ downloadUrl, video, type })
261 } catch (err) { 261 } catch (err) {
262 logger.warn('Cannot process thumbnail %s from youtubedl.', downloadUrl, { err }) 262 logger.warn('Cannot process thumbnail %s from youtube-dl.', downloadUrl, { err })
263 } 263 }
264 } 264 }
265 return null 265 return null
@@ -269,10 +269,11 @@ async function processYoutubeSubtitles (youtubeDL: YoutubeDLWrapper, targetUrl:
269 try { 269 try {
270 const subtitles = await youtubeDL.getSubtitles() 270 const subtitles = await youtubeDL.getSubtitles()
271 271
272 logger.info('Will create %s subtitles from youtube import %s.', subtitles.length, targetUrl) 272 logger.info('Found %s subtitles candidates from youtube-dl import %s.', subtitles.length, targetUrl)
273 273
274 for (const subtitle of subtitles) { 274 for (const subtitle of subtitles) {
275 if (!await isVTTFileValid(subtitle.path)) { 275 if (!await isVTTFileValid(subtitle.path)) {
276 logger.info('%s is not a valid youtube-dl subtitle, skipping', subtitle.path)
276 await remove(subtitle.path) 277 await remove(subtitle.path)
277 continue 278 continue
278 } 279 }
@@ -289,6 +290,8 @@ async function processYoutubeSubtitles (youtubeDL: YoutubeDLWrapper, targetUrl:
289 await sequelizeTypescript.transaction(async t => { 290 await sequelizeTypescript.transaction(async t => {
290 await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t) 291 await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t)
291 }) 292 })
293
294 logger.info('Added %s youtube-dl subtitle', subtitle.path)
292 } 295 }
293 } catch (err) { 296 } catch (err) {
294 logger.warn('Cannot get video subtitles.', { err }) 297 logger.warn('Cannot get video subtitles.', { err })
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index 878452ed2..192b2aeb9 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -449,6 +449,16 @@ describe('Test video imports', function () {
449 const video = await server.videos.get({ id: videoUUID }) 449 const video = await server.videos.get({ id: videoUUID })
450 450
451 expect(video.name).to.equal('E2E tests') 451 expect(video.name).to.equal('E2E tests')
452
453 const { data: captions } = await server.captions.list({ videoId: videoUUID })
454 expect(captions).to.have.lengthOf(1)
455 expect(captions[0].language.id).to.equal('fr')
456
457 const str = `WEBVTT FILE\r?\n\r?\n` +
458 `1\r?\n` +
459 `00:00:04.000 --> 00:00:09.000\r?\n` +
460 `January 1, 1994. The North American`
461 await testCaptionFile(server.url, captions[0].captionPath, new RegExp(str))
452 } 462 }
453 } 463 }
454 }) 464 })