From 40e87e9ecc54e3513fb586928330a7855eb192c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jul 2018 19:02:00 +0200 Subject: Implement captions/subtitles --- server/initializers/constants.ts | 23 +++++++++++++++++++++-- server/initializers/database.ts | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index c5bc886d8..49809e64c 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -138,6 +138,7 @@ const CONFIG = { VIDEOS_DIR: buildPath(config.get('storage.videos')), THUMBNAILS_DIR: buildPath(config.get('storage.thumbnails')), PREVIEWS_DIR: buildPath(config.get('storage.previews')), + CAPTIONS_DIR: buildPath(config.get('storage.captions')), TORRENTS_DIR: buildPath(config.get('storage.torrents')), CACHE_DIR: buildPath(config.get('storage.cache')) }, @@ -183,6 +184,9 @@ const CONFIG = { CACHE: { PREVIEWS: { get SIZE () { return config.get('cache.previews.size') } + }, + VIDEO_CAPTIONS: { + get SIZE () { return config.get('cache.captions.size') } } }, INSTANCE: { @@ -225,6 +229,14 @@ const CONSTRAINTS_FIELDS = { SUPPORT: { min: 3, max: 500 }, // Length URL: { min: 3, max: 2000 } // Length }, + VIDEO_CAPTIONS: { + CAPTION_FILE: { + EXTNAME: [ '.vtt' ], + FILE_SIZE: { + max: 2 * 1024 * 1024 // 2MB + } + } + }, VIDEOS: { NAME: { min: 3, max: 120 }, // Length LANGUAGE: { min: 1, max: 10 }, // Length @@ -351,6 +363,10 @@ const IMAGE_MIMETYPE_EXT = { 'image/jpeg': '.jpg' } +const VIDEO_CAPTIONS_MIMETYPE_EXT = { + 'text/vtt': '.vtt' +} + // --------------------------------------------------------------------------- const SERVER_ACTOR_NAME = 'peertube' @@ -403,7 +419,8 @@ const STATIC_PATHS = { THUMBNAILS: '/static/thumbnails/', TORRENTS: '/static/torrents/', WEBSEED: '/static/webseed/', - AVATARS: '/static/avatars/' + AVATARS: '/static/avatars/', + VIDEO_CAPTIONS: '/static/video-captions/' } const STATIC_DOWNLOAD_PATHS = { TORRENTS: '/download/torrents/', @@ -435,7 +452,8 @@ const EMBED_SIZE = { // Sub folders of cache directory const CACHE = { DIRECTORIES: { - PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews') + PREVIEWS: join(CONFIG.STORAGE.CACHE_DIR, 'previews'), + VIDEO_CAPTIONS: join(CONFIG.STORAGE.CACHE_DIR, 'video-captions') } } @@ -490,6 +508,7 @@ updateWebserverConfig() export { API_VERSION, + VIDEO_CAPTIONS_MIMETYPE_EXT, AVATARS_SIZE, ACCEPT_HEADERS, BCRYPT_SALT_SIZE, diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 4d90c90fc..434d7ef19 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -23,6 +23,7 @@ import { VideoShareModel } from '../models/video/video-share' import { VideoTagModel } from '../models/video/video-tag' import { CONFIG } from './constants' import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' +import { VideoCaptionModel } from '../models/video/video-caption' require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string @@ -71,6 +72,7 @@ async function initDatabaseModels (silent: boolean) { VideoChannelModel, VideoShareModel, VideoFileModel, + VideoCaptionModel, VideoBlacklistModel, VideoTagModel, VideoModel, -- cgit v1.2.3