2020-11-05 10:56:23 +01:00
|
|
|
import { of } from 'rxjs'
|
2021-10-22 15:51:02 +02:00
|
|
|
import { switchMap } from 'rxjs/operators'
|
2021-02-10 09:05:29 +01:00
|
|
|
import { SelectChannelItem } from 'src/types/select-options-item.model'
|
2019-01-14 14:55:43 +01:00
|
|
|
import { Component, HostListener, OnInit } from '@angular/core'
|
2017-06-16 14:32:15 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router'
|
2018-12-19 16:04:34 +01:00
|
|
|
import { Notifier } from '@app/core'
|
2022-10-07 15:26:53 +02:00
|
|
|
import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
|
2021-06-28 17:30:59 +02:00
|
|
|
import { Video, VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit, VideoService } from '@app/shared/shared-main'
|
2020-11-05 10:56:23 +01:00
|
|
|
import { LiveVideoService } from '@app/shared/shared-video-live'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
2022-07-15 15:30:14 +02:00
|
|
|
import { logger } from '@root-helpers/logger'
|
2023-04-14 09:57:37 +02:00
|
|
|
import { pick, simpleObjectsDeepEqual } from '@shared/core-utils'
|
2020-10-26 16:44:23 +01:00
|
|
|
import { LiveVideo, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
|
2022-06-21 15:31:25 +02:00
|
|
|
import { VideoSource } from '@shared/models/videos/video-source'
|
2022-07-15 15:30:14 +02:00
|
|
|
import { hydrateFormFromVideo } from './shared/video-edit-utils'
|
2016-04-14 22:07:46 +02:00
|
|
|
|
2016-03-14 13:50:19 +01:00
|
|
|
@Component({
|
2017-04-10 21:15:28 +02:00
|
|
|
selector: 'my-videos-update',
|
2017-11-28 15:40:53 +01:00
|
|
|
styleUrls: [ './shared/video-edit.component.scss' ],
|
2017-04-10 21:15:28 +02:00
|
|
|
templateUrl: './video-update.component.html'
|
2016-03-14 13:50:19 +01:00
|
|
|
})
|
2017-04-10 21:15:28 +02:00
|
|
|
export class VideoUpdateComponent extends FormReactive implements OnInit {
|
2022-07-04 11:31:22 +02:00
|
|
|
videoEdit: VideoEdit
|
2021-01-26 10:56:55 +01:00
|
|
|
videoDetails: VideoDetails
|
2022-06-21 15:31:25 +02:00
|
|
|
videoSource: VideoSource
|
2020-09-17 09:20:52 +02:00
|
|
|
userVideoChannels: SelectChannelItem[] = []
|
|
|
|
videoCaptions: VideoCaptionEdit[] = []
|
2020-09-25 10:04:21 +02:00
|
|
|
liveVideo: LiveVideo
|
2016-09-09 22:16:51 +02:00
|
|
|
|
2018-02-16 17:24:47 +01:00
|
|
|
isUpdatingVideo = false
|
2022-02-07 10:27:08 +01:00
|
|
|
forbidScheduledPublication = false
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2018-07-25 10:28:43 +02:00
|
|
|
private updateDone = false
|
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
constructor (
|
2022-10-07 15:26:53 +02:00
|
|
|
protected formReactiveService: FormReactiveService,
|
2017-04-10 21:15:28 +02:00
|
|
|
private route: ActivatedRoute,
|
2017-01-27 16:14:11 +01:00
|
|
|
private router: Router,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2017-12-20 14:29:55 +01:00
|
|
|
private videoService: VideoService,
|
2018-05-16 11:33:11 +02:00
|
|
|
private loadingBar: LoadingBarService,
|
2020-10-26 16:44:23 +01:00
|
|
|
private videoCaptionService: VideoCaptionService,
|
|
|
|
private liveVideoService: LiveVideoService
|
2021-08-17 14:42:53 +02:00
|
|
|
) {
|
2017-06-16 14:32:15 +02:00
|
|
|
super()
|
2016-09-09 22:16:51 +02:00
|
|
|
}
|
2016-03-14 13:50:19 +01:00
|
|
|
|
2017-06-16 14:32:15 +02:00
|
|
|
ngOnInit () {
|
2018-06-05 10:58:45 +02:00
|
|
|
this.buildForm({})
|
2017-04-10 21:15:28 +02:00
|
|
|
|
2021-10-22 15:51:02 +02:00
|
|
|
const { videoData } = this.route.snapshot.data
|
2022-06-21 15:31:25 +02:00
|
|
|
const { video, videoChannels, videoCaptions, videoSource, liveVideo } = videoData
|
2021-10-22 15:51:02 +02:00
|
|
|
|
|
|
|
this.videoDetails = video
|
2022-07-04 11:31:22 +02:00
|
|
|
this.videoEdit = new VideoEdit(this.videoDetails)
|
2021-10-22 15:51:02 +02:00
|
|
|
|
|
|
|
this.userVideoChannels = videoChannels
|
|
|
|
this.videoCaptions = videoCaptions
|
2022-06-21 15:31:25 +02:00
|
|
|
this.videoSource = videoSource
|
2021-10-22 15:51:02 +02:00
|
|
|
this.liveVideo = liveVideo
|
|
|
|
|
2022-07-04 11:31:22 +02:00
|
|
|
this.forbidScheduledPublication = this.videoEdit.privacy !== VideoPrivacy.PRIVATE
|
2021-10-22 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onFormBuilt () {
|
2022-07-04 11:31:22 +02:00
|
|
|
hydrateFormFromVideo(this.form, this.videoEdit, true)
|
2021-10-22 15:51:02 +02:00
|
|
|
|
|
|
|
if (this.liveVideo) {
|
|
|
|
this.form.patchValue({
|
|
|
|
saveReplay: this.liveVideo.saveReplay,
|
2023-03-31 09:12:21 +02:00
|
|
|
replayPrivacy: this.liveVideo.replaySettings ? this.liveVideo.replaySettings.privacy : VideoPrivacy.PRIVATE,
|
2022-03-04 13:40:02 +01:00
|
|
|
latencyMode: this.liveVideo.latencyMode,
|
2021-10-22 15:51:02 +02:00
|
|
|
permanentLive: this.liveVideo.permanentLive
|
|
|
|
})
|
|
|
|
}
|
2016-06-07 22:34:02 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:55:43 +01:00
|
|
|
@HostListener('window:beforeunload', [ '$event' ])
|
|
|
|
onUnload (event: any) {
|
|
|
|
const { text, canDeactivate } = this.canDeactivate()
|
|
|
|
|
|
|
|
if (canDeactivate) return
|
|
|
|
|
|
|
|
event.returnValue = text
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
|
|
|
|
canDeactivate (): { canDeactivate: boolean, text?: string } {
|
2018-07-25 10:28:43 +02:00
|
|
|
if (this.updateDone === true) return { canDeactivate: true }
|
|
|
|
|
2020-08-12 10:40:04 +02:00
|
|
|
const text = $localize`You have unsaved changes! If you leave, your changes will be lost.`
|
2019-01-14 14:55:43 +01:00
|
|
|
|
2018-07-25 10:28:43 +02:00
|
|
|
for (const caption of this.videoCaptions) {
|
2019-01-14 14:55:43 +01:00
|
|
|
if (caption.action) return { canDeactivate: false, text }
|
2018-07-25 10:28:43 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:55:43 +01:00
|
|
|
return { canDeactivate: this.formChanged === false, text }
|
2018-07-25 10:28:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 14:16:15 +02:00
|
|
|
isWaitTranscodingHidden () {
|
2021-01-26 10:56:55 +01:00
|
|
|
if (this.videoDetails.getFiles().length > 1) { // Already transcoded
|
2022-10-11 14:16:15 +02:00
|
|
|
return true
|
2021-01-26 10:56:55 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 14:16:15 +02:00
|
|
|
return false
|
2021-01-26 10:56:55 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:33:24 +01:00
|
|
|
async update () {
|
|
|
|
await this.waitPendingCheck()
|
|
|
|
this.forceCheck()
|
|
|
|
|
|
|
|
if (!this.form.valid || this.isUpdatingVideo === true) {
|
2017-06-16 14:32:15 +02:00
|
|
|
return
|
2017-05-05 14:29:58 +02:00
|
|
|
}
|
|
|
|
|
2022-07-04 11:31:22 +02:00
|
|
|
this.videoEdit.patch(this.form.value)
|
2017-04-10 21:15:28 +02:00
|
|
|
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().start()
|
2018-02-16 17:24:47 +01:00
|
|
|
this.isUpdatingVideo = true
|
2018-07-12 19:02:00 +02:00
|
|
|
|
|
|
|
// Update the video
|
2022-07-04 11:31:22 +02:00
|
|
|
this.videoService.updateVideo(this.videoEdit)
|
2018-07-12 19:02:00 +02:00
|
|
|
.pipe(
|
|
|
|
// Then update captions
|
2022-07-04 11:31:22 +02:00
|
|
|
switchMap(() => this.videoCaptionService.updateCaptions(this.videoEdit.id, this.videoCaptions)),
|
2020-10-26 16:44:23 +01:00
|
|
|
|
|
|
|
switchMap(() => {
|
|
|
|
if (!this.liveVideo) return of(undefined)
|
|
|
|
|
2023-04-19 15:18:44 +02:00
|
|
|
const saveReplay = !!this.form.value.saveReplay
|
|
|
|
const replaySettings = saveReplay
|
|
|
|
? { privacy: this.form.value.replayPrivacy }
|
|
|
|
: undefined
|
|
|
|
|
2021-01-26 15:28:38 +01:00
|
|
|
const liveVideoUpdate: LiveVideoUpdate = {
|
2023-04-19 15:18:44 +02:00
|
|
|
saveReplay,
|
|
|
|
replaySettings,
|
2022-03-04 13:40:02 +01:00
|
|
|
permanentLive: !!this.form.value.permanentLive,
|
|
|
|
latencyMode: this.form.value.latencyMode
|
2021-01-26 15:28:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't update live attributes if they did not change
|
2023-04-14 09:57:37 +02:00
|
|
|
const baseVideo = pick(this.liveVideo, Object.keys(liveVideoUpdate) as (keyof LiveVideoUpdate)[])
|
|
|
|
const liveChanged = !simpleObjectsDeepEqual(baseVideo, liveVideoUpdate)
|
2021-01-26 15:28:38 +01:00
|
|
|
if (!liveChanged) return of(undefined)
|
|
|
|
|
2022-07-04 11:31:22 +02:00
|
|
|
return this.liveVideoService.updateLive(this.videoEdit.id, liveVideoUpdate)
|
2020-10-26 16:44:23 +01:00
|
|
|
})
|
2018-07-12 19:02:00 +02:00
|
|
|
)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
2018-07-25 10:28:43 +02:00
|
|
|
this.updateDone = true
|
2018-07-12 19:02:00 +02:00
|
|
|
this.isUpdatingVideo = false
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().complete()
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`Video updated.`)
|
2022-07-04 11:31:22 +02:00
|
|
|
this.router.navigateByUrl(Video.buildWatchUrl(this.videoEdit))
|
2018-07-12 19:02:00 +02:00
|
|
|
},
|
|
|
|
|
2021-08-17 11:27:47 +02:00
|
|
|
error: err => {
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().complete()
|
2018-07-12 19:02:00 +02:00
|
|
|
this.isUpdatingVideo = false
|
2018-12-19 16:04:34 +01:00
|
|
|
this.notifier.error(err.message)
|
2022-07-15 15:30:14 +02:00
|
|
|
logger.error(err)
|
2018-07-12 19:02:00 +02:00
|
|
|
}
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2016-03-14 13:50:19 +01:00
|
|
|
}
|
2017-03-22 21:47:05 +01:00
|
|
|
|
2020-08-20 16:18:16 +02:00
|
|
|
hydratePluginFieldsFromVideo () {
|
2022-07-04 11:31:22 +02:00
|
|
|
if (!this.videoEdit.pluginData) return
|
2020-08-20 16:18:16 +02:00
|
|
|
|
|
|
|
this.form.patchValue({
|
2022-07-04 11:31:22 +02:00
|
|
|
pluginData: this.videoEdit.pluginData
|
2020-08-20 16:18:16 +02:00
|
|
|
})
|
|
|
|
}
|
2021-06-28 17:30:59 +02:00
|
|
|
|
|
|
|
getVideoUrl () {
|
|
|
|
return Video.buildWatchUrl(this.videoDetails)
|
|
|
|
}
|
2016-03-14 13:50:19 +01:00
|
|
|
}
|