ActivityPub-federated video streaming platform using P2P directly in your web browser
Filter out non text languages for captions
Chocobozzz79e80c4780a1
diff --git a/client/src/app/+videos-publish-manage/shared-manage/captions/video-caption-add-modal.component.ts b/client/src/app/+videos-publish-manage/shared-manage/captions/video-caption-add-modal.component.tsindex b2525eb277..ae76c8bd5a 100644--- a/client/src/app/+videos-publish-manage/shared-manage/captions/video-caption-add-modal.component.ts+++ b/client/src/app/+videos-publish-manage/shared-manage/captions/video-caption-add-modal.component.ts@@ -46,7 +46,7 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni}ngOnInit () {- this.serverService.getVideoLanguages()+ this.serverService.getVideoTextLanguages().subscribe(languages => this.videoCaptionLanguages = languages)this.buildForm({diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.tsindex 0556ba2e96..e34db4d527 100644--- a/client/src/app/core/server/server.service.ts+++ b/client/src/app/core/server/server.service.ts@@ -36,6 +36,7 @@ export class ServerService {private videoPrivaciesObservable: Observable<ConstantLabel<VideoPrivacyType>[]>private videoPlaylistPrivaciesObservable: Observable<ConstantLabel<VideoPlaylistPrivacyType>[]>private videoLanguagesObservable: Observable<ConstantLabel<string>[]>+ private videoTextLanguagesObservable: Observable<ConstantLabel<string>[]>private configObservable: Observable<ServerConfig>private configLoaded = false@@ -134,7 +135,11 @@ export class ServerService {getVideoCategories () {if (!this.videoCategoriesObservable) {- this.videoCategoriesObservable = this.loadAttributeEnum<number>(ServerService.BASE_VIDEO_URL, 'categories', true)+ this.videoCategoriesObservable = this.loadAttributeEnum<number>({+ baseUrl: ServerService.BASE_VIDEO_URL,+ attributeName: 'categories',+ sort: true+ })}return this.videoCategoriesObservable.pipe(first())@@ -142,7 +147,10 @@ export class ServerService {getVideoLicences () {if (!this.videoLicensesObservable) {- this.videoLicensesObservable = this.loadAttributeEnum<VideoLicenceType>(ServerService.BASE_VIDEO_URL, 'licences')+ this.videoLicensesObservable = this.loadAttributeEnum<VideoLicenceType>({+ baseUrl: ServerService.BASE_VIDEO_URL,+ attributeName: 'licences'+ })}return this.videoLicensesObservable.pipe(first())@@ -150,15 +158,35 @@ export class ServerService {getVideoLanguages () {if (!this.videoLanguagesObservable) {- this.videoLanguagesObservable = this.loadAttributeEnum<string>(ServerService.BASE_VIDEO_URL, 'languages', true)+ this.videoLanguagesObservable = this.loadAttributeEnum<string>({+ baseUrl: ServerService.BASE_VIDEO_URL,+ attributeName: 'languages',+ sort: true+ })}return this.videoLanguagesObservable.pipe(first())}+ getVideoTextLanguages () {+ if (!this.videoTextLanguagesObservable) {+ this.videoTextLanguagesObservable = this.loadAttributeEnum<string>({+ baseUrl: ServerService.BASE_VIDEO_URL,+ attributeName: 'languages',+ query: { scope: 'subtitle' },+ sort: true+ })+ }++ return this.videoTextLanguagesObservable.pipe(first())+ }+getVideoPrivacies () {if (!this.videoPrivaciesObservable) {- this.videoPrivaciesObservable = this.loadAttributeEnum<VideoPrivacyType>(ServerService.BASE_VIDEO_URL, 'privacies')+ this.videoPrivaciesObservable = this.loadAttributeEnum<VideoPrivacyType>({+ baseUrl: ServerService.BASE_VIDEO_URL,+ attributeName: 'privacies'+ })}return this.videoPrivaciesObservable.pipe(first())@@ -167,8 +195,7 @@ export class ServerService {getVideoPlaylistPrivacies () {if (!this.videoPlaylistPrivaciesObservable) {this.videoPlaylistPrivaciesObservable = this.loadAttributeEnum<VideoPlaylistPrivacyType>(- ServerService.BASE_VIDEO_PLAYLIST_URL,- 'privacies'+ { baseUrl: ServerService.BASE_VIDEO_PLAYLIST_URL, attributeName: 'privacies' })}@@ -196,15 +223,18 @@ export class ServerService {return this.http.get<ServerStats>(ServerService.BASE_STATS_URL)}- private loadAttributeEnum<T extends string | number> (- baseUrl: string,- attributeName: 'categories' | 'licences' | 'languages' | 'privacies',- sort = false- ) {+ private loadAttributeEnum<T extends string | number> (options: {+ baseUrl: string+ attributeName: 'categories' | 'licences' | 'languages' | 'privacies'+ query?: Record<string, string>+ sort?: boolean+ }) {+ const { baseUrl, attributeName, query, sort = false } = options+return this.getServerLocale().pipe(switchMap(translations => {- return this.http.get<{ [id: string]: string }>(baseUrl + attributeName)+ return this.http.get<{ [id: string]: string }>(baseUrl + attributeName, { params: query }).pipe(map(data => ({ data, translations })))}),map(({ data, translations }) => {diff --git a/packages/server-commands/src/videos/videos-command.ts b/packages/server-commands/src/videos/videos-command.tsindex c0e0559093..5d648e81f3 100644--- a/packages/server-commands/src/videos/videos-command.ts+++ b/packages/server-commands/src/videos/videos-command.ts@@ -57,13 +57,17 @@ export class VideosCommand extends AbstractCommand {})}- getLanguages (options: OverrideCommandOptions = {}) {+ getLanguages (options: OverrideCommandOptions & {+ scope?: 'subtitle'+ } = {}) {const path = '/api/v1/videos/languages'return this.getRequestBody<{ [id: string]: string }>({...options,path,+ query: { scope: options.scope },+implicitToken: false,defaultExpectedStatus: HttpStatusCode.OK_200})diff --git a/packages/tests/src/api/videos/single-server.ts b/packages/tests/src/api/videos/single-server.tsindex 1eb3e547a2..f607ffe477 100644--- a/packages/tests/src/api/videos/single-server.ts+++ b/packages/tests/src/api/videos/single-server.ts@@ -118,6 +118,15 @@ describe('Test a single server', function () {expect(Object.keys(languages)).to.have.length.above(5)expect(languages['ru']).to.equal('Russian')+ expect(languages['jsl']).to.not.be.undefined+ })++ it('Should list video text languages', async function () {+ const languages = await server.videos.getLanguages({ scope: 'subtitle' })+ expect(Object.keys(languages)).to.have.length.above(5)++ expect(languages['ru']).to.equal('Russian')+ expect(languages['jsl']).to.be.undefined})it('Should list video privacies', async function () {diff --git a/scripts/i18n/create-custom-files.ts b/scripts/i18n/create-custom-files.tsindex 7bcbde3def..6d2c8755f7 100755--- a/scripts/i18n/create-custom-files.ts+++ b/scripts/i18n/create-custom-files.ts@@ -142,7 +142,7 @@ Object.values(VIDEO_CATEGORIES)// ISO 639 keysconst languageKeys: any = {}-const languages = await buildLanguages()+const { allLanguages: languages } = await buildLanguages()Object.keys(languages).forEach(k => {languageKeys[languages[k]] = languages[k]})diff --git a/server/core/controllers/api/videos/index.ts b/server/core/controllers/api/videos/index.tsindex b462452f12..2f1a563b16 100644--- a/server/core/controllers/api/videos/index.ts+++ b/server/core/controllers/api/videos/index.ts@@ -9,7 +9,13 @@ import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../import { buildNSFWFilters, getCountVideos } from '../../../helpers/express-utils.js'import { logger } from '../../../helpers/logger.js'import { getFormattedObjects } from '../../../helpers/utils.js'-import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants.js'+import {+ VIDEO_CATEGORIES,+ VIDEO_LANGUAGES,+ VIDEO_LICENCES,+ VIDEO_PRIVACIES,+ VIDEO_TEXT_LANGUAGES+} from '../../../initializers/constants.js'import { sequelizeTypescript } from '../../../initializers/database.js'import { Hooks } from '../../../lib/plugins/hooks.js'import {@@ -24,6 +30,7 @@ import {setDefaultPagination,setDefaultVideosSort,videoGetValidatorFactory,+ videoLanguagesScopeValidator,videosRemoveValidator,videosSortValidator} from '../../../middlewares/index.js'@@ -78,7 +85,7 @@ videosRouter.use('/', videoEmbedPrivacyRouter)videosRouter.get('/categories', openapiOperationDoc({ operationId: 'getCategories' }), listVideoCategories)videosRouter.get('/licences', openapiOperationDoc({ operationId: 'getLicences' }), listVideoLicences)-videosRouter.get('/languages', openapiOperationDoc({ operationId: 'getLanguages' }), listVideoLanguages)+videosRouter.get('/languages', openapiOperationDoc({ operationId: 'getLanguages' }), videoLanguagesScopeValidator, listVideoLanguages)videosRouter.get('/privacies', openapiOperationDoc({ operationId: 'getPrivacies' }), listVideoPrivacies)videosRouter.get(@@ -126,7 +133,13 @@ function listVideoLicences (_req: express.Request, res: express.Response) {res.json(VIDEO_LICENCES)}-function listVideoLanguages (_req: express.Request, res: express.Response) {+function listVideoLanguages (req: express.Request, res: express.Response) {+ const scope = req.query.scope as string++ if (scope === 'subtitle') {+ return res.json(VIDEO_TEXT_LANGUAGES)+ }+res.json(VIDEO_LANGUAGES)}diff --git a/server/core/helpers/custom-validators/video-captions.ts b/server/core/helpers/custom-validators/video-captions.tsindex dcd9fc2c15..66e29055f3 100644--- a/server/core/helpers/custom-validators/video-captions.ts+++ b/server/core/helpers/custom-validators/video-captions.ts@@ -1,12 +1,12 @@import { UploadFilesForCheck } from 'express'import { readFile } from 'fs/promises'import { getFileSize } from '@peertube/peertube-node-utils'-import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants.js'+import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_TEXT_LANGUAGES } from '../../initializers/constants.js'import { logger } from '../logger.js'import { exists, isFileValid } from './misc.js'function isVideoCaptionLanguageValid (value: any) {- return exists(value) && VIDEO_LANGUAGES[value] !== undefined+ return exists(value) && VIDEO_TEXT_LANGUAGES[value] !== undefined}// MacOS sends application/octet-streamdiff --git a/server/core/initializers/constants.ts b/server/core/initializers/constants.tsindex 4056443eb1..3fa728e4c2 100644--- a/server/core/initializers/constants.ts+++ b/server/core/initializers/constants.ts@@ -628,6 +628,7 @@ export const VIDEO_LICENCES: { [id in VideoLicenceType]: string } = {}export const VIDEO_LANGUAGES: { [id: string]: string } = {}+export const VIDEO_TEXT_LANGUAGES: { [id: string]: string } = {}export const VIDEO_PRIVACIES: { [id in VideoPrivacyType]: string } = {[VideoPrivacy.PUBLIC]: 'Public',@@ -1353,7 +1354,15 @@ registerConfigChangedHandler(() => {export async function loadLanguages () {if (Object.keys(VIDEO_LANGUAGES).length !== 0) return- Object.assign(VIDEO_LANGUAGES, await buildLanguages())+ const { allLanguages, nonTextLanguages } = await buildLanguages()++ Object.assign(VIDEO_LANGUAGES, allLanguages)++ for (const [ code, name ] of Object.entries(allLanguages)) {+ if (!nonTextLanguages[code]) {+ VIDEO_TEXT_LANGUAGES[code] = name+ }+ }}// ---------------------------------------------------------------------------@@ -1377,7 +1386,7 @@ export async function buildLanguages () {const languages: { [id: string]: string } = {}- const additionalLanguages = {+ const nonTextLanguages = {sgn: true, // Sign languages (macro language)ase: true, // American sign languageasq: true, // Austrian sign language@@ -1396,6 +1405,12 @@ export async function buildLanguages () {rsl: true, // Russian sign languagefse: true, // Finnish sign language+ zxx: true // No linguistic content (ISO-639-2),+ }++ const additionalLanguages = {+ ...nonTextLanguages,+kab: true, // Kabylegcf: true, // Guadeloupean@@ -1406,8 +1421,6 @@ export async function buildLanguages () {jbo: true, // Lojbanavk: true, // Kotava- zxx: true, // No linguistic content (ISO-639-2),-gsw: true // Swiss German (ISO-639-3)}@@ -1445,7 +1458,7 @@ export async function buildLanguages () {languages['rcf'] = 'Réunion Creole French'languages['gcr'] = 'Guianese Creole French'- return languages+ return { allLanguages: languages, nonTextLanguages }}// ---------------------------------------------------------------------------diff --git a/server/core/middlewares/validators/videos/videos.ts b/server/core/middlewares/validators/videos/videos.tsindex 46d8135d3c..af0a8b97e9 100644--- a/server/core/middlewares/validators/videos/videos.ts+++ b/server/core/middlewares/validators/videos/videos.ts@@ -644,6 +644,19 @@ export function areErrorsInNSFW (req: express.Request, res: express.Response) {return false}+export const videoLanguagesScopeValidator = [+ query('scope')+ .optional()+ .isIn([ 'subtitle' ])+ .withMessage('Should have a valid scope (subtitle)'),++ (req: express.Request, res: express.Response, next: express.NextFunction) => {+ if (areValidationErrors(req, res)) return++ return next()+ }+]+// ---------------------------------------------------------------------------// Private// ---------------------------------------------------------------------------diff --git a/server/core/models/video/video-caption.ts b/server/core/models/video/video-caption.tsindex 5ec1522021..30b13dcce5 100644--- a/server/core/models/video/video-caption.ts+++ b/server/core/models/video/video-caption.ts@@ -36,7 +36,7 @@ import {import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions.js'import { logger } from '../../helpers/logger.js'import { CONFIG } from '../../initializers/config.js'-import { CONSTRAINTS_FIELDS, FILES_CACHE, LAZY_STATIC_PATHS, VIDEO_LANGUAGES, WEBSERVER } from '../../initializers/constants.js'+import { CONSTRAINTS_FIELDS, FILES_CACHE, LAZY_STATIC_PATHS, VIDEO_TEXT_LANGUAGES, WEBSERVER } from '../../initializers/constants.js'import { SequelizeModel, buildWhereIdOrUUID, doesExist, throwIfNotValid } from '../shared/index.js'import { VideoStreamingPlaylistModel } from './video-streaming-playlist.js'import { VideoModel } from './video.js'@@ -263,7 +263,7 @@ export class VideoCaptionModel extends SequelizeModel<VideoCaptionModel> {// ---------------------------------------------------------------------------static getLanguageLabel (language: string) {- return VIDEO_LANGUAGES[language] || 'Unknown'+ return VIDEO_TEXT_LANGUAGES[language] || 'Unknown'}static generateCaptionName (language: string) {diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yamlindex 1ab02c8249..9aac74aef8 100644--- a/support/doc/api/openapi.yaml+++ b/support/doc/api/openapi.yaml@@ -3475,6 +3475,15 @@ paths:operationId: getLanguagestags:- Video+ parameters:+ - name: scope+ in: query+ description: "**PeerTube >= 8.2** Filter languages by scope. Use `subtitle` to exclude sign languages and other languages that don't make sense for subtitles."+ required: false+ schema:+ type: string+ enum:+ - subtitleresponses:'200':description: successful operation