Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add simple subtitle edition from video captions tab

lutangar57d74ec83d64
diff --git a/client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts b/client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts
index 5c4152884a..6deadfcbed 100644
--- a/client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts
+++ b/client/src/app/+videos/+video-edit/shared/video-caption-add-modal.component.ts
@@ -77,7 +77,8 @@ export class VideoCaptionAddModalComponent extends FormReactive implements OnIni
this.captionAdded.emit({
language: languageObject,
- captionfile: this.form.value['captionfile']
+ captionfile: this.form.value['captionfile'],
+ action: 'CREATE'
})
this.hide()
diff --git a/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.html b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.html
new file mode 100644
index 0000000000..4543b93d83
--- /dev/null
+++ b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.html
@@ -0,0 +1,36 @@
+<ng-template #modal>
+ <ng-container [formGroup]="form">
+
+ <div class="modal-header">
+ <h4 i18n class="modal-title">Edit caption</h4>
+ <my-global-icon iconName="cross" aria-label="Close" role="button" (click)="hide()"></my-global-icon>
+ </div>
+
+ <div class="modal-body">
+ <label i18n for="captionFileContent">Caption</label>
+ <textarea
+ id="captionFileContent"
+ formControlName="captionFileContent"
+ class="form-control caption-textarea"
+ [ngClass]="{ 'input-error': formErrors['captionFileContent'] }"
+ >
+ </textarea>
+
+ <div *ngIf="formErrors.captionFileContent" class="form-error">
+ {{ formErrors.description }}
+ </div>
+ </div>
+
+ <div class="modal-footer inputs">
+ <input
+ type="button" role="button" i18n-value value="Cancel" class="peertube-button grey-button"
+ (click)="cancel()" (key.enter)="cancel()"
+ >
+
+ <input
+ type="submit" i18n-value value="Edit this caption" class="peertube-button orange-button"
+ [disabled]="!form.valid" (click)="updateCaption()"
+ >
+ </div>
+ </ng-container>
+</ng-template>
diff --git a/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.scss b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.scss
new file mode 100644
index 0000000000..bd96f2b7a9
--- /dev/null
+++ b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.scss
@@ -0,0 +1,4 @@
+.caption-textarea {
+ min-height: 600px;
+}
+
diff --git a/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.ts b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.ts
new file mode 100644
index 0000000000..d2232a38e3
--- /dev/null
+++ b/client/src/app/+videos/+video-edit/shared/video-caption-edit-modal/video-caption-edit-modal.component.ts
@@ -0,0 +1,92 @@
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
+
+import { VIDEO_CAPTION_FILE_CONTENT_VALIDATOR } from '@app/shared/form-validators/video-captions-validators'
+import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
+import { VideoCaptionEdit, VideoCaptionService, VideoCaptionWithPathEdit } from '@app/shared/shared-main'
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
+import { HTMLServerConfig, VideoConstant } from '@shared/models'
+import { ServerService } from '../../../../core'
+
+@Component({
+ selector: 'my-video-caption-edit-modal',
+ styleUrls: [ './video-caption-edit-modal.component.scss' ],
+ templateUrl: './video-caption-edit-modal.component.html'
+})
+
+export class VideoCaptionEditModalComponent extends FormReactive implements OnInit {
+ @Input() videoCaption: VideoCaptionWithPathEdit
+ @Input() serverConfig: HTMLServerConfig
+
+ @Output() captionEdited = new EventEmitter<VideoCaptionEdit>()
+
+ @ViewChild('modal', { static: true }) modal: ElementRef
+
+ videoCaptionLanguages: VideoConstant<string>[] = []
+ private openedModal: NgbModalRef
+ private closingModal = false
+
+ constructor (
+ protected formValidatorService: FormValidatorService,
+ private modalService: NgbModal,
+ private videoCaptionService: VideoCaptionService,
+ private serverService: ServerService
+ ) {
+ super()
+ }
+
+ ngOnInit () {
+ this.serverService.getVideoLanguages().subscribe(languages => this.videoCaptionLanguages = languages)
+
+ this.buildForm({ captionFileContent: VIDEO_CAPTION_FILE_CONTENT_VALIDATOR })
+
+ this.loadCaptionContent()
+ }
+
+ loadCaptionContent () {
+ const { captionPath } = this.videoCaption
+ if (captionPath) {
+ this.videoCaptionService.getCaptionContent({
+ captionPath
+ }).subscribe((res) => {
+ this.form.patchValue({
+ captionFileContent: res
+ })
+ })
+ }
+ }
+
+ show () {
+ this.closingModal = false
+
+ this.openedModal = this.modalService.open(this.modal, { centered: true, keyboard: false })
+ }
+
+ hide () {
+ this.closingModal = true
+ this.openedModal.close()
+ }
+
+ cancel () {
+ this.hide()
+ }
+
+ isReplacingExistingCaption () {
+ return true
+ }
+
+ updateCaption () {
+ const format = 'vtt'
+ const languageId = this.videoCaption.language.id
+ const languageObject = this.videoCaptionLanguages.find(l => l.id === languageId)
+ this.captionEdited.emit({
+ language: languageObject,
+ captionfile: new File([ this.form.value['captionFileContent'] ], `${languageId}.${format}`, {
+ type: 'text/vtt',
+ lastModified: Date.now()
+ }),
+ action: 'UPDATE'
+ })
+
+ this.hide()
+ }
+}
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.html b/client/src/app/+videos/+video-edit/shared/video-edit.component.html
index 9bb13ba883..2281f86317 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.component.html
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.html
@@ -186,6 +186,7 @@
<div i18n class="caption-entry-state">Already uploaded &#10004;</div>
+ <span i18n class="caption-entry-edit" (click)="videoCaptionEditModal.show()">Edit</span>
<span i18n class="caption-entry-delete" (click)="deleteCaption(videoCaption)">Delete</span>
</ng-container>
@@ -197,6 +198,14 @@
<span i18n class="caption-entry-delete" (click)="deleteCaption(videoCaption)">Cancel create</span>
</ng-container>
+ <ng-container *ngIf="videoCaption.action === 'UPDATE'">
+ <span class="caption-entry-label">{{ videoCaption.language.label }}</span>
+
+ <div i18n class="caption-entry-state caption-entry-state-create">Will be edited on update</div>
+
+ <span i18n class="caption-entry-delete" (click)="deleteCaption(videoCaption)">Cancel edition</span>
+ </ng-container>
+
<ng-container *ngIf="videoCaption.action === 'REMOVE'">
<span class="caption-entry-label">{{ videoCaption.language.label }}</span>
@@ -204,6 +213,13 @@
<span i18n class="caption-entry-delete" (click)="deleteCaption(videoCaption)">Cancel deletion</span>
</ng-container>
+
+ <my-video-caption-edit-modal
+ #videoCaptionEditModal
+ [videoCaption]="videoCaption"
+ [serverConfig]="serverConfig"
+ (captionEdited)="onCaptionEdited($event)"
+ ></my-video-caption-edit-modal>
</div>
</div>
@@ -373,5 +389,5 @@
</div>
<my-video-caption-add-modal
- #videoCaptionAddModal [existingCaptions]="getExistingCaptions()" [serverConfig]="serverConfig" (captionAdded)="onCaptionAdded($event)"
+ #videoCaptionAddModal [existingCaptions]="getExistingCaptions()" [serverConfig]="serverConfig" (captionAdded)="onCaptionEdited($event)"
></my-video-caption-add-modal>
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.scss b/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
index 4b1dec89ad..5344e54315 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
@@ -96,6 +96,10 @@ my-peertube-checkbox {
}
}
+ .caption-entry-edit {
+ @include peertube-button;
+ }
+
.caption-entry-delete {
@include peertube-button;
@include grey-button;
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts
index 31dbe43e69..0f4d0619bf 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts
@@ -21,7 +21,7 @@ import {
} from '@app/shared/form-validators/video-validators'
import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms'
import { InstanceService } from '@app/shared/shared-instance'
-import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
+import { VideoCaptionEdit, VideoCaptionWithPathEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
import { PluginInfo } from '@root-helpers/plugins-manager'
import {
HTMLServerConfig,
@@ -34,6 +34,7 @@ import {
} from '@shared/models'
import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'
+import { VideoCaptionEditModalComponent } from './video-caption-edit-modal/video-caption-edit-modal.component'
import { VideoEditType } from './video-edit.type'
type VideoLanguages = VideoConstant<string> & { group?: string }
@@ -58,13 +59,14 @@ export class VideoEditComponent implements OnInit, OnDestroy {
@Input() userVideoChannels: SelectChannelItem[] = []
@Input() forbidScheduledPublication = true
- @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
+ @Input() videoCaptions: (VideoCaptionWithPathEdit)[] = []
@Input() waitTranscodingEnabled = true
@Input() type: VideoEditType
@Input() liveVideo: LiveVideo
@ViewChild('videoCaptionAddModal', { static: true }) videoCaptionAddModal: VideoCaptionAddModalComponent
+ @ViewChild('videoCaptionEditModal', { static: true }) editCaptionModal: VideoCaptionEditModalComponent
@Output() formBuilt = new EventEmitter<void>()
@Output() pluginFieldsAdded = new EventEmitter<void>()
@@ -228,12 +230,12 @@ export class VideoEditComponent implements OnInit, OnDestroy {
.map(c => c.language.id)
}
- onCaptionAdded (caption: VideoCaptionEdit) {
+ onCaptionEdited (caption: VideoCaptionEdit) {
const existingCaption = this.videoCaptions.find(c => c.language.id === caption.language.id)
// Replace existing caption?
if (existingCaption) {
- Object.assign(existingCaption, caption, { action: 'CREATE' as 'CREATE' })
+ Object.assign(existingCaption, caption)
} else {
this.videoCaptions.push(
Object.assign(caption, { action: 'CREATE' as 'CREATE' })
@@ -251,7 +253,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
}
// This caption is not on the server, just remove it from our array
- if (caption.action === 'CREATE') {
+ if (caption.action === 'CREATE' || caption.action === 'UPDATE') {
removeElementFromArray(this.videoCaptions, caption)
return
}
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.module.ts b/client/src/app/+videos/+video-edit/shared/video-edit.module.ts
index 7a3854065f..4e87673643 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.module.ts
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.module.ts
@@ -6,6 +6,7 @@ import { SharedMainModule } from '@app/shared/shared-main'
import { SharedVideoLiveModule } from '@app/shared/shared-video-live'
import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'
+import { VideoCaptionEditModalComponent } from './video-caption-edit-modal/video-caption-edit-modal.component'
import { VideoEditComponent } from './video-edit.component'
@NgModule({
@@ -20,7 +21,8 @@ import { VideoEditComponent } from './video-edit.component'
declarations: [
VideoEditComponent,
- VideoCaptionAddModalComponent
+ VideoCaptionAddModalComponent,
+ VideoCaptionEditModalComponent
],
exports: [
diff --git a/client/src/app/shared/form-validators/video-captions-validators.ts b/client/src/app/shared/form-validators/video-captions-validators.ts
index a162164227..e589fe934f 100644
--- a/client/src/app/shared/form-validators/video-captions-validators.ts
+++ b/client/src/app/shared/form-validators/video-captions-validators.ts
@@ -14,3 +14,10 @@ export const VIDEO_CAPTION_FILE_VALIDATOR: BuildFormValidator = {
required: $localize`Video caption file is required.`
}
}
+
+export const VIDEO_CAPTION_FILE_CONTENT_VALIDATOR: BuildFormValidator = {
+ VALIDATORS: [ Validators.required ],
+ MESSAGES: {
+ required: $localize`Caption content is required.`
+ }
+}
diff --git a/client/src/app/shared/shared-main/video-caption/video-caption-edit.model.ts b/client/src/app/shared/shared-main/video-caption/video-caption-edit.model.ts
index 732f20158c..129e80bc0c 100644
--- a/client/src/app/shared/shared-main/video-caption/video-caption-edit.model.ts
+++ b/client/src/app/shared/shared-main/video-caption/video-caption-edit.model.ts
@@ -4,6 +4,8 @@ export interface VideoCaptionEdit {
label?: string
}
- action?: 'CREATE' | 'REMOVE'
+ action?: 'CREATE' | 'REMOVE' | 'UPDATE'
captionfile?: any
}
+
+export type VideoCaptionWithPathEdit = VideoCaptionEdit & { captionPath?: string }
diff --git a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts b/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
index 97b79d8426..67eb09e4d5 100644
--- a/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
+++ b/client/src/app/shared/shared-main/video-caption/video-caption.service.ts
@@ -8,6 +8,7 @@ import { VideoService } from '@app/shared/shared-main/video'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { ResultList, VideoCaption } from '@shared/models'
import { VideoCaptionEdit } from './video-caption-edit.model'
+import { environment } from '../../../../environments/environment'
@Injectable()
export class VideoCaptionService {
@@ -57,7 +58,7 @@ export class VideoCaptionService {
let obs: Observable<any> = of(undefined)
for (const videoCaption of videoCaptions) {
- if (videoCaption.action === 'CREATE') {
+ if (videoCaption.action === 'CREATE' || videoCaption.action === 'UPDATE') {
obs = obs.pipe(switchMap(() => this.addCaption(videoId, videoCaption.language.id, videoCaption.captionfile)))
} else if (videoCaption.action === 'REMOVE') {
obs = obs.pipe(switchMap(() => this.removeCaption(videoId, videoCaption.language.id)))
@@ -66,4 +67,8 @@ export class VideoCaptionService {
return obs
}
+
+ getCaptionContent ({ captionPath }: Pick<VideoCaption, 'captionPath'>) {
+ return this.authHttp.get(`${environment.originServerUrl}${captionPath}`, { responseType: 'text' })
+ }
}